From 37fa908ee1771a94b5e8b7a69205675a5ca1235f Mon Sep 17 00:00:00 2001 From: haranp Date: Sun, 15 Jun 2008 22:01:43 +0000 Subject: General code cleanups. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5867 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/decks.cc | 2 +- crawl-ref/source/items.cc | 27 +++++++++------------------ crawl-ref/source/misc.cc | 29 ++++++++++++----------------- crawl-ref/source/misc.h | 2 +- crawl-ref/source/view.cc | 2 +- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc index 629944a5c5..395e2032eb 100644 --- a/crawl-ref/source/decks.cc +++ b/crawl-ref/source/decks.cc @@ -2338,7 +2338,7 @@ static bool _trowel_card(int power, deck_rarity_type rarity) else { // Do-nothing (effectively): create a cosmetic feature - coord_def pos = pick_adjacent_free_square(you.x_pos, you.y_pos); + const coord_def pos = pick_adjacent_free_square(you.pos()); if ( pos.x >= 0 && pos.y >= 0 ) { const dungeon_feature_type statfeat[] = { diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 60a6e39bf8..5e5eba7580 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -366,9 +366,6 @@ int get_item_slot( int reserve ) void unlink_item( int dest ) { - int c = 0; - int cy = 0; - // Don't destroy non-items, may be called after an item has been // reduced to zero quantity however. if (dest == NON_ITEM || !is_valid_item( mitm[dest] )) @@ -380,14 +377,14 @@ void unlink_item( int dest ) // although it also contains items that are not linked in yet. // // Check if a monster has it: - for (c = 0; c < MAX_MONSTERS; c++) + for (int c = 0; c < MAX_MONSTERS; c++) { - struct monsters *monster = &menv[c]; + monsters *monster = &menv[c]; if (monster->type == -1) continue; - for (cy = 0; cy < NUM_MONSTER_SLOTS; cy++) + for (int cy = 0; cy < NUM_MONSTER_SLOTS; cy++) { if (monster->inv[cy] == dest) { @@ -428,7 +425,7 @@ void unlink_item( int dest ) } // Okay, item is buried, find item that's on top of it. - for (c = igrd[ mitm[dest].x ][ mitm[dest].y ]; c != NON_ITEM; + for (int c = igrd[ mitm[dest].x ][ mitm[dest].y ]; c != NON_ITEM; c = mitm[c].link) { // Find item linking to dest item. @@ -466,7 +463,7 @@ void unlink_item( int dest ) mitm[dest].props.clear(); // Look through all items for links to this item. - for (c = 0; c < MAX_ITEMS; c++) + for (int c = 0; c < MAX_ITEMS; c++) { if (is_valid_item( mitm[c] ) && mitm[c].link == dest) { @@ -482,8 +479,8 @@ void unlink_item( int dest ) } // Now check the grids to see if it's linked as a list top. - for (c = 2; c < (GXM - 1); c++) - for (cy = 2; cy < (GYM - 1); cy++) + for (int c = 2; c < (GXM - 1); c++) + for (int cy = 2; cy < (GYM - 1); cy++) { if (igrd[c][cy] == dest) { @@ -604,10 +601,7 @@ void lose_item_stack( int x, int y ) if (is_valid_item( mitm[o] )) { item_was_lost(mitm[o]); - - mitm[o].base_type = OBJ_UNASSIGNED; - mitm[o].quantity = 0; - mitm[o].props.clear(); + mitm[o].clear(); } o = next; @@ -627,10 +621,7 @@ void destroy_item_stack( int x, int y, int cause ) if (is_valid_item( mitm[o] )) { item_was_destroyed(mitm[o], cause); - - mitm[o].base_type = OBJ_UNASSIGNED; - mitm[o].quantity = 0; - mitm[o].props.clear(); + mitm[o].clear(); } o = next; diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index ca152ad59f..495d3459b6 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -2396,11 +2396,10 @@ bool i_feel_safe(bool announce, bool want_move, bool just_monsters, int range) { if (!just_monsters) { - if (in_bounds(you.x_pos, you.y_pos) - && env.cgrid[you.x_pos][you.y_pos] != EMPTY_CLOUD) + // check clouds + if (in_bounds(you.pos()) && env.cgrid(you.pos()) != EMPTY_CLOUD) { - const cloud_type type = - env.cloud[ env.cgrid[you.x_pos][you.y_pos] ].type; + const cloud_type type = env.cloud[env.cgrid(you.pos())].type; if (is_damaging_cloud(type, false)) { @@ -2557,7 +2556,7 @@ void setup_environment_effects() static void apply_environment_effect(const coord_def &c) { - const int grid = grd[c.x][c.y]; + const dungeon_feature_type grid = grd(c); if (grid == DNGN_LAVA) check_place_cloud( CLOUD_BLACK_SMOKE, c.x, c.y, random_range( 4, 8 ), KC_OTHER ); @@ -2604,19 +2603,20 @@ void run_environment_effects() run_corruption_effects(you.time_taken); } -coord_def pick_adjacent_free_square(int x, int y) +coord_def pick_adjacent_free_square(const coord_def& p) { int num_ok = 0; coord_def result(-1, -1); - for ( int ux = x-1; ux <= x+1; ++ux ) + for ( int ux = p.x-1; ux <= p.x+1; ++ux ) { - for ( int uy = y-1; uy <= y+1; ++uy ) + for ( int uy = p.y-1; uy <= p.y+1; ++uy ) { - if ( ux == x && uy == y ) + if ( ux == p.x && uy == p.y ) continue; - if ( ux >= 0 && ux < GXM && uy >= 0 && uy < GYM && - grd[ux][uy] == DNGN_FLOOR && mgrd[ux][uy] == NON_MONSTER ) + if ( in_bounds(ux, uy) + && grd[ux][uy] == DNGN_FLOOR + && mgrd[ux][uy] == NON_MONSTER ) { ++num_ok; if ( one_chance_in(num_ok) ) @@ -2669,12 +2669,7 @@ std::string your_hand(bool plural) case TRAN_NONE: case TRAN_STATUE: case TRAN_LICH: - if (you.has_usable_claws()) - { - result = "claw"; - break; - } - // deliberate fall through + result = (you.has_usable_claws() ? "claw" : "hand"); case TRAN_ICE_BEAST: result = "hand"; break; diff --git a/crawl-ref/source/misc.h b/crawl-ref/source/misc.h index a5fc5d9083..d10eb8ccb5 100644 --- a/crawl-ref/source/misc.h +++ b/crawl-ref/source/misc.h @@ -121,7 +121,7 @@ int str_to_shoptype(const std::string &s); bool player_in_a_dangerous_place(); -coord_def pick_adjacent_free_square(int x, int y); +coord_def pick_adjacent_free_square(const coord_def& p); int speed_to_duration(int speed); diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index ca754b3d44..c92df920e1 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -5704,7 +5704,7 @@ void monster_los::check_los_beam(int dx, int dy) while (dist++ <= max_dist) { - // The ray brings is out of bounds of the level map. + // The ray brings us out of bounds of the level map. // Since we're always shooting outwards there's nothing more // to look at in that direction, and we can break the loop. if (!map_bounds(ray.x(), ray.y())) -- cgit v1.2.3-54-g00ecf