summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorRobert Vollmert <rvollmert@gmx.net>2009-10-28 17:09:28 +0100
committerRobert Vollmert <rvollmert@gmx.net>2009-10-28 17:09:47 +0100
commitefa51af108c6b3d0c395f5c9215343e278e70865 (patch)
tree441ac1d6bcc2fa89d371bf6678e09e5d88baab1d /crawl-ref/source
parent890ed0d6d406eec6e2b33c3bc41c208f6f9bca5d (diff)
downloadcrawl-ref-efa51af108c6b3d0c395f5c9215343e278e70865.tar.gz
crawl-ref-efa51af108c6b3d0c395f5c9215343e278e70865.zip
Move a little more code out of newgame.cc.
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/acr.cc1
-rw-r--r--crawl-ref/source/makefile.obj1
-rw-r--r--crawl-ref/source/newgame.cc193
-rw-r--r--crawl-ref/source/newgame.h1
-rw-r--r--crawl-ref/source/ng-init.cc202
-rw-r--r--crawl-ref/source/ng-init.h9
6 files changed, 216 insertions, 191 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 9171b9bbcb..11351fc7ab 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -87,6 +87,7 @@
#include "mon-util.h"
#include "mutation.h"
#include "newgame.h"
+#include "ng-init.h"
#include "notes.h"
#include "ouch.h"
#include "output.h"
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index c65724ce77..5b7d04cc1c 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -92,6 +92,7 @@ mt19937ar.o \
mtransit.o \
mutation.o \
newgame.o \
+ng-init.o \
ng-input.o \
ng-restr.o \
notes.o \
diff --git a/crawl-ref/source/newgame.cc b/crawl-ref/source/newgame.cc
index 2c8357438a..ffb56cf046 100644
--- a/crawl-ref/source/newgame.cc
+++ b/crawl-ref/source/newgame.cc
@@ -7,6 +7,7 @@
#include "AppHdr.h"
#include "newgame.h"
+#include "ng-init.h"
#include "ng-input.h"
#include "ng-restr.h"
#include "jobs.h"
@@ -71,7 +72,6 @@ static void _species_stat_init(species_type which_species);
static void _create_wanderer(void);
static bool _give_items_skills(void);
-static void _fix_up_god_name(void);
////////////////////////////////////////////////////////////////////////
// Remember player's startup options
@@ -334,184 +334,6 @@ static bool _check_saved_game(void)
return (false);
}
-static unsigned char _random_potion_description()
-{
- int desc, nature, colour;
-
- do
- {
- desc = random2( PDQ_NQUALS * PDC_NCOLOURS );
-
- if (coinflip())
- desc %= PDC_NCOLOURS;
-
- nature = PQUAL(desc);
- colour = PCOLOUR(desc);
-
- // nature and colour correspond to primary and secondary in
- // itemname.cc. This check ensures clear potions don't get odd
- // qualifiers.
- }
- while (colour == PDC_CLEAR && nature > PDQ_VISCOUS
- || desc == PDESCS(PDC_CLEAR));
-
- return static_cast<unsigned char>(desc);
-}
-
-// Determine starting depths of branches.
-static void _initialise_branch_depths()
-{
- branches[BRANCH_ECUMENICAL_TEMPLE].startdepth = random_range(4, 7);
- branches[BRANCH_ORCISH_MINES].startdepth = random_range(6, 11);
- branches[BRANCH_ELVEN_HALLS].startdepth = random_range(3, 4);
- branches[BRANCH_LAIR].startdepth = random_range(8, 13);
- branches[BRANCH_HIVE].startdepth = random_range(11, 16);
- branches[BRANCH_SLIME_PITS].startdepth = random_range(5, 8);
- if ( coinflip() )
- {
- branches[BRANCH_SWAMP].startdepth = random_range(2, 5);
- branches[BRANCH_SHOALS].startdepth = -1;
- }
- else
- {
- branches[BRANCH_SWAMP].startdepth = -1;
- branches[BRANCH_SHOALS].startdepth = random_range(2, 5);
- }
- branches[BRANCH_SNAKE_PIT].startdepth = random_range(3, 6);
- branches[BRANCH_VAULTS].startdepth = random_range(14, 19);
- branches[BRANCH_CRYPT].startdepth = random_range(2, 4);
- branches[BRANCH_HALL_OF_BLADES].startdepth = random_range(4, 6);
- branches[BRANCH_TOMB].startdepth = random_range(2, 3);
-}
-
-static int _get_random_porridge_desc()
-{
- return PDESCQ(PDQ_GLUGGY, one_chance_in(3) ? PDC_BROWN
- : PDC_WHITE);
-}
-
-static int _get_random_coagulated_blood_desc()
-{
- potion_description_qualifier_type qualifier = PDQ_NONE;
- while (true)
- {
- switch (random2(4))
- {
- case 0:
- qualifier = PDQ_GLUGGY;
- break;
- case 1:
- qualifier = PDQ_LUMPY;
- break;
- case 2:
- qualifier = PDQ_SEDIMENTED;
- break;
- case 3:
- qualifier = PDQ_VISCOUS;
- break;
- }
- potion_description_colour_type colour = (coinflip() ? PDC_RED
- : PDC_BROWN);
-
- int desc = PDESCQ(qualifier, colour);
-
- if (you.item_description[IDESC_POTIONS][POT_BLOOD] != desc)
- return desc;
- }
-}
-
-static int _get_random_blood_desc()
-{
- return PDESCQ(coinflip() ? PDQ_NONE :
- coinflip() ? PDQ_VISCOUS
- : PDQ_SEDIMENTED, PDC_RED);
-}
-
-void initialise_item_descriptions()
-{
- // Must remember to check for already existing colours/combinations.
- you.item_description.init(255);
-
- you.item_description[IDESC_POTIONS][POT_WATER] = PDESCS(PDC_CLEAR);
- you.item_description[IDESC_POTIONS][POT_PORRIDGE]
- = _get_random_porridge_desc();
- you.item_description[IDESC_POTIONS][POT_BLOOD]
- = _get_random_blood_desc();
- you.item_description[IDESC_POTIONS][POT_BLOOD_COAGULATED]
- = _get_random_coagulated_blood_desc();
-
- // The order here must match that of IDESC in describe.h
- const int max_item_number[6] = { NUM_WANDS,
- NUM_POTIONS,
- NUM_SCROLLS,
- NUM_JEWELLERY,
- NUM_SCROLLS,
- NUM_STAVES };
-
- for (int i = 0; i < NUM_IDESC; i++)
- {
- // Only loop until NUM_WANDS etc.
- for (int j = 0; j < max_item_number[i]; j++)
- {
- // Don't override predefines
- if (you.item_description[i][j] != 255)
- continue;
-
- // Pick a new description until it's good.
- while (true)
- {
- // The numbers below are always secondary * primary,
- // except for scrolls. (See itemname.cc.)
- switch (i)
- {
- case IDESC_WANDS: // wands
- you.item_description[i][j] = random2( 16 * 12 );
- if (coinflip())
- you.item_description[i][j] %= 12;
- break;
-
- case IDESC_POTIONS: // potions
- you.item_description[i][j] = _random_potion_description();
- break;
-
- case IDESC_SCROLLS: // scrolls: random seed for the name
- case IDESC_SCROLLS_II:
- you.item_description[i][j] = random2(151);
- break;
-
- case IDESC_RINGS: // rings
- you.item_description[i][j] = random2( 13 * 13 );
- if (coinflip())
- you.item_description[i][j] %= 13;
- break;
-
- case IDESC_STAVES: // staves and rods
- you.item_description[i][j] = random2( 10 * 4 );
- break;
- }
-
- bool is_ok = true;
-
- // Test whether we've used this description before.
- // Don't have p < j because some are preassigned.
- for (int p = 0; p < max_item_number[i]; p++)
- {
- if (p == j)
- continue;
-
- if (you.item_description[i][p] == you.item_description[i][j])
- {
- is_ok = false;
- break;
- }
- }
- if (is_ok)
- break;
- }
- }
- }
-}
-
static void _give_starting_food()
{
// These undead start with no food.
@@ -1069,11 +891,11 @@ game_start:
// tmpfile purging removed in favour of marking
Generated_Levels.clear();
- _initialise_branch_depths();
+ initialise_branch_depths();
init_level_connectivity();
// Generate the second name of Jiyva
- _fix_up_god_name();
+ fix_up_jiyva_name();
_save_newgame_options();
return (true);
@@ -3469,15 +3291,6 @@ bool _needs_butchering_tool()
return (true);
}
-static void _fix_up_god_name()
-{
- do
- you.second_god_name = make_name(random_int(), false, 8, 'J');
- while (strncmp(you.second_god_name.c_str(), "J", 1) != 0);
-
- you.second_god_name = replace_all(you.second_god_name, " ", "");
-}
-
static startup_wand_type _wand_to_start(int wand, bool is_rod)
{
if (!is_rod)
diff --git a/crawl-ref/source/newgame.h b/crawl-ref/source/newgame.h
index ea3279e999..5c58bb9813 100644
--- a/crawl-ref/source/newgame.h
+++ b/crawl-ref/source/newgame.h
@@ -61,7 +61,6 @@ undead_state_type get_undead_state(const species_type sp);
* called from: acr
* *********************************************************************** */
bool new_game();
-void initialise_item_descriptions();
int give_first_conjuration_book();
bool choose_race(void);
diff --git a/crawl-ref/source/ng-init.cc b/crawl-ref/source/ng-init.cc
new file mode 100644
index 0000000000..f8b7b9c9ef
--- /dev/null
+++ b/crawl-ref/source/ng-init.cc
@@ -0,0 +1,202 @@
+/*
+ * File: ng-init.cc
+ * Summary: Initializing non-player-related parts of a new game.
+ *
+ * TODO: 'you' shouldn't occur here.
+ * Some of these might fit better elsewhere.
+ */
+
+#include "AppHdr.h"
+
+#include "branch.h"
+#include "describe.h"
+#include "itemname.h"
+#include "player.h"
+#include "stuff.h"
+
+static unsigned char _random_potion_description()
+{
+ int desc, nature, colour;
+
+ do
+ {
+ desc = random2( PDQ_NQUALS * PDC_NCOLOURS );
+
+ if (coinflip())
+ desc %= PDC_NCOLOURS;
+
+ nature = PQUAL(desc);
+ colour = PCOLOUR(desc);
+
+ // nature and colour correspond to primary and secondary in
+ // itemname.cc. This check ensures clear potions don't get odd
+ // qualifiers.
+ }
+ while (colour == PDC_CLEAR && nature > PDQ_VISCOUS
+ || desc == PDESCS(PDC_CLEAR));
+
+ return static_cast<unsigned char>(desc);
+}
+
+// Determine starting depths of branches.
+void initialise_branch_depths()
+{
+ branches[BRANCH_ECUMENICAL_TEMPLE].startdepth = random_range(4, 7);
+ branches[BRANCH_ORCISH_MINES].startdepth = random_range(6, 11);
+ branches[BRANCH_ELVEN_HALLS].startdepth = random_range(3, 4);
+ branches[BRANCH_LAIR].startdepth = random_range(8, 13);
+ branches[BRANCH_HIVE].startdepth = random_range(11, 16);
+ branches[BRANCH_SLIME_PITS].startdepth = random_range(5, 8);
+ if ( coinflip() )
+ {
+ branches[BRANCH_SWAMP].startdepth = random_range(2, 5);
+ branches[BRANCH_SHOALS].startdepth = -1;
+ }
+ else
+ {
+ branches[BRANCH_SWAMP].startdepth = -1;
+ branches[BRANCH_SHOALS].startdepth = random_range(2, 5);
+ }
+ branches[BRANCH_SNAKE_PIT].startdepth = random_range(3, 6);
+ branches[BRANCH_VAULTS].startdepth = random_range(14, 19);
+ branches[BRANCH_CRYPT].startdepth = random_range(2, 4);
+ branches[BRANCH_HALL_OF_BLADES].startdepth = random_range(4, 6);
+ branches[BRANCH_TOMB].startdepth = random_range(2, 3);
+}
+
+static int _get_random_porridge_desc()
+{
+ return PDESCQ(PDQ_GLUGGY, one_chance_in(3) ? PDC_BROWN
+ : PDC_WHITE);
+}
+
+static int _get_random_coagulated_blood_desc()
+{
+ potion_description_qualifier_type qualifier = PDQ_NONE;
+ while (true)
+ {
+ switch (random2(4))
+ {
+ case 0:
+ qualifier = PDQ_GLUGGY;
+ break;
+ case 1:
+ qualifier = PDQ_LUMPY;
+ break;
+ case 2:
+ qualifier = PDQ_SEDIMENTED;
+ break;
+ case 3:
+ qualifier = PDQ_VISCOUS;
+ break;
+ }
+ potion_description_colour_type colour = (coinflip() ? PDC_RED
+ : PDC_BROWN);
+
+ int desc = PDESCQ(qualifier, colour);
+
+ if (you.item_description[IDESC_POTIONS][POT_BLOOD] != desc)
+ return desc;
+ }
+}
+
+static int _get_random_blood_desc()
+{
+ return PDESCQ(coinflip() ? PDQ_NONE :
+ coinflip() ? PDQ_VISCOUS
+ : PDQ_SEDIMENTED, PDC_RED);
+}
+
+void initialise_item_descriptions()
+{
+ // Must remember to check for already existing colours/combinations.
+ you.item_description.init(255);
+
+ you.item_description[IDESC_POTIONS][POT_WATER] = PDESCS(PDC_CLEAR);
+ you.item_description[IDESC_POTIONS][POT_PORRIDGE]
+ = _get_random_porridge_desc();
+ you.item_description[IDESC_POTIONS][POT_BLOOD]
+ = _get_random_blood_desc();
+ you.item_description[IDESC_POTIONS][POT_BLOOD_COAGULATED]
+ = _get_random_coagulated_blood_desc();
+
+ // The order here must match that of IDESC in describe.h
+ const int max_item_number[6] = { NUM_WANDS,
+ NUM_POTIONS,
+ NUM_SCROLLS,
+ NUM_JEWELLERY,
+ NUM_SCROLLS,
+ NUM_STAVES };
+
+ for (int i = 0; i < NUM_IDESC; i++)
+ {
+ // Only loop until NUM_WANDS etc.
+ for (int j = 0; j < max_item_number[i]; j++)
+ {
+ // Don't override predefines
+ if (you.item_description[i][j] != 255)
+ continue;
+
+ // Pick a new description until it's good.
+ while (true)
+ {
+ // The numbers below are always secondary * primary,
+ // except for scrolls. (See itemname.cc.)
+ switch (i)
+ {
+ case IDESC_WANDS: // wands
+ you.item_description[i][j] = random2( 16 * 12 );
+ if (coinflip())
+ you.item_description[i][j] %= 12;
+ break;
+
+ case IDESC_POTIONS: // potions
+ you.item_description[i][j] = _random_potion_description();
+ break;
+
+ case IDESC_SCROLLS: // scrolls: random seed for the name
+ case IDESC_SCROLLS_II:
+ you.item_description[i][j] = random2(151);
+ break;
+
+ case IDESC_RINGS: // rings
+ you.item_description[i][j] = random2( 13 * 13 );
+ if (coinflip())
+ you.item_description[i][j] %= 13;
+ break;
+
+ case IDESC_STAVES: // staves and rods
+ you.item_description[i][j] = random2( 10 * 4 );
+ break;
+ }
+
+ bool is_ok = true;
+
+ // Test whether we've used this description before.
+ // Don't have p < j because some are preassigned.
+ for (int p = 0; p < max_item_number[i]; p++)
+ {
+ if (p == j)
+ continue;
+
+ if (you.item_description[i][p] == you.item_description[i][j])
+ {
+ is_ok = false;
+ break;
+ }
+ }
+ if (is_ok)
+ break;
+ }
+ }
+ }
+}
+
+void fix_up_jiyva_name()
+{
+ do
+ you.second_god_name = make_name(random_int(), false, 8, 'J');
+ while (strncmp(you.second_god_name.c_str(), "J", 1) != 0);
+
+ you.second_god_name = replace_all(you.second_god_name, " ", "");
+}
diff --git a/crawl-ref/source/ng-init.h b/crawl-ref/source/ng-init.h
new file mode 100644
index 0000000000..58fdce4514
--- /dev/null
+++ b/crawl-ref/source/ng-init.h
@@ -0,0 +1,9 @@
+#ifndef NG_INIT_H
+#define NG_INIT_H
+
+void fix_up_jiyva_name();
+void initialise_branch_depths();
+void initialise_item_descriptions();
+
+#endif
+