Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by John Åkerblom 2015-12-12
- #include <h3mlib.h>
- // This PoC breaks the hard cap of 48 Garrisons per map
- void add_48_garrisons(h3mlib_ctx_t h3m, int start_x, int start_y)
- {
- int idx = 0;
- for (int x = start_x; x < (start_x + 8); x += 2) {
- for (int y = start_y; y < (start_y + 12); ++y) {
- // Add garrison at x, y, z = x, y, 0 (0 = surface, 1, underground)
- h3m_object_add(h3m, "Garrison", x, y, 0, &idx);
- // Fill the garrison with random creatures
- h3m_object_fill_random_creatures(h3m, idx);
- }
- }
- }
- int main(void)
- {
- h3mlib_ctx_t h3m = NULL;
- int idx = 0;
- // Open existing map which already contains a bunch of garrisons, or if
- // such a map (garrisons.h3m) could not be opened, create a new one
- h3m_read(&h3m, "garrisons.h3m");
- if (h3m == NULL) {
- // Map did not exist, create a new one which garrisons will be added to
- h3m_init_min(&h3m, H3M_FORMAT_SOD, H3M_SIZE_SMALL);
- h3m_terrain_fill(h3m, H3M_TERRAIN_DIRT);
- }
- // Add 2 sets of 48 garrisons
- add_48_garrisons(h3m, 17, 1);
- add_48_garrisons(h3m, 3, 14);
- // Add 2 castles and enable players 1 and 2to make the map playable
- h3m_object_add(h3m, "Castle", 14, 12, 0, &idx);
- h3m_object_set_owner(h3m, idx, 0); // Player 1 (0), Red
- h3m_player_enable(h3m, 0);
- h3m_object_add(h3m, "Castle", 14, 6, 0, &idx);
- h3m_object_set_owner(h3m, idx, 1); // Player 2 (1), Blue
- h3m_player_enable(h3m, 1);
- // Save the modified map as out.h3m and exit
- h3m_write(h3m, "out.h3m");
- h3m_exit(&h3m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment