Structurize the informaruin about dwarves.
This commit is contained in:
parent
195e6e149b
commit
ff9c73a37d
6 changed files with 44 additions and 42 deletions
10
actions.c
10
actions.c
|
@ -145,10 +145,10 @@ static phase_codes_t attack(command_t command)
|
||||||
DESTROY(OGRE);
|
DESTROY(OGRE);
|
||||||
int dwarves = 0;
|
int dwarves = 0;
|
||||||
for (int i = 1; i < PIRATE; i++) {
|
for (int i = 1; i < PIRATE; i++) {
|
||||||
if (game.dloc[i] == game.loc) {
|
if (game.dwarves[i].loc == game.loc) {
|
||||||
++dwarves;
|
++dwarves;
|
||||||
game.dloc[i] = LOC_LONGWEST;
|
game.dwarves[i].loc = LOC_LONGWEST;
|
||||||
game.dseen[i] = false;
|
game.dwarves[i].seen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rspeak((dwarves > 1) ?
|
rspeak((dwarves > 1) ?
|
||||||
|
@ -1245,8 +1245,8 @@ static phase_codes_t throwit(command_t command)
|
||||||
return throw_support(DWARF_DODGES);
|
return throw_support(DWARF_DODGES);
|
||||||
} else {
|
} else {
|
||||||
int i = atdwrf(game.loc);
|
int i = atdwrf(game.loc);
|
||||||
game.dseen[i] = false;
|
game.dwarves[i].seen = false;
|
||||||
game.dloc[i] = LOC_NOWHERE;
|
game.dwarves[i].loc = LOC_NOWHERE;
|
||||||
return throw_support((++game.dkill == 1) ?
|
return throw_support((++game.dkill == 1) ?
|
||||||
DWARF_SMOKE :
|
DWARF_SMOKE :
|
||||||
KILLED_DWARF);
|
KILLED_DWARF);
|
||||||
|
|
8
advent.h
8
advent.h
|
@ -184,9 +184,11 @@ struct game_t {
|
||||||
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
|
char zzword[TOKLEN + 1]; // randomly generated magic word from bird
|
||||||
int abbrev[NLOCATIONS + 1]; // has location been seen?
|
int abbrev[NLOCATIONS + 1]; // has location been seen?
|
||||||
int atloc[NLOCATIONS + 1]; // head of object linked list per location
|
int atloc[NLOCATIONS + 1]; // head of object linked list per location
|
||||||
int dseen[NDWARVES + 1]; // true if dwarf has seen him
|
struct {
|
||||||
loc_t dloc[NDWARVES + 1]; // location of dwarves, initially hard-wired in
|
int seen; // true if dwarf has seen him
|
||||||
loc_t odloc[NDWARVES + 1]; // prior loc of each dwarf, initially garbage
|
loc_t loc; // location of dwarves, initially hard-wired in
|
||||||
|
loc_t oldloc; // prior loc of each dwarf, initially garbage
|
||||||
|
} dwarves[NDWARVES + 1];
|
||||||
loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE)
|
loc_t fixed[NOBJECTS + 1]; // fixed location of object (if not IS_FREE)
|
||||||
obj_t link[NOBJECTS * 2 + 1];// object-list links
|
obj_t link[NOBJECTS * 2 + 1];// object-list links
|
||||||
loc_t place[NOBJECTS + 1]; // location of object
|
loc_t place[NOBJECTS + 1]; // location of object
|
||||||
|
|
12
init.c
12
init.c
|
@ -21,17 +21,17 @@ struct settings_t settings = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct game_t game = {
|
struct game_t game = {
|
||||||
.dloc[1] = LOC_KINGHALL,
|
.dwarves[1].loc = LOC_KINGHALL,
|
||||||
.dloc[2] = LOC_WESTBANK,
|
.dwarves[2].loc = LOC_WESTBANK,
|
||||||
.dloc[3] = LOC_Y2,
|
.dwarves[3].loc = LOC_Y2,
|
||||||
.dloc[4] = LOC_ALIKE3,
|
.dwarves[4].loc = LOC_ALIKE3,
|
||||||
.dloc[5] = LOC_COMPLEX,
|
.dwarves[5].loc = LOC_COMPLEX,
|
||||||
|
|
||||||
/* Sixth dwarf is special (the pirate). He always starts at his
|
/* Sixth dwarf is special (the pirate). He always starts at his
|
||||||
* chest's eventual location inside the maze. This loc is saved
|
* chest's eventual location inside the maze. This loc is saved
|
||||||
* in chloc for ref. The dead end in the other maze has its
|
* in chloc for ref. The dead end in the other maze has its
|
||||||
* loc stored in chloc2. */
|
* loc stored in chloc2. */
|
||||||
.dloc[6] = LOC_MAZEEND12,
|
.dwarves[6].loc = LOC_MAZEEND12,
|
||||||
.chloc = LOC_MAZEEND12,
|
.chloc = LOC_MAZEEND12,
|
||||||
.chloc2 = LOC_DEADEND13,
|
.chloc2 = LOC_DEADEND13,
|
||||||
.abbnum = 5,
|
.abbnum = 5,
|
||||||
|
|
48
main.c
48
main.c
|
@ -229,13 +229,13 @@ static bool spotted_by_pirate(int i)
|
||||||
if (movechest) {
|
if (movechest) {
|
||||||
move(CHEST, game.chloc);
|
move(CHEST, game.chloc);
|
||||||
move(MESSAG, game.chloc2);
|
move(MESSAG, game.chloc2);
|
||||||
game.dloc[PIRATE] = game.chloc;
|
game.dwarves[PIRATE].loc = game.chloc;
|
||||||
game.odloc[PIRATE] = game.chloc;
|
game.dwarves[PIRATE].oldloc = game.chloc;
|
||||||
game.dseen[PIRATE] = false;
|
game.dwarves[PIRATE].seen = false;
|
||||||
} else {
|
} else {
|
||||||
/* You might get a hint of the pirate's presence even if the
|
/* You might get a hint of the pirate's presence even if the
|
||||||
* chest doesn't move... */
|
* chest doesn't move... */
|
||||||
if (game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20))
|
if (game.dwarves[PIRATE].oldloc != game.dwarves[PIRATE].loc && PCT(20))
|
||||||
rspeak(PIRATE_RUSTLES);
|
rspeak(PIRATE_RUSTLES);
|
||||||
}
|
}
|
||||||
if (robplayer) {
|
if (robplayer) {
|
||||||
|
@ -295,15 +295,15 @@ static bool dwarfmove(void)
|
||||||
for (int i = 1; i <= 2; i++) {
|
for (int i = 1; i <= 2; i++) {
|
||||||
int j = 1 + randrange(NDWARVES - 1);
|
int j = 1 + randrange(NDWARVES - 1);
|
||||||
if (PCT(50))
|
if (PCT(50))
|
||||||
game.dloc[j] = 0;
|
game.dwarves[j].loc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Alternate initial loc for dwarf, in case one of them
|
/* Alternate initial loc for dwarf, in case one of them
|
||||||
* starts out on top of the adventurer. */
|
* starts out on top of the adventurer. */
|
||||||
for (int i = 1; i <= NDWARVES - 1; i++) {
|
for (int i = 1; i <= NDWARVES - 1; i++) {
|
||||||
if (game.dloc[i] == game.loc)
|
if (game.dwarves[i].loc == game.loc)
|
||||||
game.dloc[i] = DALTLC; //
|
game.dwarves[i].loc = DALTLC; //
|
||||||
game.odloc[i] = game.dloc[i];
|
game.dwarves[i].oldloc = game.dwarves[i].loc;
|
||||||
}
|
}
|
||||||
rspeak(DWARF_RAN);
|
rspeak(DWARF_RAN);
|
||||||
drop(AXE, game.loc);
|
drop(AXE, game.loc);
|
||||||
|
@ -320,11 +320,11 @@ static bool dwarfmove(void)
|
||||||
attack = 0;
|
attack = 0;
|
||||||
stick = 0;
|
stick = 0;
|
||||||
for (int i = 1; i <= NDWARVES; i++) {
|
for (int i = 1; i <= NDWARVES; i++) {
|
||||||
if (game.dloc[i] == 0)
|
if (game.dwarves[i].loc == 0)
|
||||||
continue;
|
continue;
|
||||||
/* Fill tk array with all the places this dwarf might go. */
|
/* Fill tk array with all the places this dwarf might go. */
|
||||||
unsigned int j = 1;
|
unsigned int j = 1;
|
||||||
kk = tkey[game.dloc[i]];
|
kk = tkey[game.dwarves[i].loc];
|
||||||
if (kk != 0)
|
if (kk != 0)
|
||||||
do {
|
do {
|
||||||
enum desttype_t desttype = travel[kk].desttype;
|
enum desttype_t desttype = travel[kk].desttype;
|
||||||
|
@ -334,14 +334,14 @@ static bool dwarfmove(void)
|
||||||
continue;
|
continue;
|
||||||
else if (!INDEEP(game.newloc))
|
else if (!INDEEP(game.newloc))
|
||||||
continue;
|
continue;
|
||||||
else if (game.newloc == game.odloc[i])
|
else if (game.newloc == game.dwarves[i].oldloc)
|
||||||
continue;
|
continue;
|
||||||
else if (j > 1 && game.newloc == tk[j - 1])
|
else if (j > 1 && game.newloc == tk[j - 1])
|
||||||
continue;
|
continue;
|
||||||
else if (j >= DIM(tk) - 1)
|
else if (j >= DIM(tk) - 1)
|
||||||
/* This can't actually happen. */
|
/* This can't actually happen. */
|
||||||
continue; // LCOV_EXCL_LINE
|
continue; // LCOV_EXCL_LINE
|
||||||
else if (game.newloc == game.dloc[i])
|
else if (game.newloc == game.dwarves[i].loc)
|
||||||
continue;
|
continue;
|
||||||
else if (FORCED(game.newloc))
|
else if (FORCED(game.newloc))
|
||||||
continue;
|
continue;
|
||||||
|
@ -352,23 +352,23 @@ static bool dwarfmove(void)
|
||||||
tk[j++] = game.newloc;
|
tk[j++] = game.newloc;
|
||||||
} while
|
} while
|
||||||
(!travel[kk++].stop);
|
(!travel[kk++].stop);
|
||||||
tk[j] = game.odloc[i];
|
tk[j] = game.dwarves[i].oldloc;
|
||||||
if (j >= 2)
|
if (j >= 2)
|
||||||
--j;
|
--j;
|
||||||
j = 1 + randrange(j);
|
j = 1 + randrange(j);
|
||||||
game.odloc[i] = game.dloc[i];
|
game.dwarves[i].oldloc = game.dwarves[i].loc;
|
||||||
game.dloc[i] = tk[j];
|
game.dwarves[i].loc = tk[j];
|
||||||
game.dseen[i] = (game.dseen[i] && INDEEP(game.loc)) ||
|
game.dwarves[i].seen = (game.dwarves[i].seen && INDEEP(game.loc)) ||
|
||||||
(game.dloc[i] == game.loc ||
|
(game.dwarves[i].loc == game.loc ||
|
||||||
game.odloc[i] == game.loc);
|
game.dwarves[i].oldloc == game.loc);
|
||||||
if (!game.dseen[i])
|
if (!game.dwarves[i].seen)
|
||||||
continue;
|
continue;
|
||||||
game.dloc[i] = game.loc;
|
game.dwarves[i].loc = game.loc;
|
||||||
if (spotted_by_pirate(i))
|
if (spotted_by_pirate(i))
|
||||||
continue;
|
continue;
|
||||||
/* This threatening little dwarf is in the room with him! */
|
/* This threatening little dwarf is in the room with him! */
|
||||||
++game.dtotal;
|
++game.dtotal;
|
||||||
if (game.odloc[i] == game.dloc[i]) {
|
if (game.dwarves[i].oldloc == game.dwarves[i].loc) {
|
||||||
++attack;
|
++attack;
|
||||||
if (game.knfloc >= LOC_NOWHERE)
|
if (game.knfloc >= LOC_NOWHERE)
|
||||||
game.knfloc = game.loc;
|
game.knfloc = game.loc;
|
||||||
|
@ -827,8 +827,8 @@ static bool closecheck(void)
|
||||||
game.prop[GRATE] = GRATE_CLOSED;
|
game.prop[GRATE] = GRATE_CLOSED;
|
||||||
game.prop[FISSURE] = UNBRIDGED;
|
game.prop[FISSURE] = UNBRIDGED;
|
||||||
for (int i = 1; i <= NDWARVES; i++) {
|
for (int i = 1; i <= NDWARVES; i++) {
|
||||||
game.dseen[i] = false;
|
game.dwarves[i].seen = false;
|
||||||
game.dloc[i] = LOC_NOWHERE;
|
game.dwarves[i].loc = LOC_NOWHERE;
|
||||||
}
|
}
|
||||||
DESTROY(TROLL);
|
DESTROY(TROLL);
|
||||||
move(TROLL + NOBJECTS, IS_FREE);
|
move(TROLL + NOBJECTS, IS_FREE);
|
||||||
|
@ -1044,7 +1044,7 @@ static bool do_move(void)
|
||||||
* place) let him get out (and attacked). */
|
* place) let him get out (and attacked). */
|
||||||
if (game.newloc != game.loc && !FORCED(game.loc) && !CNDBIT(game.loc, COND_NOARRR)) {
|
if (game.newloc != game.loc && !FORCED(game.loc) && !CNDBIT(game.loc, COND_NOARRR)) {
|
||||||
for (size_t i = 1; i <= NDWARVES - 1; i++) {
|
for (size_t i = 1; i <= NDWARVES - 1; i++) {
|
||||||
if (game.odloc[i] == game.newloc && game.dseen[i]) {
|
if (game.dwarves[i].oldloc == game.newloc && game.dwarves[i].seen) {
|
||||||
game.newloc = game.loc;
|
game.newloc = game.loc;
|
||||||
rspeak(DWARF_BLOCK);
|
rspeak(DWARF_BLOCK);
|
||||||
break;
|
break;
|
||||||
|
|
4
misc.c
4
misc.c
|
@ -672,9 +672,9 @@ int atdwrf(loc_t where)
|
||||||
return at;
|
return at;
|
||||||
at = -1;
|
at = -1;
|
||||||
for (int i = 1; i <= NDWARVES - 1; i++) {
|
for (int i = 1; i <= NDWARVES - 1; i++) {
|
||||||
if (game.dloc[i] == where)
|
if (game.dwarves[i].loc == where)
|
||||||
return i;
|
return i;
|
||||||
if (game.dloc[i] != 0)
|
if (game.dwarves[i].loc != 0)
|
||||||
at = 0;
|
at = 0;
|
||||||
}
|
}
|
||||||
return at;
|
return at;
|
||||||
|
|
|
@ -190,8 +190,8 @@ bool is_valid(struct game_t valgame)
|
||||||
}
|
}
|
||||||
/* Bounds check for location arrays */
|
/* Bounds check for location arrays */
|
||||||
for (int i = 0; i <= NDWARVES; i++) {
|
for (int i = 0; i <= NDWARVES; i++) {
|
||||||
if (valgame.dloc[i] < -1 || valgame.dloc[i] > NLOCATIONS ||
|
if (valgame.dwarves[i].loc < -1 || valgame.dwarves[i].loc > NLOCATIONS ||
|
||||||
valgame.odloc[i] < -1 || valgame.odloc[i] > NLOCATIONS) {
|
valgame.dwarves[i].oldloc < -1 || valgame.dwarves[i].oldloc > NLOCATIONS) {
|
||||||
return false; // LCOV_EXCL_LINE
|
return false; // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue