projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Section 10 (class thresholds) is now parsed entirely from YAML.
[open-adventure.git]
/
newdungeon.py
diff --git
a/newdungeon.py
b/newdungeon.py
index 923fb397373b769624cfab520e93dfcd501e2018..f8ef9571abd0bc897aa2145041c3d3f646e49f2c 100755
(executable)
--- a/
newdungeon.py
+++ b/
newdungeon.py
@@
-29,28
+29,32
@@
typedef struct {{
const char* yes_response;
}} obituary_t;
const char* yes_response;
}} obituary_t;
+typedef struct {{
+ const int threshold;
+ const int point_loss;
+ const char* message;
+}} turn_threshold_t;
+
+typedef struct {{
+ const int threshold;
+ const char* message;
+}} class_t;
+
extern location_t locations[];
extern object_description_t object_descriptions[];
extern const char* arbitrary_messages[];
extern location_t locations[];
extern object_description_t object_descriptions[];
extern const char* arbitrary_messages[];
-extern const c
har* class_messag
es[];
-extern
const char* turn_threshold_message
s[];
+extern const c
lass_t class
es[];
+extern
turn_threshold_t turn_threshold
s[];
extern obituary_t obituaries[];
extern size_t CLSSES;
extern int maximum_deaths;
extern obituary_t obituaries[];
extern size_t CLSSES;
extern int maximum_deaths;
+extern int turn_threshold_count;
enum arbitrary_messages_refs {{
{}
}};
enum arbitrary_messages_refs {{
{}
}};
-enum class_messages_refs {{
-{}
-}};
-
-enum turn_threshold_messages_refs {{
-{}
-}};
-
enum locations_refs {{
{}
}};
enum locations_refs {{
{}
}};
@@
-66,11
+70,11
@@
const char* arbitrary_messages[] = {{
{}
}};
{}
}};
-const c
har* class_messag
es[] = {{
+const c
lass_t class
es[] = {{
{}
}};
{}
}};
-
const char* turn_threshold_message
s[] = {{
+
turn_threshold_t turn_threshold
s[] = {{
{}
}};
{}
}};
@@
-88,6
+92,7
@@
obituary_t obituaries[] = {{
size_t CLSSES = {};
int maximum_deaths = {};
size_t CLSSES = {};
int maximum_deaths = {};
+int turn_threshold_count = {};
"""
def make_c_string(string):
"""
def make_c_string(string):
@@
-119,20
+124,32
@@
def get_arbitrary_messages(arb):
return arb_str
def get_class_messages(cls):
return arb_str
def get_class_messages(cls):
- template = """ {},
+ template = """ {{
+ .threshold = {},
+ .message = {},
+ }},
"""
cls_str = ""
for item in cls:
"""
cls_str = ""
for item in cls:
- cls_str += template.format(make_c_string(item[1]))
+ threshold = item["threshold"]
+ message = make_c_string(item["message"])
+ cls_str += template.format(threshold, message)
cls_str = cls_str[:-1] # trim trailing newline
cls_str = cls_str[:-1] # trim trailing newline
- return cls_str
+ return cls_str
-def get_turn_threshold_messages(trn):
- template = """ {},
+def get_turn_thresholds(trn):
+ template = """ {{
+ .threshold = {},
+ .point_loss = {},
+ .message = {},
+ }},
"""
trn_str = ""
for item in trn:
"""
trn_str = ""
for item in trn:
- trn_str += template.format(make_c_string(item[1]))
+ threshold = item["threshold"]
+ point_loss = item["point_loss"]
+ message = make_c_string(item["message"])
+ trn_str += template.format(threshold, point_loss, message)
trn_str = trn_str[:-1] # trim trailing newline
return trn_str
trn_str = trn_str[:-1] # trim trailing newline
return trn_str
@@
-193,8
+210,6
@@
with open(yaml_name, "r") as f:
h = h_template.format(
get_refs(db["arbitrary_messages"]),
h = h_template.format(
get_refs(db["arbitrary_messages"]),
- get_refs(db["class_messages"]),
- get_refs(db["turn_threshold_messages"]),
get_refs(db["locations"]),
get_refs(db["object_descriptions"]),
)
get_refs(db["locations"]),
get_refs(db["object_descriptions"]),
)
@@
-202,13
+217,14
@@
h = h_template.format(
c = c_template.format(
h_name,
get_arbitrary_messages(db["arbitrary_messages"]),
c = c_template.format(
h_name,
get_arbitrary_messages(db["arbitrary_messages"]),
- get_class_messages(db["class
_messag
es"]),
- get_turn_threshold
_messages(db["turn_threshold_message
s"]),
+ get_class_messages(db["classes"]),
+ get_turn_threshold
s(db["turn_threshold
s"]),
get_locations(db["locations"]),
get_object_descriptions(db["object_descriptions"]),
get_obituaries(db["obituaries"]),
get_locations(db["locations"]),
get_object_descriptions(db["object_descriptions"]),
get_obituaries(db["obituaries"]),
- len(db["class
_messag
es"]),
+ len(db["classes"]),
len(db["obituaries"]),
len(db["obituaries"]),
+ len(db["turn_thresholds"]),
)
with open(h_name, "w") as hf:
)
with open(h_name, "w") as hf: