From: Eric S. Raymond Date: Wed, 21 Jun 2017 10:17:20 +0000 (-0400) Subject: Section 10 (class thresholds) is now parsed entirely from YAML. X-Git-Tag: 1.1~182 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f6373dd32e4ed75b18c9c6fb7dfa103d4ef68891;p=open-adventure.git Section 10 (class thresholds) is now parsed entirely from YAML. --- diff --git a/adventure.yaml b/adventure.yaml index 9cd5811..fca7676 100644 --- a/adventure.yaml +++ b/adventure.yaml @@ -1024,18 +1024,29 @@ arbitrary_messages: !!omap - GO_UNNEEDED: 'You don''t have to say "go" every time; just specify a direction or, if\nit''s nearby, name the place to which you wish to move.' - CANNOT_CARRY7: !!null -class_messages: !!omap -- CLS_0: !!null -- CLS_1: 'You are obviously a rank amateur. Better luck next time.' -- CLS_2: 'Your score qualifies you as a novice class adventurer.' -- CLS_3: 'You have achieved the rating: "Experienced Adventurer".' -- CLS_4: 'You may now consider yourself a "Seasoned Adventurer".' -- CLS_5: 'You have reached "Junior Master" status.' -- CLS_6: 'Your score puts you in Master Adventurer Class C.' -- CLS_7: 'Your score puts you in Master Adventurer Class B.' -- CLS_8: 'Your score puts you in Master Adventurer Class A.' -- 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.' +classes: +- threshold: 0 + message: !!null +- threshold: 45 + message: 'You are obviously a rank amateur. Better luck next time.' +- threshold: 120 + message: 'Your score qualifies you as a novice class adventurer.' +- threshold: 170 + message: 'You have achieved the rating: "Experienced Adventurer".' +- threshold: 250 + message: 'You may now consider yourself a "Seasoned Adventurer".' +- threshold: 320 + message: 'You have reached "Junior Master" status.' +- threshold: 375 + message: 'Your score puts you in Master Adventurer Class C.' +- threshold: 410 + message: 'Your score puts you in Master Adventurer Class B.' +- threshold: 426 + message: 'Your score puts you in Master Adventurer Class A.' +- threshold: 429 + message: 'All of Adventuredom gives tribute to you, Adventurer Grandmaster!' +- threshold: 9999 + message: '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_thresholds: - threshold: 350 diff --git a/dungeon.c b/dungeon.c index 0fbd17e..e17e93c 100644 --- a/dungeon.c +++ b/dungeon.c @@ -30,7 +30,6 @@ static long OLDLOC; // Storage for what comes out of the database long LINUSE; long TRVS; -long CLSSES; long TRNVLS; long TABNDX; long HNTMAX; @@ -45,7 +44,6 @@ long COND[LOCSIZ + 1]; long KEY[LOCSIZ + 1]; long LOCSND[LOCSIZ + 1]; long LINES[LINSIZ + 1]; -long CVAL[CLSMAX + 1]; long TTEXT[TRNSIZ + 1]; long TRNVAL[TRNSIZ + 1]; long TRAVEL[TRVSIZ + 1]; @@ -228,11 +226,7 @@ static void read_messages(FILE* database, long sect) continue; } if (sect == 10) { - CLSSES = CLSSES + 1; - if (CLSSES > CLSMAX) - BUG(TOO_MANY_CLASS_OR_TURN_MESSAGES); - CTEXT[CLSSES] = LINUSE; - CVAL[CLSSES] = loc; + /* now parsed from YAML */ continue; } if (sect == 6) { @@ -398,7 +392,6 @@ static int read_database(FILE* database) LINUSE = 1; TRVS = 1; - CLSSES = 0; TRNVLS = 0; /* Start new data section. Sect is the section number. */ @@ -529,7 +522,6 @@ static void write_file(FILE* header_file) write_1d(header_file, COND, LOCSIZ + 1, "COND"); write_1d(header_file, KEY, LOCSIZ + 1, "KEY"); write_1d(header_file, LOCSND, LOCSIZ + 1, "LOCSND"); - write_1d(header_file, CVAL, CLSMAX + 1, "CVAL"); write_1d(header_file, TRAVEL, TRVSIZ + 1, "TRAVEL"); write_1d(header_file, KTAB, TABSIZ + 1, "KTAB"); write_1d(header_file, ATAB, TABSIZ + 1, "ATAB"); diff --git a/newdungeon.py b/newdungeon.py index d16dc56..f8ef957 100755 --- a/newdungeon.py +++ b/newdungeon.py @@ -35,10 +35,15 @@ typedef struct {{ 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 const char* class_messages[]; +extern const class_t classes[]; extern turn_threshold_t turn_thresholds[]; extern obituary_t obituaries[]; @@ -50,10 +55,6 @@ enum arbitrary_messages_refs {{ {} }}; -enum class_messages_refs {{ -{} -}}; - enum locations_refs {{ {} }}; @@ -69,7 +70,7 @@ const char* arbitrary_messages[] = {{ {} }}; -const char* class_messages[] = {{ +const class_t classes[] = {{ {} }}; @@ -123,20 +124,25 @@ def get_arbitrary_messages(arb): return arb_str def get_class_messages(cls): - template = """ {}, + template = """ {{ + .threshold = {}, + .message = {}, + }}, """ 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 - return cls_str + return cls_str def get_turn_thresholds(trn): template = """ {{ .threshold = {}, .point_loss = {}, .message = {}, -}}, + }}, """ trn_str = "" for item in trn: @@ -204,7 +210,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["locations"]), get_refs(db["object_descriptions"]), ) @@ -212,12 +217,12 @@ h = h_template.format( c = c_template.format( h_name, get_arbitrary_messages(db["arbitrary_messages"]), - get_class_messages(db["class_messages"]), + get_class_messages(db["classes"]), 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["classes"]), len(db["obituaries"]), len(db["turn_thresholds"]), ) diff --git a/score.c b/score.c index 3091413..f3fc807 100644 --- a/score.c +++ b/score.c @@ -120,9 +120,9 @@ void terminate(enum termination mode) SETPRM(3, game.turns, game.turns); RSPEAK(TOTAL_SCORE); for (long i = 1; i <= (long)CLSSES; i++) { - if (CVAL[i] >= points) { - speak(class_messages[i]); - i = CVAL[i] + 1 - points; + if (classes[i].threshold >= points) { + speak(classes[i].message); + i = classes[i].threshold + 1 - points; SETPRM(1, i, i); RSPEAK(NEXT_HIGHER); exit(0);