projects
/
open-adventure.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1f9f39d
)
Initialize dwarf locations in YAML, not C.
author
Eric S. Raymond
<esr@thyrsus.com>
Tue, 2 Jan 2024 15:32:23 +0000
(10:32 -0500)
committer
Eric S. Raymond
<esr@thyrsus.com>
Tue, 2 Jan 2024 17:12:32 +0000
(12:12 -0500)
Minimizes magic numbers.
adventure.yaml
patch
|
blob
|
history
init.c
patch
|
blob
|
history
make_dungeon.py
patch
|
blob
|
history
templates/dungeon.c.tpl
patch
|
blob
|
history
templates/dungeon.h.tpl
patch
|
blob
|
history
diff --git
a/adventure.yaml
b/adventure.yaml
index 3c0e566cc6796dd8eea9a70cec321218a0cc1b7d..20697597850727bb35c5555da14f9426998dc75f 100644
(file)
--- a/
adventure.yaml
+++ b/
adventure.yaml
@@
-2835,6
+2835,18
@@
locations: !!omap
{verbs: [], action: [goto, LOC_Y2]},
]
{verbs: [], action: [goto, LOC_Y2]},
]
+# Starting locations of dwarves.
+# Sixth dwarf is special (the pirate). He always starts at his
+# chest's eventual location inside the maze.
+dwarflocs: [
+ LOC_KINGHALL,
+ LOC_WESTBANK,
+ LOC_Y2,
+ LOC_ALIKE3,
+ LOC_COMPLEX,
+ LOC_MAZEEND12,
+]
+
arbitrary_messages: !!omap
- NO_MESSAGE: !!null
- CAVE_NEARBY: |-
arbitrary_messages: !!omap
- NO_MESSAGE: !!null
- CAVE_NEARBY: |-
diff --git
a/init.c
b/init.c
index 9104a5915ef9c0c43faa5759caba7e80ddf5c939..aabd1cb3f5791910b6072100415503213f342c79 100644
(file)
--- a/
init.c
+++ b/
init.c
@@
-11,6
+11,7
@@
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
+#include <assert.h>
#include "advent.h"
#include "advent.h"
@@
-21,17
+22,10
@@
struct settings_t settings = {
};
struct game_t game = {
};
struct game_t game = {
- .dwarves[1].loc = LOC_KINGHALL,
- .dwarves[2].loc = LOC_WESTBANK,
- .dwarves[3].loc = LOC_Y2,
- .dwarves[4].loc = LOC_ALIKE3,
- .dwarves[5].loc = LOC_COMPLEX,
-
- /* Sixth dwarf is special (the pirate). He always starts at his
+ /* Last dwarf is special (the pirate). He always starts at his
* chest's eventual location inside the maze. This loc is saved
* in chloc for ref. The dead end in the other maze has its
* loc stored in chloc2. */
* chest's eventual location inside the maze. This loc is saved
* in chloc for ref. The dead end in the other maze has its
* loc stored in chloc2. */
- .dwarves[6].loc = LOC_MAZEEND12,
.chloc = LOC_MAZEEND12,
.chloc2 = LOC_DEADEND13,
.abbnum = 5,
.chloc = LOC_MAZEEND12,
.chloc2 = LOC_DEADEND13,
.abbnum = 5,
@@
-52,6
+46,11
@@
int initialise(void)
int seedval = (int)rand();
set_seed(seedval);
int seedval = (int)rand();
set_seed(seedval);
+ assert(NDWARVES == NDWARFLOCS);
+ for (int i = 1; i <= NDWARFLOCS; i++) {
+ game.dwarves[i].loc = dwarflocs[i-1];
+ }
+
for (int i = 1; i <= NOBJECTS; i++) {
game.objects[i].place = LOC_NOWHERE;
}
for (int i = 1; i <= NOBJECTS; i++) {
game.objects[i].place = LOC_NOWHERE;
}
diff --git
a/make_dungeon.py
b/make_dungeon.py
index 8ab149ec458e6575f849a7480b6f89f059279e9d..0b8bc5328c5d10a42e7c5a0ed10cb83e3a6d4c18 100755
(executable)
--- a/
make_dungeon.py
+++ b/
make_dungeon.py
@@
-626,6
+626,7
@@
if __name__ == "__main__":
tkeys=bigdump(tkey),
travel=get_travel(travel),
ignore=ignore,
tkeys=bigdump(tkey),
travel=get_travel(travel),
ignore=ignore,
+ dwarflocs=", ".join(db["dwarflocs"]) + ",",
)
# 0-origin index of birds's last song. Bird should
)
# 0-origin index of birds's last song. Bird should
@@
-650,6
+651,7
@@
if __name__ == "__main__":
motions=get_refs(db["motions"]),
actions=get_refs(db["actions"]),
state_definitions=statedefines,
motions=get_refs(db["motions"]),
actions=get_refs(db["actions"]),
state_definitions=statedefines,
+ ndwarflocs=str(len(db["dwarflocs"])),
)
with open(H_NAME, "w", encoding="ascii", errors="surrogateescape") as hf:
)
with open(H_NAME, "w", encoding="ascii", errors="surrogateescape") as hf:
diff --git
a/templates/dungeon.c.tpl
b/templates/dungeon.c.tpl
index 4a7011ab033e6f2988faf2db03f2f20833ca6d5b..a192adb19a65025d2d64c4671d244e11810efe58 100644
(file)
--- a/
templates/dungeon.c.tpl
+++ b/
templates/dungeon.c.tpl
@@
-53,4
+53,7
@@
const travelop_t travel[] = {{
const char *ignore = "{ignore}";
const char *ignore = "{ignore}";
+/* Dwarf starting locations */
+const int dwarflocs[NDWARFLOCS] = {{{dwarflocs}}};
+
/* end */
/* end */
diff --git
a/templates/dungeon.h.tpl
b/templates/dungeon.h.tpl
index 0a9c1c541bb3c2f8a091e7877ad276e415e7be95..2a26917296c3692a7bb2e3585e3d03578d268b6f 100644
(file)
--- a/
templates/dungeon.h.tpl
+++ b/
templates/dungeon.h.tpl
@@
-35,6
+35,10
@@
SPDX-License-Identifier: BSD-2-Clause
#define COND_HOGRE 20 /* Trying to deal with ogre */
#define COND_HJADE 21 /* Found all treasures except jade */
#define COND_HOGRE 20 /* Trying to deal with ogre */
#define COND_HJADE 21 /* Found all treasures except jade */
+/* Count of dwarf starting locations */
+#define NDWARFLOCS {ndwarflocs}
+extern const int dwarflocs[NDWARFLOCS];
+
typedef struct {{
const char** strs;
const int n;
typedef struct {{
const char** strs;
const int n;