From d029b08ad136ceab3a30236f22433022834f0d71 Mon Sep 17 00:00:00 2001 From: "Jason S. Ninneman" Date: Tue, 20 Jun 2017 15:35:30 -0700 Subject: [PATCH] Refactor how turn threshold penalties are accounted for. --- adventure.yaml | 19 +++++++++++++------ main.c | 27 +++++++++++++++++++-------- newdungeon.py | 33 ++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/adventure.yaml b/adventure.yaml index 4486b0e..9cd5811 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -1037,12 +1037,19 @@ class_messages: !!omap - CLS_9: 'All of Adventuredom gives tribute to you, Adventurer Grandmaster!' - CLS_10: 'Adventuredom stands in awe -- you have now joined the ranks of the\n W O R L D C H A M P I O N A D V E N T U R E R S !\nIt may interest you to know that the Dungeon-Master himself has, to\nmy knowledge, never achieved this threshhold in fewer than 330 turns.' -turn_threshold_messages: !!omap -- TURN_0: !!null -- TURN_1: 'Tsk! A wizard wouldn''t have to take 350 turns. This is going to cost\nyou a couple of points.' -- TURN_2: 500 turns? That's another few points you've lost. -- TURN_3: 'Are you still at it? Five points off for exceeding 1000 turns!' -- TURN_4: 'Good grief, don''t you *EVER* give up? Do you realize you''ve spent\nover 2500 turns at this? That''s another ten points off, a total of\ntwenty points lost for taking so long.' +turn_thresholds: +- threshold: 350 + point_loss: 2 + message: 'Tsk! A wizard wouldn''t have to take 350 turns. This is going to cost\nyou a couple of points.' +- threshold: 500 + point_loss: 3 + message: '500 turns? That''s another few points you''ve lost.' +- threshold: 1000 + point_loss: 5 + message: 'Are you still at it? Five points off for exceeding 1000 turns!' +- threshold: 2500 + point_loss: 10 + message: 'Good grief, don''t you *EVER* give up? Do you realize you''ve spent\nover 2500 turns at this? That''s another ten points off, a total of\ntwenty points lost for taking so long.' object_descriptions: !!omap - OBJ_0: diff --git a/main.c b/main.c index b99eb22..1fb31ac 100644 --- a/main.c +++ b/main.c @@ -1024,14 +1024,25 @@ L2600: L2607: game.foobar = (game.foobar > 0 ? -game.foobar : 0); ++game.turns; - if (game.turns == game.thresh) { - speak(turn_threshold_messages[game.trndex]); - game.trnluz = game.trnluz + TRNVAL[game.trndex] / 100000; - ++game.trndex; - game.thresh = -1; - if (game.trndex <= TRNVLS) - game.thresh = MOD(TRNVAL[game.trndex], 100000) + 1; - } + + /* If a turn threshold has been met, apply penalties and tell + * the player about it. */ + for (int i = turn_threshold_count; i >= 0; --i) + { + if (game.turns == turn_thresholds[i].threshold) + { + game.trnluz += turn_thresholds[i].point_loss; + speak(turn_thresholds[i].message); + } + } + /* if (game.turns == game.thresh) { */ + /* speak(turn_threshold_messages[game.trndex]); */ + /* game.trnluz = game.trnluz + TRNVAL[game.trndex] / 100000; */ + /* ++game.trndex; */ + /* game.thresh = -1; */ + /* if (game.trndex <= TRNVLS) */ + /* game.thresh = MOD(TRNVAL[game.trndex], 100000) + 1; */ + /* } */ if (command.verb == SAY && WD2 > 0) command.verb = 0; if (command.verb == SAY) { diff --git a/newdungeon.py b/newdungeon.py index 923fb39..d16dc56 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -29,15 +29,22 @@ typedef struct {{ const char* yes_response; }} obituary_t; +typedef struct {{ + const int threshold; + const int point_loss; + const char* message; +}} turn_threshold_t; + extern location_t locations[]; extern object_description_t object_descriptions[]; extern const char* arbitrary_messages[]; extern const char* class_messages[]; -extern const char* turn_threshold_messages[]; +extern turn_threshold_t turn_thresholds[]; extern obituary_t obituaries[]; extern size_t CLSSES; extern int maximum_deaths; +extern int turn_threshold_count; enum arbitrary_messages_refs {{ {} @@ -47,10 +54,6 @@ enum class_messages_refs {{ {} }}; -enum turn_threshold_messages_refs {{ -{} -}}; - enum locations_refs {{ {} }}; @@ -70,7 +73,7 @@ const char* class_messages[] = {{ {} }}; -const char* turn_threshold_messages[] = {{ +turn_threshold_t turn_thresholds[] = {{ {} }}; @@ -88,6 +91,7 @@ obituary_t obituaries[] = {{ size_t CLSSES = {}; int maximum_deaths = {}; +int turn_threshold_count = {}; """ def make_c_string(string): @@ -127,12 +131,19 @@ def get_class_messages(cls): cls_str = cls_str[:-1] # trim trailing newline 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 += 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 @@ -194,7 +205,6 @@ with open(yaml_name, "r") as f: 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"]), ) @@ -203,12 +213,13 @@ c = c_template.format( h_name, get_arbitrary_messages(db["arbitrary_messages"]), get_class_messages(db["class_messages"]), - get_turn_threshold_messages(db["turn_threshold_messages"]), + get_turn_thresholds(db["turn_thresholds"]), get_locations(db["locations"]), get_object_descriptions(db["object_descriptions"]), get_obituaries(db["obituaries"]), len(db["class_messages"]), len(db["obituaries"]), + len(db["turn_thresholds"]), ) with open(h_name, "w") as hf: -- 2.31.1