Break travel opcodes into a two-element structure.
This commit is contained in:
parent
d53f125555
commit
8560122f01
3 changed files with 35 additions and 14 deletions
2
init.c
2
init.c
|
@ -25,7 +25,7 @@ void initialise(void)
|
||||||
game.abbrev[i] = 0;
|
game.abbrev[i] = 0;
|
||||||
if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
|
if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
|
||||||
int k = tkey[i];
|
int k = tkey[i];
|
||||||
if (MOD(labs(travel[k]), 1000) == 1)
|
if (MOD(labs(travel[k].opcode), 1000) == 1)
|
||||||
conditions[i] |= (1 << COND_FORCED);
|
conditions[i] |= (1 << COND_FORCED);
|
||||||
}
|
}
|
||||||
game.atloc[i] = 0;
|
game.atloc[i] = 0;
|
||||||
|
|
12
main.c
12
main.c
|
@ -32,13 +32,13 @@
|
||||||
* inherited from FORTRAN, someday. To understand these, read the
|
* inherited from FORTRAN, someday. To understand these, read the
|
||||||
* encoding description for travel.
|
* encoding description for travel.
|
||||||
*/
|
*/
|
||||||
#define T_DESTINATION(entry) MOD(labs(entry) / 1000, 1000)
|
#define T_DESTINATION(entry) MOD(labs((entry).opcode) / 1000, 1000)
|
||||||
#define T_NODWARVES(entry) labs(entry) / 1000000 == 100
|
#define T_NODWARVES(entry) labs((entry).opcode) / 1000000 == 100
|
||||||
#define T_MOTION(entry) MOD(labs(entry), 1000)
|
#define T_MOTION(entry) MOD(labs((entry).opcode), 1000)
|
||||||
#define L_SPEAK(loc) ((loc) - 500)
|
|
||||||
#define T_TERMINATE(entry) (T_MOTION(entry) == 1)
|
#define T_TERMINATE(entry) (T_MOTION(entry) == 1)
|
||||||
#define T_STOP(entry) ((entry) < 0)
|
#define T_STOP(entry) ((entry).stop)
|
||||||
#define T_OPCODE(entry) (entry)
|
#define T_OPCODE(entry) ((entry).opcode)
|
||||||
|
#define L_SPEAK(loc) ((loc) - 500)
|
||||||
|
|
||||||
struct game_t game;
|
struct game_t game;
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,11 @@ typedef struct {{
|
||||||
const long message;
|
const long message;
|
||||||
}} action_t;
|
}} action_t;
|
||||||
|
|
||||||
|
typedef struct {{
|
||||||
|
const long opcode;
|
||||||
|
const bool stop;
|
||||||
|
}} travelop_t;
|
||||||
|
|
||||||
extern const location_t locations[];
|
extern const location_t locations[];
|
||||||
extern const object_t objects[];
|
extern const object_t objects[];
|
||||||
extern const char* arbitrary_messages[];
|
extern const char* arbitrary_messages[];
|
||||||
|
@ -147,7 +152,7 @@ extern const hint_t hints[];
|
||||||
extern long conditions[];
|
extern long conditions[];
|
||||||
extern const motion_t motions[];
|
extern const motion_t motions[];
|
||||||
extern const action_t actions[];
|
extern const action_t actions[];
|
||||||
extern const long travel[];
|
extern const travelop_t travel[];
|
||||||
extern const long tkey[];
|
extern const long tkey[];
|
||||||
|
|
||||||
#define NLOCATIONS {}
|
#define NLOCATIONS {}
|
||||||
|
@ -233,7 +238,9 @@ const action_t actions[] = {{
|
||||||
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
const travelop_t travel[] = {{
|
||||||
{}
|
{}
|
||||||
|
}};
|
||||||
|
|
||||||
/* end */
|
/* end */
|
||||||
"""
|
"""
|
||||||
|
@ -558,7 +565,7 @@ def buildtravel(locs, objs, voc):
|
||||||
state = i
|
state = i
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("dungeon: unmatched state symbol %s in not caluase of %s\n" % (cond[2], name))
|
sys.stderr.write("dungeon: unmatched state symbol %s in not clause of %s\n" % (cond[2], name))
|
||||||
sys.exit(0);
|
sys.exit(0);
|
||||||
return 300 + obj + 100 * state
|
return 300 + obj + 100 * state
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -600,7 +607,9 @@ def buildtravel(locs, objs, voc):
|
||||||
# }
|
# }
|
||||||
# TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
|
# TRAVEL[TRVS - 1] = -TRAVEL[TRVS - 1];
|
||||||
# }
|
# }
|
||||||
travel = [0]
|
#
|
||||||
|
# We're going to break the magic numbers up into a struct.
|
||||||
|
travel = [[0, False]]
|
||||||
tkey = [0]
|
tkey = [0]
|
||||||
oldloc = 0
|
oldloc = 0
|
||||||
while ltravel:
|
while ltravel:
|
||||||
|
@ -611,12 +620,24 @@ def buildtravel(locs, objs, voc):
|
||||||
tkey.append(len(travel))
|
tkey.append(len(travel))
|
||||||
oldloc = loc
|
oldloc = loc
|
||||||
elif travel:
|
elif travel:
|
||||||
travel[-1] *= -1
|
travel[-1][1] = not travel[-1][1]
|
||||||
while rule:
|
while rule:
|
||||||
travel.append(rule.pop(0) + newloc * 1000)
|
travel.append([rule.pop(0) + newloc * 1000, False])
|
||||||
travel[-1] *= -1
|
travel[-1][1] = True
|
||||||
return (travel, tkey)
|
return (travel, tkey)
|
||||||
|
|
||||||
|
def get_travel(travel):
|
||||||
|
template = """ {{
|
||||||
|
.opcode = {},
|
||||||
|
.stop = {},
|
||||||
|
}},
|
||||||
|
"""
|
||||||
|
out = ""
|
||||||
|
for entry in travel:
|
||||||
|
out += template.format(entry[0], entry[1]).lower()
|
||||||
|
out = out[:-1] # trim trailing newline
|
||||||
|
return out
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
with open(yaml_name, "r") as f:
|
with open(yaml_name, "r") as f:
|
||||||
db = yaml.load(f)
|
db = yaml.load(f)
|
||||||
|
@ -642,7 +663,7 @@ if __name__ == "__main__":
|
||||||
get_motions(db["motions"]),
|
get_motions(db["motions"]),
|
||||||
get_actions(db["actions"]),
|
get_actions(db["actions"]),
|
||||||
"const long tkey[] = {%s};" % bigdump(tkey),
|
"const long tkey[] = {%s};" % bigdump(tkey),
|
||||||
"const long travel[] = {%s};" % bigdump(travel),
|
get_travel(travel),
|
||||||
)
|
)
|
||||||
|
|
||||||
h = h_template.format(
|
h = h_template.format(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue