/* ** WtScn.C -- Scanner for WT ** ** This module scans input messages from BL for things of note. ** See coding for details. */ #include #include #include #include "wt.h" #include "wtclk.h" #include "wtlog.h" #include "wtscn.h" #include "wtsta.h" /*=====================*/ /*===== Variables =====*/ /*=====================*/ static char tmp_str[90]; static char *recov_msgs[] = { "But you ", "But courageously you ", "Dazedly you ", "Gritting your teeth you ", "Groggily you ", "However you ", "Indomitably you ", "Summoning strength you ", "With a vast effort you ", "With renewed vigour you ", "With tremendous willpower you ", "Yet courageously you ", "Yet you ", "" }; char *level_list[] = { "warrior", "hero", "heroine", "champion", "superhero", "superheroine", "enchanter", "enchantress", "sorcerer", "sorceress", "necromancer", "necromancess", "legend", "wizard", "witch", "arch-wizard", "arch-witch", "" }; int level_trans[] = { 1, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10, 10, 10 }; static int watch_mode = 0; /* 1 if snoop auto split */ static int ppnlog_mode = 0; /* 1 if logging PPNs. */ /*===========================*/ /*===== Local Functions =====*/ /*===========================*/ /****************************************/ /* lookup(): look up a string in a list */ /****************************************/ int lookup(char *str, char **list) { int index; index = 1; while (**list) { if (! strcmp(str, *list)) return index; index++; list++; } return 0; } /* end lookup() */ /*============================*/ /*===== Global Functions =====*/ /*============================*/ /*********************************************/ /* */ /* scn_left(): scan a string at the left end */ /* */ /*********************************************/ int scn_left(char *msg, char *key) { return (! strncmp(msg, key, strlen(key))); } /* end scn_left */ /***********************************************/ /* scn_right(): scan a string at the right end */ /***********************************************/ int scn_right(char *msg, char *key) { int sm, sk; sm = strlen(msg); sk = strlen(key); if (sm < sk) return 0; msg += (sm-sk); return (! strcmp(msg, key)); } /* end scn_right() */ /**************************************/ /* scn_interp(): Interpret input line */ /**************************************/ void scn_interp(char *str) { char **msg_ptr; char *p, *q, *levelp; int l; if (scn_left(str, "Multi-User Dungeon")) { sta_play(1); return; } if (scn_left(str, "Hello, ") || scn_left(str, "Hello again, ")) { p = strchr(str, ',') + 2; strcpy(tmp_str, p); p = strstr(tmp_str, " the "); if (p == NULL) p = strchr(tmp_str, '!'); if (p != NULL) *p = '\0'; if (strlen(tmp_str) <= NAME_LEN) sta_ownname(tmp_str); return; } if (scn_left(str, "Score to date: ")) { p = strchr(str, ':') + 2; sta_score(p); return; } if (scn_left(str, "Strength: ")) { p = strchr(str, ':') + 2; p = strchr(p, ':') + 2; sta_stam(p); return; } if (scn_left(str, "Maximum ")) { p = strchr(str, ':') + 2; sta_maxs(p); return; } if (scn_left(str, "Score: ") || scn_left(str, "*Score: ")) { p = strchr(str, ':') + 2; sta_score(p); p = strchr(p, ':') + 2; sta_stam(p); p = strchr(p, '/') + 1; sta_maxs(p); sta_sleep(0); return; } if (scn_left(str, "[")) { p = str + 1; sta_score(p); return; } if (scn_left(str, "ZZZzzz") || scn_left(str, "You fall asleep, deep ")) { sta_sleep(1); } if (scn_left(str, "You are too alert ") || scn_left(str, "You wake up.")) { sta_sleep(0); } if (scn_left(str, "Your stamina is now ")) { p = strchr(str, 'w') + 2; sta_stam(p); sta_sleep(0); return; } /* --- stop repeating if "Your spell worked!" --- */ if (scn_left(str, "Your spell worked!")) { sta_repeat(0); sta_loop(0); } for (msg_ptr=recov_msgs; **msg_ptr; msg_ptr++) { if (scn_left(str, *msg_ptr)) { sta_hit(); return; } } if (scn_left(str, "Press :") || scn_left(str, "NO CARRIER")) { sta_play(0); set_watching(0); return; } /* --- look for snoop messages --- */ if (watch_mode) { if (scn_left(str, "You have started to watch on ") || scn_left(str, "You have started to snoop on ")) { set_watching(1); return; } else if (scn_left(str, "You have stopped snooping on ") || scn_left(str, "You can snoop on Someone no longer") || scn_left(str, "You're not snooping")) { set_watching(0); return; } } /* --- look for "has entered" --- */ strcpy(tmp_str, str); p = strstr(tmp_str, " has entered British Legends"); if (p != NULL) { *p = '\0'; p = strstr(tmp_str, " the "); if (p) { levelp = p + 5; *p = '\0'; } else { levelp = "novice"; } p = strchr(tmp_str, ' '); if (!p) { sta_player(tmp_str, level_trans[lookup(levelp, level_list)], 1); return; } } /* --- look for "has just passed on." --- */ p = strstr(tmp_str, " has just passed on."); if (p != NULL) { *p = '\0'; sta_passed_on(tmp_str); } /* --- look for player WHO list: "xxx [the level] is playing" --- */ strcpy(tmp_str, str); p = strstr(tmp_str, " is playing"); if (p != NULL) { *p = '\0'; p = strstr(tmp_str, " the "); if (p) { levelp = p + 5; *p = '\0'; } else { levelp = "novice"; } p = strchr(tmp_str, ' '); if (!p) { sta_player(tmp_str, level_trans[lookup(levelp, level_list)], 0); return; } } /* --- look for invis QU list: "(xxxx the level) [" */ if (tmp_str[0] == '(') { p = strchr(tmp_str, ' '); if (scn_left(p, " the ")) { *p = '\0'; q = strchr(p + 5, ')'); if (q != NULL && q[2]=='[') *q = '\0'; l = lookup(p + 5, level_list); if (l) { sta_player(tmp_str+1, level_trans[l], 0); return; } } } /* --- look for novice QU from wiz mode: "xxxx [123456,1234]" --- */ p = strchr(tmp_str, ']'); if (p!=NULL && p[1]=='\0') { q = strchr(tmp_str, ' '); if (q!=NULL & q[1]=='[') { *q = '\0'; sta_player(tmp_str, 1, 0); return; } } /* --- look for player QU list: "xxxx the level" (no novices) --- */ p = strchr(tmp_str, ' '); if (scn_left(p, " the ")) { *p = '\0'; q = strchr(p + 5, ' '); if (q != NULL && q[1]=='[') *q = '\0'; l = lookup(p + 5, level_list); if (l) { sta_player(tmp_str, level_trans[l], 0); return; } } } /* end scn_interp() */ /******************************************************/ /* scn_setppnlog(): set PPNLOG mode (called from CFG) */ /******************************************************/ void scn_setppnlog(int lmode) { ppnlog_mode = lmode; } /* end scn_setppnlog() */ /****************************************************/ /* scn_setwatch(): set WATCH mode (called from CFG) */ /****************************************************/ void scn_setwatch(int wmode) { watch_mode = wmode; } /* end scn_setwatch() */ /* EOF(WtScn.C) */