summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/command.cc111
-rw-r--r--crawl-ref/source/debug.cc5
-rw-r--r--crawl-ref/source/direct.cc2
-rw-r--r--crawl-ref/source/dungeon.cc13
-rw-r--r--crawl-ref/source/dungeon.h2
-rw-r--r--crawl-ref/source/effects.cc4
-rw-r--r--crawl-ref/source/food.cc2
-rw-r--r--crawl-ref/source/makeitem.cc1
-rw-r--r--crawl-ref/source/misc.cc69
-rw-r--r--crawl-ref/source/newgame.cc6
-rw-r--r--crawl-ref/source/output.cc11
-rw-r--r--crawl-ref/source/spells2.cc6
-rw-r--r--crawl-ref/source/spells3.cc45
-rw-r--r--crawl-ref/source/spl-cast.cc2
-rw-r--r--crawl-ref/source/spl-cast.h2
15 files changed, 109 insertions, 172 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index cd6955ec0a..ea370ed5d3 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -167,124 +167,71 @@ static void adjust_item(void)
swap_inv_slots(from_slot, to_slot, true);
} // end adjust_item()
-static void adjust_spells_cleanup(bool needs_redraw)
-{
- if (needs_redraw)
- redraw_screen();
-}
-
static void adjust_spells(void)
{
- unsigned char index_1, index_2;
- unsigned char nthing = 0;
-
- bool needs_redraw = false;
-
if (!you.spell_no)
{
mpr("You don't know any spells.");
return;
}
- query:
+ // Select starting slot
mpr("Adjust which spell?", MSGCH_PROMPT);
- unsigned char keyin = get_ch();
-
- if (keyin == '?' || keyin == '*')
+ int keyin = 0;
+ if ( Options.auto_list )
+ keyin = list_spells();
+ else
{
- if (keyin == '*' || keyin == '?')
- {
- nthing = list_spells();
- needs_redraw = true;
- }
-
- if (isalpha( nthing ) || nthing == ESCAPE)
- keyin = nthing;
- else
- {
- mesclr( true );
- goto query;
- }
+ keyin = get_ch();
+ if (keyin == '?' || keyin == '*')
+ keyin = list_spells();
}
-
- if (keyin == ESCAPE)
+
+ if ( !isalpha(keyin) )
{
- adjust_spells_cleanup(needs_redraw);
canned_msg( MSG_OK );
return;
}
- int input_1 = keyin;
-
- if (!isalpha( input_1 ))
- {
- adjust_spells_cleanup(needs_redraw);
- mpr("You don't know that spell.");
- return;
- }
-
- index_1 = letter_to_index( input_1 );
- spell_type spell = get_spell_by_letter( input_1 );
+ const int input_1 = keyin;
+ const int index_1 = letter_to_index( input_1 );
+ spell_type spell = get_spell_by_letter( input_1 );
if (spell == SPELL_NO_SPELL)
{
- adjust_spells_cleanup(needs_redraw);
mpr("You don't know that spell.");
return;
}
// print out targeted spell:
- mprf( "%c - %s", input_1, spell_title( spell ) );
-
- mpr( "Adjust to which letter?", MSGCH_PROMPT );
-
- keyin = get_ch();
+ mprf( "%c - %s", keyin, spell_title( spell ) );
- if (keyin == '?' || keyin == '*')
+ // Select target slot
+ keyin = 0;
+ while ( !isalpha(keyin) )
{
- if (keyin == '*' || keyin == '?')
- {
- nthing = list_spells();
- needs_redraw = true;
- }
-
- if (isalpha( nthing ) || nthing == ESCAPE)
- keyin = nthing;
- else
+ mpr( "Adjust to which letter?", MSGCH_PROMPT );
+ keyin = get_ch();
+ if (keyin == ESCAPE)
{
- mesclr( true );
- goto query;
+ canned_msg( MSG_OK );
+ return;
}
+ if (keyin == '?' || keyin == '*')
+ keyin = list_spells();
}
- if (keyin == ESCAPE)
- {
- adjust_spells_cleanup(needs_redraw);
- canned_msg( MSG_OK );
- return;
- }
-
- int input_2 = keyin;
-
- if (!isalpha( input_2 ))
- {
- adjust_spells_cleanup(needs_redraw);
- mpr("What?");
- return;
- }
-
- adjust_spells_cleanup(needs_redraw);
-
- index_2 = letter_to_index( input_2 );
+ const int input_2 = keyin;
+ const int index_2 = letter_to_index( keyin );
// swap references in the letter table:
- int tmp = you.spell_letter_table[index_2];
+ const int tmp = you.spell_letter_table[index_2];
you.spell_letter_table[index_2] = you.spell_letter_table[index_1];
you.spell_letter_table[index_1] = tmp;
- // print out spell in new slot (now at input_2)
- mprf("%c - %s", input_2, spell_title( get_spell_by_letter(input_2) ) );
+ // print out spell in new slot
+ mprf("%c - %s", input_2, spell_title(get_spell_by_letter(input_2)));
// print out other spell if one was involved (now at input_1)
spell = get_spell_by_letter( input_1 );
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 54abcab342..22d3f372d1 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -1409,13 +1409,14 @@ void debug_get_religion(void)
for (int i = 1; i < NUM_GODS; i++)
{
+ const god_type gi = static_cast<god_type>(i);
char name[80];
- strncpy( name, god_name(static_cast<god_type>(i)), sizeof( name ) );
+ strncpy(name, god_name(gi), sizeof(name));
char *ptr = strstr( strlwr(name), strlwr(specs) );
if (ptr != NULL)
{
- god = static_cast<god_type>(i);
+ god = gi;
break;
}
}
diff --git a/crawl-ref/source/direct.cc b/crawl-ref/source/direct.cc
index b84ca81e1f..798a1f25bb 100644
--- a/crawl-ref/source/direct.cc
+++ b/crawl-ref/source/direct.cc
@@ -1627,7 +1627,7 @@ static void describe_cell(int mx, int my)
if (targ_item != NON_ITEM)
{
- // If a mimic is on this square, we pretend its the first item -- bwr
+ // If a mimic is on this square, we pretend it's the first item -- bwr
if (mimic_item)
mpr("There is something else lying underneath.",MSGCH_FLOOR_ITEMS);
else
diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc
index b27f935d11..62a156abca 100644
--- a/crawl-ref/source/dungeon.cc
+++ b/crawl-ref/source/dungeon.cc
@@ -990,7 +990,7 @@ static void prepare_shoals(int level_number)
replace_in_grid(margin, margin, GXM-margin, GYM-margin,
DNGN_SHALLOW_WATER, DNGN_WATER_STUCK);
- for ( int i = 0; i < 6; ++i )
+ for ( int iteration = 0; iteration < 6; ++iteration )
{
for ( int x = margin; x < GXM - margin; ++x )
{
@@ -2676,7 +2676,6 @@ static void special_room(int level_number, spec_room &sr)
// fills a special room with bees
static void beehive(spec_room &sr)
{
- int i;
int x,y;
for (x = sr.x1; x <= sr.x2; x++)
@@ -2686,9 +2685,9 @@ static void beehive(spec_room &sr)
if (coinflip())
continue;
- i = get_item_slot();
+ const int i = get_item_slot();
if (i == NON_ITEM)
- goto finished_food;
+ continue;
mitm[i].quantity = 1;
mitm[i].base_type = OBJ_FOOD;
@@ -2702,10 +2701,8 @@ static void beehive(spec_room &sr)
}
- finished_food:
-
- int queenx = sr.x1 + random2(sr.x2 - sr.x1);
- int queeny = sr.y1 + random2(sr.y2 - sr.y1);
+ const int queenx = sr.x1 + random2(sr.x2 - sr.x1);
+ const int queeny = sr.y1 + random2(sr.y2 - sr.y1);
for (x = sr.x1; x <= sr.x2; x++)
{
diff --git a/crawl-ref/source/dungeon.h b/crawl-ref/source/dungeon.h
index f20025371c..6ea27e147a 100644
--- a/crawl-ref/source/dungeon.h
+++ b/crawl-ref/source/dungeon.h
@@ -24,7 +24,7 @@
const int MAKE_GOOD_ITEM = 351;
// Should be the larger of GXM/GYM
-#define MAP_SIDE GXM
+#define MAP_SIDE ( (GXM) > (GYM) ? (GXM) : (GYM) )
// This may sometimes be used as map_type[x][y] (for minivaults) and as
// map_type[y][x] for large-scale vaults. Keep an eye out for the associated
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 4dfe3323ee..3cfafba58c 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -512,13 +512,13 @@ static int find_acquirement_subtype(object_class_type class_wanted,
{
// Meat is better than bread (except for herbivores), and
// by choosing it as the default we don't have to worry
- // about special cases for carnivorous races (ie kobold)
+ // about special cases for carnivorous races (e.g. kobolds)
type_wanted = FOOD_MEAT_RATION;
if (you.mutation[MUT_HERBIVOROUS])
type_wanted = FOOD_BREAD_RATION;
- // If we have some regular rations, then we're probably be more
+ // If we have some regular rations, then we're probably more
// interested in faster foods (especially royal jelly)...
// otherwise the regular rations should be a good enough offer.
if (already_has[FOOD_MEAT_RATION]
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 8e3d770342..c2010d7037 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -252,7 +252,7 @@ bool butchery(void)
// offer the possibility of butchering
snprintf(info, INFO_SIZE, "Butcher %s?",
mitm[objl].name(DESC_NOCAP_A).c_str());
- int answer = yesnoquit( info, true, 'n', false );
+ const int answer = yesnoquit( info, true, 'n', false );
if ( answer == -1 )
{
canceled_butcher = true;
diff --git a/crawl-ref/source/makeitem.cc b/crawl-ref/source/makeitem.cc
index 735d6b1c4a..c3269a0fbd 100644
--- a/crawl-ref/source/makeitem.cc
+++ b/crawl-ref/source/makeitem.cc
@@ -3016,7 +3016,6 @@ static item_make_species_type give_weapon(monsters *mon, int level,
item_def &item = mitm[bp];
item_make_species_type item_race = MAKE_ITEM_RANDOM_RACE;
- // this flags things to "goto give_armour" below ... {dlb}
item.base_type = OBJ_UNASSIGNED;
if (mon->type == MONS_DANCING_WEAPON
diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc
index 590a8fcda8..5040a38a88 100644
--- a/crawl-ref/source/misc.cc
+++ b/crawl-ref/source/misc.cc
@@ -73,7 +73,7 @@
bool scramble(void);
static bool trap_item(object_class_type base_type, char sub_type,
char beam_x, char beam_y);
-static void dart_trap(bool trap_known, int trapped, struct bolt &pbolt, bool poison);
+static void dart_trap(bool trap_known, int trapped, bolt &pbolt, bool poison);
// void place_chunks(int mcls, unsigned char rot_status, unsigned char chx,
// unsigned char chy, unsigned char ch_col)
@@ -1196,15 +1196,12 @@ void new_level(void)
#endif
}
-static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt,
- bool poison )
+static void dart_trap(bool trap_known, int trapped, bolt &pbolt, bool poison)
{
int damage_taken = 0;
int trap_hit, your_dodge;
- std::string msg;
-
- if (random2(10) < 2 || (trap_known && !one_chance_in(4)))
+ if (one_chance_in(5) || (trap_known && !one_chance_in(4)))
{
mprf( "You avoid triggering a%s trap.", pbolt.name.c_str() );
return;
@@ -1213,9 +1210,7 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt,
if (you.equip[EQ_SHIELD] != -1 && one_chance_in(3))
exercise( SK_SHIELDS, 1 );
- msg = "A";
- msg += pbolt.name;
- msg += " shoots out and ";
+ std::string msg = "A" + pbolt.name + " shoots out and ";
if (random2( 20 + 5 * you.shield_blocks * you.shield_blocks )
< player_shield_class())
@@ -1223,42 +1218,42 @@ static void dart_trap( bool trap_known, int trapped, struct bolt &pbolt,
you.shield_blocks++;
msg += "hits your shield.";
mpr(msg.c_str());
- goto out_of_trap;
}
-
- // note that this uses full ( not random2limit(foo,40) ) player_evasion.
- trap_hit = (20 + (you.your_level * 2)) * random2(200) / 100;
-
- your_dodge = player_evasion() + random2(you.dex) / 3
- - 2 + (you.duration[DUR_REPEL_MISSILES] * 10);
-
- if (trap_hit >= your_dodge && you.duration[DUR_DEFLECT_MISSILES] == 0)
+ else
{
- msg += "hits you!";
- mpr(msg.c_str());
+ // note that this uses full ( not random2limit(foo,40) )
+ // player_evasion.
+ trap_hit = (20 + (you.your_level * 2)) * random2(200) / 100;
- if (poison && random2(100) < 50 - (3 * player_AC()) / 2
+ your_dodge = player_evasion() + random2(you.dex) / 3
+ - 2 + (you.duration[DUR_REPEL_MISSILES] * 10);
+
+ if (trap_hit >= your_dodge && you.duration[DUR_DEFLECT_MISSILES] == 0)
+ {
+ msg += "hits you!";
+ mpr(msg.c_str());
+
+ if (poison && random2(100) < 50 - (3 * player_AC()) / 2
&& !player_res_poison())
+ {
+ poison_player( 1 + random2(3) );
+ }
+
+ damage_taken = roll_dice( pbolt.damage );
+ damage_taken -= random2( player_AC() + 1 );
+
+ if (damage_taken > 0)
+ ouch( damage_taken, 0, KILLED_BY_TRAP, pbolt.name.c_str() );
+ }
+ else
{
- poison_player( 1 + random2(3) );
+ msg += "misses you.";
+ mpr(msg.c_str());
}
- damage_taken = roll_dice( pbolt.damage );
- damage_taken -= random2( player_AC() + 1 );
-
- if (damage_taken > 0)
- ouch( damage_taken, 0, KILLED_BY_TRAP, pbolt.name.c_str() );
+ if (player_light_armour(true) && coinflip())
+ exercise( SK_DODGING, 1 );
}
- else
- {
- msg += "misses you.";
- mpr(msg.c_str());
- }
-
- if (player_light_armour(true) && coinflip())
- exercise( SK_DODGING, 1 );
-
- out_of_trap:
pbolt.target_x = you.x_pos;
pbolt.target_y = you.y_pos;
diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc
index 9eb3e65ead..d957b81237 100644
--- a/crawl-ref/source/newgame.cc
+++ b/crawl-ref/source/newgame.cc
@@ -782,8 +782,7 @@ game_start:
if (!give_items_skills())
{
// now choose again, name stays same
- char *name = new char();
- strcpy(name, you.your_name);
+ const std::string old_name = you.your_name;
Options.prev_randpick = false;
Options.prev_race = ng_race;
@@ -797,7 +796,8 @@ game_start:
Options.reset_startup_options();
- strncpy(you.your_name, name, kNameLen);
+ // Restore old name
+ strncpy(you.your_name, old_name.c_str(), kNameLen);
you.your_name[kNameLen - 1] = 0;
// choose new character
diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc
index b5cd2f3118..fe66dd794a 100644
--- a/crawl-ref/source/output.cc
+++ b/crawl-ref/source/output.cc
@@ -1013,12 +1013,11 @@ void print_overview_screen()
}
text = "<yellow>";
- snprintf(info, INFO_SIZE, "%s%s%s", you.your_name, title, race_class);
- text += info;
- int k = get_number_of_cols() - linelength -1;
- text += std::string(k, ' ');
- snprintf(info, INFO_SIZE, "%s", time_turns);
- text += info;
+ text += you.your_name;
+ text += title;
+ text += race_class;
+ text += std::string(get_number_of_cols() - linelength - 1, ' ');
+ text += time_turns;
text += "</yellow>\n";
cmd_help.add_text(text);
diff --git a/crawl-ref/source/spells2.cc b/crawl-ref/source/spells2.cc
index 9eeaa49fc4..13fe97e359 100644
--- a/crawl-ref/source/spells2.cc
+++ b/crawl-ref/source/spells2.cc
@@ -273,14 +273,12 @@ int corpse_rot(int power)
place_cloud(CLOUD_MIASMA, adx, ady,
4 + random2avg(16, 3), KC_YOU);
- goto out_of_raise;
+ // Don't look for more corpses here
+ break;
}
hrg = mitm[objl].link;
objl = hrg;
}
-
- out_of_raise:
- objl = 1;
}
}
}
diff --git a/crawl-ref/source/spells3.cc b/crawl-ref/source/spells3.cc
index 142f0e94d9..c77a4d7468 100644
--- a/crawl-ref/source/spells3.cc
+++ b/crawl-ref/source/spells3.cc
@@ -415,9 +415,9 @@ void dancing_weapon(int pow, bool force_hostile)
{
int numsc = std::min(2 + (random2(pow) / 5), 6);
- int i;
int summs = 0;
beh_type behavi = BEH_FRIENDLY;
+ bool failed = false;
const int wpn = you.equip[EQ_WEAPON];
@@ -427,27 +427,36 @@ void dancing_weapon(int pow, bool force_hostile)
|| is_range_weapon( you.inv[wpn] )
|| is_fixed_artefact( you.inv[wpn] ))
{
- goto failed_spell;
+ failed = true;
}
// See if we can get an mitm for the dancing weapon:
- i = get_item_slot();
+ int i = get_item_slot();
if (i == NON_ITEM)
- goto failed_spell;
+ failed = true;
- // cursed weapons become hostile
- if (item_cursed( you.inv[wpn] ) || force_hostile)
- behavi = BEH_HOSTILE;
+ if ( !failed )
+ {
- summs = create_monster( MONS_DANCING_WEAPON, numsc, behavi,
- you.x_pos, you.y_pos, you.pet_target, 1 );
+ // cursed weapons become hostile
+ if (item_cursed( you.inv[wpn] ) || force_hostile)
+ behavi = BEH_HOSTILE;
+
+ summs = create_monster( MONS_DANCING_WEAPON, numsc, behavi,
+ you.x_pos, you.y_pos, you.pet_target, 1 );
+ if ( summs == -1 )
+ failed = true;
+ }
- if (summs < 0)
+ if ( failed )
{
- // must delete the item before failing!
- mitm[i].base_type = OBJ_UNASSIGNED;
- mitm[i].quantity = 0;
- goto failed_spell;
+ destroy_item(i);
+ if ( wpn != -1 )
+ mpr("Your weapon vibrates crazily for a second.");
+ else
+ msg::stream << "Your " << your_hand(true) << " twitch."
+ << std::endl;
+ return;
}
// We are successful:
@@ -470,14 +479,6 @@ void dancing_weapon(int pow, bool force_hostile)
menv[summs].inv[MSLOT_WEAPON] = i;
menv[summs].colour = mitm[i].colour;
-
- return;
-
-failed_spell:
- if ( wpn != -1 )
- mpr("Your weapon vibrates crazily for a second.");
- else
- msg::stream <<"Your " << your_hand(true) << " twitch." << std::endl;
} // end dancing_weapon()
static bool monster_on_level(int monster)
diff --git a/crawl-ref/source/spl-cast.cc b/crawl-ref/source/spl-cast.cc
index 9f62c54a46..a54f09dbb6 100644
--- a/crawl-ref/source/spl-cast.cc
+++ b/crawl-ref/source/spl-cast.cc
@@ -186,7 +186,7 @@ static std::string spell_extra_description(spell_type spell)
return desc.str();
}
-char list_spells()
+int list_spells()
{
ToggleableMenu spell_menu(MF_SINGLESELECT | MF_ANYPRINTABLE |
MF_ALWAYS_SHOW_MORE | MF_ALLOW_FORMATTING);
diff --git a/crawl-ref/source/spl-cast.h b/crawl-ref/source/spl-cast.h
index 6021cd634b..eeaa6578bc 100644
--- a/crawl-ref/source/spl-cast.h
+++ b/crawl-ref/source/spl-cast.h
@@ -16,7 +16,7 @@
#include "enum.h"
-char list_spells( void );
+int list_spells();
int spell_fail( spell_type spell );
int calc_spell_power(spell_type spell, bool apply_intel,
bool fail_rate_chk = false );