summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-31 18:41:16 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-31 18:41:16 +0000
commit0ca19d27dea350d314c9aa6d6c733bc6d15b5af6 (patch)
treea5e76b1c45e527471c54ea788ba98b7c58cf426a
parent522d82aa2e3f30bba891843b44904741ab790659 (diff)
downloadcrawl-ref-0ca19d27dea350d314c9aa6d6c733bc6d15b5af6.tar.gz
crawl-ref-0ca19d27dea350d314c9aa6d6c733bc6d15b5af6.zip
Code cleanups, mainly in clouds.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8865 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/abl-show.cc8
-rw-r--r--crawl-ref/source/acr.cc75
-rw-r--r--crawl-ref/source/cloud.cc129
-rw-r--r--crawl-ref/source/tutorial.cc23
-rw-r--r--crawl-ref/source/tutorial.h5
-rw-r--r--crawl-ref/source/view.cc34
-rw-r--r--crawl-ref/source/view.h39
7 files changed, 133 insertions, 180 deletions
diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index 6c09050df8..9ee74cd549 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -2350,16 +2350,14 @@ static int _is_god_ability(int abil)
return (GOD_NO_GOD);
}
-void set_god_ability_slots(void)
+void set_god_ability_slots()
{
ASSERT(you.religion != GOD_NO_GOD);
- int i;
-
_set_god_ability_helper(ABIL_RENOUNCE_RELIGION, 'X');
// Clear out other god invocations.
- for (i = 0; i < 52; i++)
+ for (int i = 0; i < 52; i++)
{
const int god = _is_god_ability(you.ability_letter_table[i]);
if (god != GOD_NO_GOD && god != you.religion)
@@ -2368,7 +2366,7 @@ void set_god_ability_slots(void)
// Finally, add in current god's invocations in traditional slots.
int num = 0;
- for (i = 0; i < MAX_GOD_ABILITIES; ++i)
+ for (int i = 0; i < MAX_GOD_ABILITIES; ++i)
{
if (god_abilities[you.religion][i] != ABIL_NON_ABILITY)
{
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index db19ec7c91..d1eb144496 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -274,10 +274,11 @@ int main( int argc, char *argv[] )
else
learned_something_new(TUT_LOAD_SAVED_GAME);
+ _prep_input();
+
// Catch up on any experience levels we did not assign last time. This
// can happen if Crawl sees SIGHUP while it is waiting for the player
// to dismiss a level-up prompt.
- _prep_input();
level_change();
while (true)
@@ -2492,6 +2493,41 @@ static void _check_sanctuary()
decrease_sanctuary_radius();
}
+static void _regenerate_hp_and_mp()
+{
+ // XXX: using an int tmp to fix the fact that hit_points_regeneration
+ // is only an unsigned char and is thus likely to overflow. -- bwr
+ int tmp = you.hit_points_regeneration;
+
+ if (you.hp < you.hp_max && !you.disease && !you.duration[DUR_DEATHS_DOOR])
+ tmp += player_regen();
+
+ while (tmp >= 100)
+ {
+ inc_hp(1, false);
+ tmp -= 100;
+ }
+
+ ASSERT( tmp >= 0 && tmp < 100 );
+ you.hit_points_regeneration = static_cast<unsigned char>(tmp);
+
+ // XXX: Doing the same as the above, although overflow isn't an
+ // issue with magic point regeneration, yet. -- bwr
+ tmp = you.magic_points_regeneration;
+
+ if (you.magic_points < you.max_magic_points)
+ tmp += 7 + you.max_magic_points / 2;
+
+ while (tmp >= 100)
+ {
+ inc_mp(1, false);
+ tmp -= 100;
+ }
+
+ ASSERT( tmp >= 0 && tmp < 100 );
+ you.magic_points_regeneration = static_cast<unsigned char>(tmp);
+}
+
void world_reacts()
{
crawl_state.clear_mon_acting();
@@ -2518,9 +2554,7 @@ void world_reacts()
}
_check_banished();
-
_check_shafts();
-
_check_sanctuary();
run_environment_effects();
@@ -2560,41 +2594,10 @@ void world_reacts()
_decrement_durations();
const int food_use = player_hunger_rate();
-
if (food_use > 0 && you.hunger >= 40)
- make_hungry( food_use, true );
-
- // XXX: using an int tmp to fix the fact that hit_points_regeneration
- // is only an unsigned char and is thus likely to overflow. -- bwr
- int tmp = static_cast< int >( you.hit_points_regeneration );
-
- if (you.hp < you.hp_max && !you.disease && !you.duration[DUR_DEATHS_DOOR])
- tmp += player_regen();
-
- while (tmp >= 100)
- {
- inc_hp(1, false);
- tmp -= 100;
- }
+ make_hungry(food_use, true);
- ASSERT( tmp >= 0 && tmp < 100 );
- you.hit_points_regeneration = static_cast< unsigned char >( tmp );
-
- // XXX: Doing the same as the above, although overflow isn't an
- // issue with magic point regeneration, yet. -- bwr
- tmp = static_cast< int >( you.magic_points_regeneration );
-
- if (you.magic_points < you.max_magic_points)
- tmp += 7 + you.max_magic_points / 2;
-
- while (tmp >= 100)
- {
- inc_mp(1, false);
- tmp -= 100;
- }
-
- ASSERT( tmp >= 0 && tmp < 100 );
- you.magic_points_regeneration = static_cast< unsigned char >( tmp );
+ _regenerate_hp_and_mp();
// If you're wielding a rod, it'll gradually recharge.
_recharge_rods();
diff --git a/crawl-ref/source/cloud.cc b/crawl-ref/source/cloud.cc
index 4280700571..a102053972 100644
--- a/crawl-ref/source/cloud.cc
+++ b/crawl-ref/source/cloud.cc
@@ -27,11 +27,10 @@ REVISION("$Rev$");
#include "terrain.h"
#include "view.h"
-// Returns true if this cloud spreads out as it dissipates.
-static unsigned char _actual_spread_rate(cloud_type type, int spread_rate)
+static int _actual_spread_rate(cloud_type type, int spread_rate)
{
if (spread_rate >= 0)
- return (unsigned char) spread_rate;
+ return spread_rate;
switch (type)
{
@@ -67,17 +66,18 @@ static void _new_cloud( int cloud, cloud_type type, const coord_def& p,
int decay, kill_category whose, killer_type killer,
unsigned char spread_rate )
{
- ASSERT( env.cloud[ cloud ].type == CLOUD_NONE );
-
+ ASSERT( env.cloud[cloud].type == CLOUD_NONE );
ASSERT(_killer_whose_match(whose, killer));
- env.cloud[ cloud ].type = type;
- env.cloud[ cloud ].decay = decay;
- env.cloud[ cloud ].pos = p;
- env.cloud[ cloud ].whose = whose;
- env.cloud[ cloud ].killer = killer;
- env.cloud[ cloud ].spread_rate = spread_rate;
- env.cgrid(p) = cloud;
+ cloud_struct& c = env.cloud[cloud];
+
+ c.type = type;
+ c.decay = decay;
+ c.pos = p;
+ c.whose = whose;
+ c.killer = killer;
+ c.spread_rate = spread_rate;
+ env.cgrid(p) = cloud;
env.cloud_no++;
}
@@ -131,8 +131,9 @@ static int _spread_cloud(const cloud_struct &cloud)
return (extra_decay);
}
-static void _dissipate_cloud(int cc, cloud_struct &cloud, int dissipate)
+static void _dissipate_cloud(int cloudidx, int dissipate)
{
+ cloud_struct &cloud = env.cloud[cloudidx];
// Apply calculated rate to the actual cloud.
cloud.decay -= dissipate;
@@ -144,54 +145,46 @@ static void _dissipate_cloud(int cc, cloud_struct &cloud, int dissipate)
// Check for total dissipation and handle accordingly.
if (cloud.decay < 1)
- delete_cloud( cc );
+ delete_cloud(cloudidx);
}
-void manage_clouds(void)
+void manage_clouds()
{
- // Amount which cloud dissipates - must be unsigned! {dlb}
- unsigned int dissipate = 0;
-
- for (unsigned char cc = 0; cc < MAX_CLOUDS; cc++)
+ for (int i = 0; i < MAX_CLOUDS; ++i)
{
- if (env.cloud[cc].type == CLOUD_NONE) // No cloud -> next iteration.
+ cloud_struct& cloud = env.cloud[i];
+
+ if (cloud.type == CLOUD_NONE)
continue;
- dissipate = you.time_taken;
+ int dissipate = you.time_taken;
- // water -> flaming clouds:
- // lava -> freezing clouds:
- if (env.cloud[cc].type == CLOUD_FIRE
- && grd(env.cloud[cc].pos) == DNGN_DEEP_WATER)
- {
+ // Fire clouds dissipate faster over water,
+ // cold clouds dissipate faster over lava.
+ if (cloud.type == CLOUD_FIRE && grd(cloud.pos) == DNGN_DEEP_WATER)
dissipate *= 4;
- }
- else if (env.cloud[cc].type == CLOUD_COLD
- && grd(env.cloud[cc].pos) == DNGN_LAVA)
- {
+ else if (cloud.type == CLOUD_COLD && grd(cloud.pos) == DNGN_LAVA)
dissipate *= 4;
- }
- expose_items_to_element(cloud2beam(env.cloud[cc].type),
- env.cloud[cc].pos, 2);
+ expose_items_to_element(cloud2beam(cloud.type), cloud.pos, 2);
- _dissipate_cloud(cc, env.cloud[cc], dissipate);
+ _dissipate_cloud(i, dissipate);
}
}
void delete_cloud( int cloud )
{
- if (env.cloud[ cloud ].type != CLOUD_NONE)
+ cloud_struct& c = env.cloud[cloud];
+ if (c.type != CLOUD_NONE)
{
- const coord_def cloud_pos = env.cloud[ cloud ].pos;
-
- env.cloud[ cloud ].type = CLOUD_NONE;
- env.cloud[ cloud ].decay = 0;
- env.cloud[ cloud ].pos.reset();
- env.cloud[ cloud ].whose = KC_OTHER;
- env.cloud[ cloud ].killer = KILL_NONE;
- env.cloud[ cloud ].spread_rate = 0;
- env.cgrid(cloud_pos) = EMPTY_CLOUD;
+ c.type = CLOUD_NONE;
+ c.decay = 0;
+ c.whose = KC_OTHER;
+ c.killer = KILL_NONE;
+ c.spread_rate = 0;
+
+ env.cgrid(c.pos) = EMPTY_CLOUD;
+ c.pos.reset();
env.cloud_no--;
}
}
@@ -243,10 +236,8 @@ void check_place_cloud( cloud_type cl_type, const coord_def& p, int lifetime,
int steam_cloud_damage(const cloud_struct &cloud)
{
int decay = cloud.decay;
- if (decay > 60)
- decay = 60;
- else if (decay < 10)
- decay = 10;
+ decay = std::min(decay, 60);
+ decay = std::max(decay, 10);
// Damage in range 3 - 16.
return ((decay * 13 + 20) / 50);
@@ -284,49 +275,47 @@ void place_cloud(cloud_type cl_type, const coord_def& ctarget, int cl_range,
int cl_new = -1;
const int target_cgrid = env.cgrid(ctarget);
-
- // that is, another cloud already there {dlb}
if (target_cgrid != EMPTY_CLOUD)
{
- if (env.cloud[ target_cgrid ].type >= CLOUD_GREY_SMOKE
- && env.cloud[ target_cgrid ].type <= CLOUD_STEAM
- || env.cloud[ target_cgrid ].type == CLOUD_STINK
- || env.cloud[ target_cgrid ].type == CLOUD_BLACK_SMOKE
- || env.cloud[ target_cgrid ].type == CLOUD_MIST
- || env.cloud[ target_cgrid ].decay <= 20) //soon gone
+ // There's already a cloud here. See if we can overwrite it.
+ cloud_struct& old_cloud = env.cloud[target_cgrid];
+ if (old_cloud.type >= CLOUD_GREY_SMOKE && old_cloud.type <= CLOUD_STEAM
+ || old_cloud.type == CLOUD_STINK
+ || old_cloud.type == CLOUD_BLACK_SMOKE
+ || old_cloud.type == CLOUD_MIST
+ || old_cloud.decay <= 20) // soon gone
{
- cl_new = env.cgrid(ctarget);
- delete_cloud( env.cgrid(ctarget) );
+ // Delete this cloud and replace it.
+ cl_new = target_cgrid;
+ delete_cloud(target_cgrid);
}
- else
- {
+ else // Guess not.
return;
- }
}
- unsigned char spread_rate = _actual_spread_rate( cl_type, _spread_rate );
+ const int spread_rate = _actual_spread_rate(cl_type, _spread_rate);
// Too many clouds.
if (env.cloud_no >= MAX_CLOUDS)
{
// Default to random in case there's no low quality clouds.
- int cl_del = random2( MAX_CLOUDS );
+ int cl_del = random2(MAX_CLOUDS);
for (int ci = 0; ci < MAX_CLOUDS; ci++)
{
- if (env.cloud[ ci ].type >= CLOUD_GREY_SMOKE
- && env.cloud[ ci ].type <= CLOUD_STEAM
- || env.cloud[ ci ].type == CLOUD_STINK
- || env.cloud[ ci ].type == CLOUD_BLACK_SMOKE
- || env.cloud[ ci ].type == CLOUD_MIST
- || env.cloud[ ci ].decay <= 20) //soon gone
+ cloud_struct& cloud = env.cloud[ci];
+ if (cloud.type >= CLOUD_GREY_SMOKE && cloud.type <= CLOUD_STEAM
+ || cloud.type == CLOUD_STINK
+ || cloud.type == CLOUD_BLACK_SMOKE
+ || cloud.type == CLOUD_MIST
+ || cloud.decay <= 20) // soon gone
{
cl_del = ci;
break;
}
}
- delete_cloud( cl_del );
+ delete_cloud(cl_del);
cl_new = cl_del;
}
diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc
index 79db961492..f5c8d62edc 100644
--- a/crawl-ref/source/tutorial.cc
+++ b/crawl-ref/source/tutorial.cc
@@ -3950,3 +3950,26 @@ void tutorial_describe_monster(const monsters *mons)
linebreak_string2(broken, _get_tutorial_cols());
formatted_string::parse_block(broken, false).display();
}
+
+void tutorial_observe_cell(const coord_def& gc)
+{
+ if (grid_is_escape_hatch(grd(gc)))
+ learned_something_new(TUT_SEEN_ESCAPE_HATCH, gc);
+ else if (grid_is_branch_stairs(grd(gc)))
+ learned_something_new(TUT_SEEN_BRANCH, gc);
+ else if (is_feature('>', gc))
+ learned_something_new(TUT_SEEN_STAIRS, gc);
+ else if (is_feature('_', gc))
+ learned_something_new(TUT_SEEN_ALTAR, gc);
+ else if (grd(gc) == DNGN_CLOSED_DOOR)
+ learned_something_new(TUT_SEEN_DOOR, gc);
+ else if (grd(gc) == DNGN_ENTER_SHOP)
+ learned_something_new(TUT_SEEN_SHOP, gc);
+
+ if (igrd(gc) != NON_ITEM
+ && Options.feature_item_brand != CHATTR_NORMAL
+ && (is_feature('>', gc) || is_feature('<', gc)))
+ {
+ learned_something_new(TUT_STAIR_BRAND, gc);
+ }
+}
diff --git a/crawl-ref/source/tutorial.h b/crawl-ref/source/tutorial.h
index 5811ef5b8a..f8a75d570e 100644
--- a/crawl-ref/source/tutorial.h
+++ b/crawl-ref/source/tutorial.h
@@ -44,11 +44,13 @@ void tut_gained_new_skill(int skill);
void tutorial_first_monster(const monsters& mon);
void tutorial_first_item(const item_def& item);
void learned_something_new(tutorial_event_type seen_what,
- coord_def gc = coord_def(0,0));
+ coord_def gc = coord_def());
formatted_string tut_abilities_info(void);
void print_tut_skills_info(void);
void print_tut_skills_description_info(void);
+void tutorial_observe_cell(const coord_def& gc);
+
// Additional information for tutorial players.
void tutorial_describe_item(const item_def &item);
void tutorial_inscription_info(bool autoinscribe, std::string prompt);
@@ -59,4 +61,5 @@ void tutorial_describe_feature(dungeon_feature_type feat);
bool tutorial_monster_interesting(const monsters *mons);
void tutorial_describe_monster(const monsters *mons);
+
#endif
diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc
index dce2984de8..6bd9e82b11 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -5180,36 +5180,12 @@ void viewwindow(bool draw_it, bool do_updates)
#endif
// Print tutorial messages for features in LOS.
- if (Options.tutorial_left && in_bounds(gc)
- && crawl_view.in_grid_los(gc))
+ if (Options.tutorial_left
+ && in_bounds(gc)
+ && crawl_view.in_grid_los(gc)
+ && env.show(ep))
{
- const int object = env.show(ep);
- if (object && Options.tutorial_left)
- {
- if (grid_is_escape_hatch(grd(gc)))
- {
- learned_something_new(TUT_SEEN_ESCAPE_HATCH, gc);
- }
- else if (grid_is_branch_stairs(grd(gc)))
- learned_something_new(TUT_SEEN_BRANCH, gc);
- else if (is_feature('>', gc))
- {
- learned_something_new(TUT_SEEN_STAIRS, gc);
- }
- else if (is_feature('_', gc))
- learned_something_new(TUT_SEEN_ALTAR, gc);
- else if (grd(gc) == DNGN_CLOSED_DOOR)
- learned_something_new(TUT_SEEN_DOOR, gc);
- else if (grd(gc) == DNGN_ENTER_SHOP)
- learned_something_new(TUT_SEEN_SHOP, gc);
-
- if (igrd(gc) != NON_ITEM
- && Options.feature_item_brand != CHATTR_NORMAL
- && (is_feature('>', gc) || is_feature('<', gc)))
- {
- learned_something_new(TUT_STAIR_BRAND, gc);
- }
- }
+ tutorial_observe_cell(gc);
}
// Order is important here.
diff --git a/crawl-ref/source/view.h b/crawl-ref/source/view.h
index 6f710dbb24..c544f6024b 100644
--- a/crawl-ref/source/view.h
+++ b/crawl-ref/source/view.h
@@ -63,30 +63,14 @@ void init_char_table(char_set_type set);
void init_feature_table();
void init_monsters_seens();
-/* called from: beam - fight */
void beogh_follower_convert(monsters *monster, bool orc_hit = false);
-
-// last updated 29may2000 {dlb}
-/* ***********************************************************************
- * called from: bang - beam - direct - effects - fight - monstuff -
- * mstuff2 - spells1 - spells2
- * *********************************************************************** */
bool mons_near(const monsters *monster, unsigned short foe = MHITYOU);
bool mon_enemies_around(const monsters *monster);
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr - view
- * *********************************************************************** */
void item(void);
void find_features(const std::vector<coord_def>& features,
unsigned char feature, std::vector<coord_def> *found);
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: direct - monstufff - view
- * *********************************************************************** */
void losight(env_show_grid &sh, feature_grid &gr,
const coord_def& center, bool clear_walls_block = false,
bool ignore_clouds = false);
@@ -96,40 +80,17 @@ bool magic_mapping(int map_radius, int proportion, bool suppress_msg,
bool force = false);
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr - effects - it_use2 - it_use3 - item_use - spell -
- * spells - spells3 - spells4
- * *********************************************************************** */
bool noisy(int loudness, const coord_def& where, const char *msg = NULL,
bool mermaid = false);
void blood_smell( int strength, const coord_def& where);
void handle_monster_shouts(monsters* monster, bool force = false);
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr - spells3
- * *********************************************************************** */
void show_map( coord_def &spec_place, bool travel_mode );
-
-// last updated 19jun2000 (gdl)
-/* ***********************************************************************
- * called from: acr view
- * *********************************************************************** */
void setLOSRadius(int newLR);
-
-// last updated 02apr2001 (gdl)
-/* ***********************************************************************
- * called from: view monstuff
- * *********************************************************************** */
bool check_awaken(monsters* monster);
-
int count_detected_mons(void);
-
void clear_map(bool clear_items = true, bool clear_mons = true);
-
bool is_feature(int feature, const coord_def& where);
-
void get_item_glyph(const item_def *item, unsigned *glych,
unsigned short *glycol);
void get_mons_glyph(const monsters *mons, unsigned *glych,