Moved all level data into a struct
authorMartin Read <martin@blackswordsonics.com>
Wed, 25 Sep 2013 19:18:35 +0000 (20:18 +0100)
committerMartin Read <martin@blackswordsonics.com>
Wed, 25 Sep 2013 19:18:35 +0000 (20:18 +0100)
combat.cc
display-nc.cc
fov.cc
main.cc
map.cc
map.hh
mon2.cc
monsters.cc
objects.cc
u.cc

index a7e2044..c54ebcf 100644 (file)
--- a/combat.cc
+++ b/combat.cc
@@ -36,9 +36,9 @@ int player_attack(int dy, int dx)
     {
         ushootm(dy, dx);
     }
-    else if (mapmonster[u.y + dy][u.x + dx] != -1)
+    else if (lvl.mons[u.y + dy][u.x + dx] != -1)
     {
-        uhitm(mapmonster[u.y + dy][u.x + dx]);
+        uhitm(lvl.mons[u.y + dy][u.x + dx]);
     }
     else
     {
@@ -141,10 +141,10 @@ int ushootm(int sy, int sx)
     range = 1;
     for ( ; !done; (y += sy), (x += sx))
     {
-        if (mapmonster[y][x] != -1)
+        if (lvl.mons[y][x] != -1)
         {
             done = 1;
-            mptr = monsters + mapmonster[y][x];
+            mptr = monsters + lvl.mons[y][x];
             tohit = zero_die(u.agility + u.level - range);
             if (range == 1)
             {
@@ -153,17 +153,17 @@ int ushootm(int sy, int sx)
             }
             if (tohit >= mptr->defence)
             {
-                if (mon_visible(mapmonster[y][x]))
+                if (mon_visible(lvl.mons[y][x]))
                 {
                     print_msg("You hit ");
-                    print_mon_name(mapmonster[y][x], 1);
+                    print_mon_name(lvl.mons[y][x], 1);
                     print_msg(".\n");
                     print_msg("You do %d damage.\n", damage);
                 }
-                damage_mon(mapmonster[y][x], damage, 1);
+                damage_mon(lvl.mons[y][x], damage, 1);
                 if ((mptr->used) && (wep->obj_id == PO_THUNDERBOW))
                 {
-                    int kb = knockback_mon(mapmonster[y][x], sy, sx, true, true);
+                    int kb = knockback_mon(lvl.mons[y][x], sy, sx, true, true);
                     switch (kb)
                     {
                     case 0:
@@ -182,15 +182,15 @@ int ushootm(int sy, int sx)
             else
             {
                 print_msg("You miss ");
-                print_mon_name(mapmonster[y][x], 1);
+                print_mon_name(lvl.mons[y][x], 1);
                 print_msg(".\n");
                 return 0;
             }
         }
-        else if ((terrain[y][x] == WALL) || (terrain[y][x] == HARDWALL) ||
-                 (terrain[y][x] == DOOR))
+        else if ((lvl.terrain[y][x] == WALL) || (lvl.terrain[y][x] == HARDWALL) ||
+                 (lvl.terrain[y][x] == DOOR))
         {
-            print_msg("Your %s hits the %s.\n", (wep->obj_id == PO_CROSSBOW) ? "bolt" : "arrow", (terrain[y][x] == DOOR) ? "door" : "wall");
+            print_msg("Your %s hits the %s.\n", (wep->obj_id == PO_CROSSBOW) ? "bolt" : "arrow", (lvl.terrain[y][x] == DOOR) ? "door" : "wall");
             return 0;
         }
     }
@@ -358,7 +358,7 @@ int mshootu(int mon)
          !done;
          (y += sy), (x += sx))
     {
-        if ((terrain[y][x] == WALL) || (terrain[y][x] == DOOR))
+        if ((lvl.terrain[y][x] == WALL) || (lvl.terrain[y][x] == DOOR))
         {
             done = 1;
         }
@@ -412,10 +412,10 @@ int mshootu(int mon)
                 print_msg("It misses you.\n");
             }
         }
-        else if (mapmonster[y][x] != -1)
+        else if (lvl.mons[y][x] != -1)
         {
             done = 1;
-            bystander = monsters + mapmonster[y][x];
+            bystander = monsters + lvl.mons[y][x];
             switch (dtype)
             {
             case DT_COLD:
@@ -455,7 +455,7 @@ int mshootu(int mon)
             if (tohit >= bystander->defence)
             {
                 damage = one_die(mptr->rdam);
-                damage_mon(mapmonster[y][x], dtype, 0);
+                damage_mon(lvl.mons[y][x], dtype, 0);
             }
         }
     }
@@ -470,10 +470,10 @@ int throw_flask(int obj, int sy, int sx)
     {
         y += sy;
         x += sx;
-        if ((mapmonster[y][x] != -1) &&
-            (monsters[mapmonster[y][x]].used))
+        if ((lvl.mons[y][x] != -1) &&
+            (monsters[lvl.mons[y][x]].used))
         {
-            struct mon *mptr = monsters + mapmonster[y][x];
+            struct mon *mptr = monsters + lvl.mons[y][x];
             switch (objects[obj].obj_id)
             {
             case PO_FLASK_WEAKNESS:
index f61f2b8..c70e671 100644 (file)
@@ -186,19 +186,19 @@ void newsym(int y, int x)
     {
         back_buffer[y][x] = &player_tile;
     }
-    else if ((!show_terrain) && (mapmonster[y][x] != -1) && mon_visible(mapmonster[y][x]))
+    else if ((!show_terrain) && (lvl.mons[y][x] != -1) && mon_visible(lvl.mons[y][x]))
     {
-        back_buffer[y][x] = monster_char(monsters[mapmonster[y][x]].mon_id);
+        back_buffer[y][x] = monster_char(monsters[lvl.mons[y][x]].mon_id);
     }
-    else if (mapflags[y][x] & MAPFLAG_EXPLORED)
+    else if (lvl.flags[y][x] & MAPFLAG_EXPLORED)
     {
-        if ((!show_terrain) && (mapobject[y][x] != -1))
+        if ((!show_terrain) && (lvl.objs[y][x] != -1))
         {
-            back_buffer[y][x] = object_char(objects[mapobject[y][x]].obj_id);
+            back_buffer[y][x] = object_char(objects[lvl.objs[y][x]].obj_id);
         }
         else
         {
-            back_buffer[y][x] = terrain_char(terrain[y][x]);
+            back_buffer[y][x] = terrain_char(lvl.terrain[y][x]);
         }
     }
     else
diff --git a/fov.cc b/fov.cc
index 092c90d..890e13f 100644 (file)
--- a/fov.cc
+++ b/fov.cc
@@ -67,7 +67,7 @@ static void compute_row(Radiance *rad, int octant, int radius, double inmost_slo
  */
 static bool dflt_blk(int y, int x)
 {
-    return ((y <= 0) || (x <= 0) || (y >= DUN_HEIGHT - 1) || (x >= DUN_WIDTH - 1) || (terrain_is_opaque(terrain[y][x])));
+    return ((y <= 0) || (x <= 0) || (y >= DUN_HEIGHT - 1) || (x >= DUN_WIDTH - 1) || (terrain_is_opaque(lvl.terrain[y][x])));
 }
 
 /*! \brief Function for marking affected cells as explored
@@ -77,7 +77,7 @@ static bool dflt_blk(int y, int x)
  */
 static bool mark_explored(int y, int x, void *pvt)
 {
-    mapflags[y][x] |= MAPFLAG_EXPLORED;
+    lvl.flags[y][x] |= MAPFLAG_EXPLORED;
     newsym(y, x);
     return true;
 }
diff --git a/main.cc b/main.cc
index 3f213d5..81f9b2a 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -53,7 +53,7 @@ static void rebuild_mapmons(void)
     {
         if (monsters[i].used)
         {
-            mapmonster[monsters[i].y][monsters[i].x] = i;
+            lvl.mons[monsters[i].y][monsters[i].x] = i;
         }
     }
 }
@@ -65,7 +65,7 @@ static void rebuild_mapobjs(void)
     {
         if (objects[i].used && !objects[i].with_you)
         {
-            mapobject[objects[i].y][objects[i].x] = i;
+            lvl.objs[objects[i].y][objects[i].x] = i;
         }
     }
 }
@@ -92,14 +92,14 @@ void save_game(void)
     /* Write out the map flags; if we decide to have at-generation
      * flags as well as at-exploration flags, the at-generation flags
      * will be stored in a separate array. */
-    fwrite(mapflags, DUN_HEIGHT, DUN_WIDTH * sizeof (int), fp);
+    fwrite(lvl.flags, 1, sizeof lvl.flags, fp);
     /* Write out the permanent object data. This is hideously
      * wasteful (and guarantees savefile breakage at version-up), but
      * it makes handling flavours much easier... */
-    fwrite(permobjs, 100, sizeof (struct permobj), fp);
+    fwrite(permobjs, NUM_OF_PERMOBJS, sizeof (struct permobj), fp);
     /* Write out the dynamic monster/object arrays. */
-    fwrite(monsters, 100, sizeof (struct mon), fp);
-    fwrite(objects, 100, sizeof (struct obj), fp);
+    fwrite(monsters, MONSTERS_IN_PLAY, sizeof (struct mon), fp);
+    fwrite(objects, OBJECTS_IN_PLAY, sizeof (struct obj), fp);
     /* Write out the depth */
     fwrite(&depth, 1, sizeof depth, fp);
     /* Write out the player. */
@@ -122,22 +122,22 @@ void load_game(void)
     fp = fopen("victrix-abyssi.sav", "rb");
     fread(rng_state, sizeof rng_state, 1, fp);
     build_level();
-    fread(mapflags, DUN_HEIGHT, DUN_WIDTH * sizeof (int), fp);
-    fread(permobjs, 100, sizeof (struct permobj), fp);
-    fread(monsters, 100, sizeof (struct mon), fp);
-    fread(objects, 100, sizeof (struct obj), fp);
+    fread(lvl.flags, 1, sizeof lvl.flags, fp);
+    fread(permobjs, NUM_OF_PERMOBJS, sizeof (struct permobj), fp);
+    fread(monsters, MONSTERS_IN_PLAY, sizeof (struct mon), fp);
+    fread(objects, OBJECTS_IN_PLAY, sizeof (struct obj), fp);
     rebuild_mapobjs();
     rebuild_mapmons();
     fread(&depth, 1, sizeof depth, fp);
     fread(&u, 1, sizeof u, fp);
     fread(&game_tick, 1, sizeof game_tick, fp);
     fclose(fp);
-    unlink("victrix-abyssi.sav");
     explore_around(u.y, u.x);
     status_updated = 1;
     map_updated = 1;
     hard_redraw = 1;
     print_msg("Game loaded.\n");
+    unlink("victrix-abyssi.sav");
 }
 
 int exclusive_flat(int lower, int upper)
@@ -227,7 +227,7 @@ int do_command(enum game_cmd cmd)
         return 0;
 
     case GET_ITEM:
-        if (mapobject[u.y][u.x] != -1)
+        if (lvl.objs[u.y][u.x] != -1)
         {
             attempt_pickup();
             return 1;
@@ -309,7 +309,7 @@ int do_command(enum game_cmd cmd)
         if (u.armour != -1)
         {
             if ((u.resistances[DT_FIRE] == RESIST_ARMOUR) &&
-                (terrain[u.y][u.x] == LAVA))
+                (lvl.terrain[u.y][u.x] == LAVA))
             {
                 print_msg("Your armour is your only current source of fire\nresistance; removing it here would incinerate you.\n");
                 return 0;
@@ -330,7 +330,7 @@ int do_command(enum game_cmd cmd)
         return 0;
 
     case GO_DOWN_STAIRS:
-        if (terrain[u.y][u.x] == STAIRS)
+        if (lvl.terrain[u.y][u.x] == STAIRS)
         {
             leave_level();
             make_new_level();
@@ -401,12 +401,12 @@ int do_command(enum game_cmd cmd)
             print_msg("You have no ring to remove!\n");
             return 0;
         }
-        else if ((terrain[u.y][u.x] == LAVA) && (u.resistances[DT_FIRE] == RESIST_RING))
+        else if ((lvl.terrain[u.y][u.x] == LAVA) && (u.resistances[DT_FIRE] == RESIST_RING))
         {
             print_msg("That ring is your only current source of fire resistance. Removing\nit here would incinerate you.\n");
             return 0;
         }
-        else if ((objects[u.ring].obj_id == PO_RING_FROST) && (terrain[u.y][u.x] == WATER))
+        else if ((objects[u.ring].obj_id == PO_RING_FROST) && (lvl.terrain[u.y][u.x] == WATER))
         {
             print_msg("Since nobody ever taught you to swim, removing that ring\nhere would result in your death by drowning.\n");
             return 0;
@@ -475,7 +475,7 @@ int do_command(enum game_cmd cmd)
         print_msg("1d32-1: %d %d %d %d %d %d %d %d\n", zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32));
         return 0;
     case DROP_ITEM:
-        if (mapobject[u.y][u.x] != -1)
+        if (lvl.objs[u.y][u.x] != -1)
         {
             print_msg("There is already an item here.\n");
             return 0;
@@ -617,8 +617,8 @@ int main(void)
     struct stat s;
     int i;
     display_init();
-    memset(mapobject, -1, sizeof mapobject);
-    memset(mapmonster, -1, sizeof mapmonster);
+    memset(lvl.objs, -1, sizeof lvl.objs);
+    memset(lvl.mons, -1, sizeof lvl.mons);
     /* Do we have a saved game? */
     i = stat("victrix-abyssi.sav.gz", &s);
     if (!i)
diff --git a/map.cc b/map.cc
index ca55395..0cb720a 100644 (file)
--- a/map.cc
+++ b/map.cc
 #include "fov.hh"
 
 #include <string.h>
-int mapobject[DUN_HEIGHT][DUN_WIDTH];
-int mapmonster[DUN_HEIGHT][DUN_WIDTH];
-enum terrain_num terrain[DUN_HEIGHT][DUN_WIDTH];
-int mapflags[DUN_HEIGHT][DUN_WIDTH];
+level lvl;
 int depth = 1;
-enum level_theme current_theme;
-enum level_layout current_layout;
 
 static int get_levgen_mon_floor(int *y, int *x);
 static void build_level_shrine(void);
@@ -48,10 +43,10 @@ static int intrusion_write(int y, int x, void *data);
 void leave_level(void)
 {
     int i;
-    memset(mapobject, -1, sizeof mapobject);
-    memset(mapmonster, -1, sizeof mapmonster);
-    memset(terrain, 0, sizeof terrain);
-    memset(mapflags, 0, sizeof mapflags);
+    memset(lvl.objs, -1, sizeof lvl.objs);
+    memset(lvl.mons, -1, sizeof lvl.mons);
+    memset(lvl.terrain, 0, sizeof lvl.terrain);
+    memset(lvl.flags, 0, sizeof lvl.flags);
     for (i = 0; i < 100; i++)
     {
         /* Throw away each monster */
@@ -146,33 +141,33 @@ void build_level(void)
     theme_roll = zero_die(depth + 50);
     if (!zero_die(4))
     {
-        current_layout = LAYOUT_CAVE_INTRUSIONS;
+        lvl.layout = LAYOUT_CAVE_INTRUSIONS;
     }
     else if ((depth >= 15) && !zero_die(6))
     {
-        current_layout = LAYOUT_CAVE_SHRINE;
+        lvl.layout = LAYOUT_CAVE_SHRINE;
     }
     else
     {
-        current_layout = LAYOUT_CLASSIC_CAVE;
+        lvl.layout = LAYOUT_CLASSIC_CAVE;
     }
     if ((theme_roll < 50) || (depth < 10))
     {
-        current_theme = THEME_NORMAL; /* no restrictions */
+        lvl.theme = THEME_NORMAL; /* no restrictions */
     }
     else if (theme_roll < 60)
     {
-        current_theme = THEME_UNDEAD;
+        lvl.theme = THEME_UNDEAD;
     }
     else if (theme_roll < 80)
     {
-        current_theme = THEME_DRAGONS;
+        lvl.theme = THEME_DRAGONS;
     }
     else if (theme_roll < 90)
     {
-        current_theme = THEME_DEMONS;
+        lvl.theme = THEME_DEMONS;
     }
-    switch (current_layout)
+    switch (lvl.layout)
     {
     case LAYOUT_CAVE_SHRINE:
         build_level_shrine();
@@ -197,7 +192,7 @@ void build_level_classic(void)
 
     run_random_walk(y, x, excavation_write, walk_data, LEVGEN_WALK_CELLS);
     run_random_walk(y, x, excavation_write, walk_data, LEVGEN_WALK_CELLS);
-    if ((current_theme != THEME_UNDEAD) && (depth > 20) && !zero_die(4))
+    if ((lvl.theme != THEME_UNDEAD) && (depth > 20) && !zero_die(4))
     {
         num_pools = inclusive_flat(1, 4);
         walk_data[0] = 2;
@@ -220,7 +215,7 @@ void build_level_classic(void)
         do {
             y = exclusive_flat(1, DUN_HEIGHT - 2);
             x = exclusive_flat(1, DUN_WIDTH - 2);
-        } while (terrain[y][x] != FLOOR);
+        } while (lvl.terrain[y][x] != FLOOR);
         run_random_walk(y, x, excavation_write, walk_data, pool_size);
         --num_pools;
     }
@@ -229,8 +224,8 @@ void build_level_classic(void)
     {
         y = exclusive_flat(0, DUN_HEIGHT - 1);
         x = exclusive_flat(0, DUN_WIDTH - 1);
-    } while (terrain[y][x] != FLOOR);
-    terrain[y][x] = STAIRS;
+    } while (lvl.terrain[y][x] != FLOOR);
+    lvl.terrain[y][x] = STAIRS;
 }
 
 struct shrine shrines[4] =
@@ -318,16 +313,16 @@ static void build_level_shrine(void)
             switch (shrines[shrine_num].grid[i][j])
             {
             case '.':
-                terrain[y][x] = FLOOR;
+                lvl.terrain[y][x] = FLOOR;
                 break;
             case '#':
-                terrain[y][x] = HARDWALL;
+                lvl.terrain[y][x] = HARDWALL;
                 break;
             case '+':
-                terrain[y][x] = DOOR;
+                lvl.terrain[y][x] = DOOR;
                 break;
             case '_':
-                terrain[y][x] = ALTAR;
+                lvl.terrain[y][x] = ALTAR;
                 break;
             }
         }
@@ -339,10 +334,10 @@ static void build_level_shrine(void)
     {
         y = exclusive_flat(0, DUN_HEIGHT - 1);
         x = exclusive_flat(0, DUN_WIDTH - 1);
-    } while ((terrain[y][x] != FLOOR) &&
+    } while ((lvl.terrain[y][x] != FLOOR) &&
              (y >= shrine_ty) && (y < shrine_ty + SHRINE_HEIGHT) &&
              (x >= shrine_lx) && (x < shrine_lx + SHRINE_WIDTH));
-    terrain[y][x] = STAIRS;
+    lvl.terrain[y][x] = STAIRS;
 }
 
 static int excavation_write(int y, int x, void *data)
@@ -351,7 +346,7 @@ static int excavation_write(int y, int x, void *data)
     const int *overwrite = data_as_ints + 2;
     int newterr = data_as_ints[1];
     int j;
-    if (mapflags[y][x] & MAPFLAG_HARDWALL)
+    if (lvl.flags[y][x] & MAPFLAG_HARDWALL)
     {
         /* Don't bite into hardened walls, but don't waste a step on
          * them either. */
@@ -359,9 +354,9 @@ static int excavation_write(int y, int x, void *data)
     }
     for (j = 0; j < data_as_ints[0]; ++j)
     {
-        if (terrain[y][x] == overwrite[j])
+        if (lvl.terrain[y][x] == overwrite[j])
         {
-            terrain[y][x] = (terrain_num) newterr;
+            lvl.terrain[y][x] = (terrain_num) newterr;
             return 1;
         }
     }
@@ -370,11 +365,11 @@ static int excavation_write(int y, int x, void *data)
 
 static int intrusion_write(int y, int x, void *data)
 {
-    if (terrain[y][x] != WALL)
+    if (lvl.terrain[y][x] != WALL)
     {
         return 0;
     }
-    if (mapflags[y][x] & MAPFLAG_HARDWALL)
+    if (lvl.flags[y][x] & MAPFLAG_HARDWALL)
     {
         return 0;
     }
@@ -387,8 +382,8 @@ static int intrusion_write(int y, int x, void *data)
     {
         return 2;
     }
-    mapflags[y][x] |= MAPFLAG_HARDWALL;
-    terrain[y][x] = HARDWALL;
+    lvl.flags[y][x] |= MAPFLAG_HARDWALL;
+    lvl.terrain[y][x] = HARDWALL;
     return 1;
 }
 
@@ -421,7 +416,7 @@ void build_level_intrusions(void)
                 y = inclusive_flat((2 * DUN_HEIGHT) / 3, DUN_HEIGHT - 2);
             }
             //print_msg("Trying y %d x %d for intrusion\n", y, x);
-        } while (mapflags[y][x] & MAPFLAG_HARDWALL);
+        } while (lvl.flags[y][x] & MAPFLAG_HARDWALL);
         intrusion_size = inclusive_flat(27, 54);
         //print_msg("Building intrusion %d size %d y %d x %d\n", i, intrusion_size, y, x);
         run_random_walk(y, x, intrusion_write, NULL, intrusion_size);
@@ -435,8 +430,8 @@ void build_level_intrusions(void)
     {
         y = exclusive_flat(0, DUN_HEIGHT - 1);
         x = exclusive_flat(0, DUN_WIDTH - 1);
-    } while (terrain[y][x] != FLOOR);
-    terrain[y][x] = STAIRS;
+    } while (lvl.terrain[y][x] != FLOOR);
+    lvl.terrain[y][x] = STAIRS;
 }
 
 int get_levgen_mon_floor(int *y, int *x)
@@ -447,8 +442,8 @@ int get_levgen_mon_floor(int *y, int *x)
     {
         ty = exclusive_flat(0, DUN_HEIGHT - 1);
         tx = exclusive_flat(0, DUN_WIDTH - 1);
-        if ((terrain[ty][tx] != FLOOR) ||
-            (mapmonster[ty][tx] != -1))
+        if ((lvl.terrain[ty][tx] != FLOOR) ||
+            (lvl.mons[ty][tx] != -1))
         {
             ty = -1;
             tx = -1;
@@ -506,11 +501,11 @@ void inject_player(void)
     {
         u.y = exclusive_flat(0, DUN_HEIGHT - 1);
         u.x = exclusive_flat(0, DUN_WIDTH - 1);
-        if (terrain[u.y][u.x] != FLOOR)
+        if (lvl.terrain[u.y][u.x] != FLOOR)
         {
             continue;
         }
-        if (mapmonster[u.y][u.x] != -1)
+        if (lvl.mons[u.y][u.x] != -1)
         {
             continue;
         }
diff --git a/map.hh b/map.hh
index 5f0d337..ffddbf4 100644 (file)
--- a/map.hh
+++ b/map.hh
@@ -72,10 +72,18 @@ struct shrine
 };
 
 /* XXX map.c data and funcs*/
-extern int mapobject[DUN_HEIGHT][DUN_WIDTH];
-extern int mapmonster[DUN_HEIGHT][DUN_WIDTH];
-extern enum terrain_num terrain[DUN_HEIGHT][DUN_WIDTH];
-extern int mapflags[DUN_HEIGHT][DUN_WIDTH];
+struct level
+{
+    int objs[DUN_HEIGHT][DUN_WIDTH];
+    int mons[DUN_HEIGHT][DUN_WIDTH];
+    terrain_num terrain[DUN_HEIGHT][DUN_WIDTH];
+    uint32_t flags[DUN_HEIGHT][DUN_WIDTH];
+    level_theme theme;
+    level_layout layout;
+};
+
+extern level lvl;
+
 extern int depth;
 extern enum level_theme current_theme;
 extern enum level_layout current_layout;
diff --git a/mon2.cc b/mon2.cc
index 84352a9..5519d8e 100644 (file)
--- a/mon2.cc
+++ b/mon2.cc
@@ -274,7 +274,7 @@ static void get_seeking_prefs(int y, int x, int dy, int dx, int *pref_y, int *pr
          *   Square closer to player: +1
          *   Square further from player: -1
          */
-        if (!mon_can_pass(mapmonster[y][x], ai_cells[i].y, ai_cells[i].x))
+        if (!mon_can_pass(lvl.mons[y][x], ai_cells[i].y, ai_cells[i].x))
         {
             /* Square impassable to this monster. Set score WAY
              * out of bounds and continue. */
@@ -501,7 +501,7 @@ static void get_dodger_prefs(int y, int x, int dy, int dx, int *pref_y, int *pre
          * closing. When I add more AI state to the monster structure,
          * this will change.
          */
-        if (!mon_can_pass(mapmonster[y][x], ai_cells[i].y, ai_cells[i].x))
+        if (!mon_can_pass(lvl.mons[y][x], ai_cells[i].y, ai_cells[i].x))
         {
             /* Square impassable. Set score WAY out of bounds
              * and continue. */
@@ -584,17 +584,17 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
     case 0:
         /* Simple convergence */
         get_naive_prefs(*py, *px, dy, dx, ai_y, ai_x);
-        if (mon_can_pass(mapmonster[*py][*px], ai_y[0], ai_x[0]))
+        if (mon_can_pass(lvl.mons[*py][*px], ai_y[0], ai_x[0]))
         {
             y = ai_y[0];
             x = ai_x[0];
         }
-        else if (mon_can_pass(mapmonster[*py][*px], ai_y[1], ai_x[1]))
+        else if (mon_can_pass(lvl.mons[*py][*px], ai_y[1], ai_x[1]))
         {
             y = ai_y[1];
             x = ai_x[1];
         }
-        else if (mon_can_pass(mapmonster[*py][*px], ai_y[2], ai_x[2]))
+        else if (mon_can_pass(lvl.mons[*py][*px], ai_y[2], ai_x[2]))
         {
             y = ai_y[2];
             x = ai_x[2];
@@ -612,18 +612,18 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
             /* On cardinal. Stay there if we can. But close anyway. */
             x = *px + sx;
             y = *py + sy;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             x = *px;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             y = *py;
             x = *px + sx;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
@@ -634,17 +634,17 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
              * off cardinal in y than in x */
             y = *py + sy;
             x = *px;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             x = *px + sx;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             y = *py;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
@@ -654,17 +654,17 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
             /* One step off a diagonal cardinal, with adx > ady */
             x = *px + sx;
             y = *py;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             y = *py + sy;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
             x = *px;
-            if (mon_can_pass(mapmonster[*py][*px], y, x))
+            if (mon_can_pass(lvl.mons[*py][*px], y, x))
             {
                 break;
             }
@@ -681,17 +681,17 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
         /* "Drunk" monster i.e. monster moving while it doesn't know
          * how to find you. */
         get_drunk_prefs(*py, *px, dy, dx, ai_y, ai_x);
-        if (mon_can_pass(mapmonster[*py][*px], ai_y[0], ai_x[0]))
+        if (mon_can_pass(lvl.mons[*py][*px], ai_y[0], ai_x[0]))
         {
             y = ai_y[0];
             x = ai_x[0];
         }
-        else if (mon_can_pass(mapmonster[*py][*px], ai_y[1], ai_x[1]))
+        else if (mon_can_pass(lvl.mons[*py][*px], ai_y[1], ai_x[1]))
         {
             y = ai_y[1];
             x = ai_x[1];
         }
-        else if (mon_can_pass(mapmonster[*py][*px], ai_y[2], ai_x[2]))
+        else if (mon_can_pass(lvl.mons[*py][*px], ai_y[2], ai_x[2]))
         {
             y = ai_y[2];
             x = ai_x[2];
@@ -712,7 +712,7 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode)
         break;
     case 5:
         /* "chase" AI i.e. pursue your last known position. */
-        get_chase_prefs(mapmonster[*py][*px], ai_y, ai_x);
+        get_chase_prefs(lvl.mons[*py][*px], ai_y, ai_x);
         y = ai_y[0];
         x = ai_x[0];
         break;
@@ -742,17 +742,17 @@ void mon_acts(int mon)
         print_msg("Program disordered: monster in player's square.\n");
         print_msg("Discarding misplaced monster.\n");
         mptr->used = 0;
-        mapmonster[y][x] = -1;
+        lvl.mons[y][x] = -1;
         return;
     }
-    if (mapmonster[y][x] != mon)
+    if (lvl.mons[y][x] != mon)
     {
         print_msg("Program disordered: monster(s) misplaced.\n");
         mptr->used = 0;
-        if (mapmonster[y][x] != -1)
+        if (lvl.mons[y][x] != -1)
         {
-            monsters[mapmonster[y][x]].used = 0;
-            mapmonster[y][x] = -1;
+            monsters[lvl.mons[y][x]].used = 0;
+            lvl.mons[y][x] = -1;
         }
         return;
     }
index e8d5c53..1c1b0e1 100644 (file)
@@ -48,8 +48,8 @@ int summoning(int y, int x, int how_many)
         {
             dy = zero_die(3) - 1;
             dx = zero_die(3) - 1;
-            if ((terrain[y + dy][x + dx] == FLOOR) &&
-                (mapmonster[y + dy][x + dx] == -1) &&
+            if ((lvl.terrain[y + dy][x + dx] == FLOOR) &&
+                (lvl.mons[y + dy][x + dx] == -1) &&
                 ((y + dy != u.y) || (x + dx != u.x)))
             {
                 pmon = get_random_pmon();
@@ -100,7 +100,7 @@ int get_random_pmon(void)
 int create_mon(int pm_idx, int y, int x)
 {
     int mon;
-    if (mapmonster[y][x] != -1)
+    if (lvl.mons[y][x] != -1)
     {
         print_msg("Attempt to create monster at occupied space %d %d\n", y, x);
         return -1;
@@ -139,7 +139,7 @@ int create_mon(int pm_idx, int y, int x)
                 monsters[mon].rdam = -1;
             }
             monsters[mon].awake = 0;
-            mapmonster[y][x] = mon;
+            lvl.mons[y][x] = mon;
             newsym(y, x);
             return mon;
         }
@@ -154,7 +154,7 @@ void death_drop(int mon)
     int x = monsters[mon].x;
     int dy, dx;
     int tryct;
-    while (((mapobject[y][x] != -1) || (terrain[y][x] != FLOOR)) && tryct < 100)
+    while (((lvl.objs[y][x] != -1) || (lvl.terrain[y][x] != FLOOR)) && tryct < 100)
     {
         dy = zero_die(3) - 1;
         dx = zero_die(3) - 1;
@@ -238,7 +238,7 @@ int mon_can_pass(int mon, int y, int x)
     {
         return 0;
     }
-    if (mapmonster[y][x] != -1)
+    if (lvl.mons[y][x] != -1)
     {
         return 0;
     }
@@ -251,7 +251,7 @@ int mon_can_pass(int mon, int y, int x)
     {
         return 1;
     }
-    terr = terrain[y][x];
+    terr = lvl.terrain[y][x];
     switch (terr)
     {
     case WALL:
@@ -271,7 +271,7 @@ int mon_can_pass(int mon, int y, int x)
     default:
         break;
     }
-    if ((terrain[y][x] == WATER) && !mon_resists_drowning(mon))
+    if ((lvl.terrain[y][x] == WATER) && !mon_resists_drowning(mon))
     {
         return 0;
     }
@@ -345,7 +345,7 @@ void damage_mon(int mon, int amount, int by_you)
             print_msg(" dies.\n");
         }
         death_drop(mon);
-        mapmonster[mptr->y][mptr->x] = -1;
+        lvl.mons[mptr->y][mptr->x] = -1;
         newsym(mptr->y, mptr->x);
         mptr->used = 0;
         map_updated = 1;
@@ -403,7 +403,7 @@ int teleport_mon(int mon)
     {
         y = exclusive_flat(0, DUN_HEIGHT - 1);
         x = exclusive_flat(0, DUN_WIDTH - 1);
-        if ((mapmonster[y][x] == -1) && (terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x)))
+        if ((lvl.mons[y][x] == -1) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x)))
         {
             reloc_mon(mon, y, x);
             rval = 0;
@@ -419,7 +419,7 @@ int knockback_mon(int mon, int sy, int sx, bool cansee, bool by_you)
     struct mon *mptr = monsters + mon;
     int y = mptr->y + sy;
     int x = mptr->x + sx;
-    enum terrain_num terr = terrain[y][x];
+    enum terrain_num terr = lvl.terrain[y][x];
 
     if (mon_resists_knockback(mon))
     {
@@ -501,11 +501,11 @@ int knockback_mon(int mon, int sy, int sx, bool cansee, bool by_you)
 void reloc_mon(int mon, int y, int x)
 {
     struct mon *mptr = monsters + mon;
-    mapmonster[mptr->y][mptr->x] = -1;
+    lvl.mons[mptr->y][mptr->x] = -1;
     newsym(mptr->y, mptr->x);
     mptr->y = y;
     mptr->x = x;
-    mapmonster[mptr->y][mptr->x] = mon;
+    lvl.mons[mptr->y][mptr->x] = mon;
     newsym(mptr->y, mptr->x);
 }
 
@@ -518,7 +518,7 @@ void move_mon(int mon, int y, int x)
         return;
     }
     mptr = monsters + mon;
-    if (mapmonster[mptr->y][mptr->x] != mon)
+    if (lvl.mons[mptr->y][mptr->x] != mon)
     {
         print_msg("Monster map array in disorder.\n");
         press_enter();
@@ -534,7 +534,7 @@ void summon_demon_near(int y, int x)
     int i;
     y2 = y - 1 + zero_die(3);
     x2 = x - 1 + zero_die(3);
-    if ((terrain[y2][x2] == FLOOR) && (mapmonster[y2][x2] == -1) &&
+    if ((lvl.terrain[y2][x2] == FLOOR) && (lvl.mons[y2][x2] == -1) &&
         ((y2 != u.y) || (x2 != u.x)))
     {
         i = create_mon(PM_DEMON, y2, x2);
index 2ec5d4b..91404a5 100644 (file)
@@ -453,7 +453,7 @@ int create_obj(int po_idx, int quantity, int with_you, int y, int x)
     }
     if (!objects[i].with_you)
     {
-        mapobject[y][x] = i;
+        lvl.objs[y][x] = i;
     }
     return i;
 }
@@ -537,11 +537,11 @@ int drop_obj(int inv_idx)
 {
     struct obj *optr;
     optr = objects + u.inventory[inv_idx];
-    if (mapobject[u.y][u.x] == -1)
+    if (lvl.objs[u.y][u.x] == -1)
     {
         optr->y = u.y;
         optr->x = u.x;
-        mapobject[u.y][u.x] = u.inventory[inv_idx];
+        lvl.objs[u.y][u.x] = u.inventory[inv_idx];
         if (u.weapon == u.inventory[inv_idx])
         {
             u.weapon = -1;
@@ -549,7 +549,7 @@ int drop_obj(int inv_idx)
         u.inventory[inv_idx] = -1;
         optr->with_you = 0;
         print_msg("You drop ");
-        print_obj_name(mapobject[u.y][u.x]);
+        print_obj_name(lvl.objs[u.y][u.x]);
         print_msg(".\n");
         return 0;
     }
@@ -577,19 +577,19 @@ void attempt_pickup(void)
 {
     int i;
     int stackable;
-    stackable = po_is_stackable(objects[mapobject[u.y][u.x]].obj_id);
+    stackable = po_is_stackable(objects[lvl.objs[u.y][u.x]].obj_id);
     if (stackable)
     {
         for (i = 0; i < 19; i++)
         {
-            if ((objects[u.inventory[i]].obj_id == objects[mapobject[u.y][u.x]].obj_id))
+            if ((objects[u.inventory[i]].obj_id == objects[lvl.objs[u.y][u.x]].obj_id))
             {
                 print_msg("You get ");
-                print_obj_name(mapobject[u.y][u.x]);
+                print_obj_name(lvl.objs[u.y][u.x]);
                 print_msg(".\nYou now have\n");
-                objects[u.inventory[i]].quan += objects[mapobject[u.y][u.x]].quan;
-                objects[mapobject[u.y][u.x]].used = 0;
-                mapobject[u.y][u.x] = -1;
+                objects[u.inventory[i]].quan += objects[lvl.objs[u.y][u.x]].quan;
+                objects[lvl.objs[u.y][u.x]].used = 0;
+                lvl.objs[u.y][u.x] = -1;
                 print_msg("%c) ", 'a' + i);
                 print_obj_name(u.inventory[i]);
                 print_msg("\n");
@@ -609,8 +609,8 @@ void attempt_pickup(void)
         print_msg("Your pack is full.\n");
         return;
     }
-    u.inventory[i] = mapobject[u.y][u.x];
-    mapobject[u.y][u.x] = -1;
+    u.inventory[i] = lvl.objs[u.y][u.x];
+    lvl.objs[u.y][u.x] = -1;
     objects[u.inventory[i]].with_you = 1;
     objects[u.inventory[i]].x = -1;
     objects[u.inventory[i]].y = -1;
@@ -797,14 +797,14 @@ int zap_weapon(void)
                     {
                         continue;
                     }
-                    if (mapmonster[y][x] != -1)
+                    if (lvl.mons[y][x] != -1)
                     {
-                        struct mon *mptr = monsters + mapmonster[y][x];
+                        struct mon *mptr = monsters + lvl.mons[y][x];
                         if (!pmon_resists_fire(mptr->mon_id))
                         {
-                            print_mon_name(mapmonster[y][x], 3);
+                            print_mon_name(lvl.mons[y][x], 3);
                             print_msg(" is engulfed in roaring flames.\n");
-                            damage_mon(mapmonster[y][x], dice(4, 10), 1);
+                            damage_mon(lvl.mons[y][x], dice(4, 10), 1);
                         }
                     }
                 }
diff --git a/u.cc b/u.cc
index 6c4359e..9374013 100644 (file)
--- a/u.cc
+++ b/u.cc
@@ -90,7 +90,7 @@ int move_player(int dy, int dx)
         print_msg("Attempted move out of bounds.\n");
         return 0;       /* No movement. */
     }
-    if (mapmonster[u.y + dy][u.x + dx] != -1)
+    if (lvl.mons[u.y + dy][u.x + dx] != -1)
     {
         if (u.weapon != -1)
         {
@@ -103,7 +103,7 @@ int move_player(int dy, int dx)
         }
         return player_attack(dy, dx);
     }
-    switch (terrain[u.y + dy][u.x + dx])
+    switch (lvl.terrain[u.y + dy][u.x + dx])
     {
     case WALL:
     case HARDWALL:
@@ -118,7 +118,7 @@ int move_player(int dy, int dx)
     case LAVA:
         if (u.resistances[DT_FIRE])
         {
-            if (terrain[u.y][u.x] != LAVA)
+            if (lvl.terrain[u.y][u.x] != LAVA)
             {
                 print_msg("You walk on the lava.\n");
             }
@@ -133,7 +133,7 @@ int move_player(int dy, int dx)
     case WATER:
         if ((u.ring != -1) && (objects[u.ring].obj_id == PO_RING_FROST))
         {
-            if (terrain[u.y][u.x] != WATER)
+            if (lvl.terrain[u.y][u.x] != WATER)
             {
                 print_msg("You walk on the water.\n");
             }
@@ -163,10 +163,10 @@ int reloc_player(int y, int x)
     map_updated = 1;
     status_updated = 1;
     display_update();
-    if (mapobject[y][x] != -1)
+    if (lvl.objs[y][x] != -1)
     {
         print_msg("You see here ");
-        print_obj_name(mapobject[y][x]);
+        print_obj_name(lvl.objs[y][x]);
         print_msg(".\n");
     }
     return 0;
@@ -564,7 +564,7 @@ int teleport_u(void)
     {
         y = exclusive_flat(0, DUN_HEIGHT - 1);
         x = exclusive_flat(0, DUN_WIDTH - 1);
-        if ((mapmonster[y][x] == -1) && (terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x)))
+        if ((lvl.mons[y][x] == -1) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x)))
         {
             print_msg("You are whisked away!\n");
             reloc_player(y, x);