Guest User

Untitled

a guest
Dec 12th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. // Created by John Åkerblom 2015-12-12
  2.  
  3. #include <h3mlib.h>
  4.  
  5. // This PoC breaks the hard cap of 48 Garrisons per map
  6.  
  7. void add_48_garrisons(h3mlib_ctx_t h3m, int start_x, int start_y)
  8. {
  9.     int idx = 0;
  10.     for (int x = start_x; x < (start_x + 8); x += 2) {
  11.         for (int y = start_y; y < (start_y + 12); ++y) {
  12.             // Add garrison at x, y, z = x, y, 0 (0 = surface, 1, underground)
  13.             h3m_object_add(h3m, "Garrison", x, y, 0, &idx);
  14.             // Fill the garrison with random creatures
  15.             h3m_object_fill_random_creatures(h3m, idx);
  16.         }
  17.     }
  18. }
  19.  
  20. int main(void)
  21. {
  22.     h3mlib_ctx_t h3m = NULL;
  23.     int idx = 0;
  24.  
  25.     // Open existing map which already contains a bunch of garrisons, or if
  26.     // such a map (garrisons.h3m) could not be opened, create a new one
  27.     h3m_read(&h3m, "garrisons.h3m");
  28.     if (h3m == NULL) {
  29.         // Map did not exist, create a new one which garrisons will be added to
  30.         h3m_init_min(&h3m, H3M_FORMAT_SOD, H3M_SIZE_SMALL);
  31.         h3m_terrain_fill(h3m, H3M_TERRAIN_DIRT);
  32.     }
  33.  
  34.     // Add 2 sets of 48 garrisons
  35.     add_48_garrisons(h3m, 17, 1);
  36.     add_48_garrisons(h3m, 3, 14);
  37.  
  38.     // Add 2 castles and enable players 1 and 2to make the map playable
  39.     h3m_object_add(h3m, "Castle", 14, 12, 0, &idx);
  40.     h3m_object_set_owner(h3m, idx, 0); // Player 1 (0), Red
  41.     h3m_player_enable(h3m, 0);
  42.  
  43.     h3m_object_add(h3m, "Castle", 14, 6, 0, &idx);
  44.     h3m_object_set_owner(h3m, idx, 1); // Player 2 (1), Blue
  45.     h3m_player_enable(h3m, 1);
  46.    
  47.     // Save the modified map as out.h3m and exit
  48.     h3m_write(h3m, "out.h3m");
  49.     h3m_exit(&h3m);
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment