diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index c72074717..f192fc20a 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -444,6 +444,13 @@ UniValue cclib_error(UniValue &result,const char *errorstr) return(result); } +uint256 juint256(cJSON *obj) +{ + uint256 tmp; bits256 t = jbits256(obj,0); + memcpy(&tmp,&t,sizeof(tmp)); + return(revuint256(tmp)); +} + cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will be freed by caller { cJSON *params; char *jsonstr,*newstr; int32_t i,j; diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index d6f834dbc..bdbf37b76 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -28,9 +28,9 @@ command(struct rogue_state *rs) char *fp; THING *mp; static char countch, direction, newcount = FALSE; - + if (on(player, ISHASTE)) - ntimes++; + ntimes++; /* * Let the daemons start up */ @@ -38,82 +38,85 @@ command(struct rogue_state *rs) do_fuses(rs,BEFORE); while (ntimes--) { - again = FALSE; - if (has_hit) - { - endmsg(rs); - has_hit = FALSE; - } - /* - * these are illegal things for the player to be, so if any are - * set, someone's been poking in memeory - */ - if (on(player, ISSLOW|ISGREED|ISINVIS|ISREGEN|ISTARGET)) - exit(1); - - look(rs,TRUE); - if (!running) - door_stop = FALSE; - status(rs); - lastscore = purse; - move(hero.y, hero.x); - if (!((running || count) && jump)) - refresh(); /* Draw screen */ - take = 0; - after = TRUE; - /* - * Read command or continue run - */ + again = FALSE; + if (has_hit) + { + endmsg(rs); + has_hit = FALSE; + } + /* + * these are illegal things for the player to be, so if any are + * set, someone's been poking in memeory + */ + if (on(player, ISSLOW|ISGREED|ISINVIS|ISREGEN|ISTARGET)) + exit(1); + + look(rs,TRUE); + if (!running) + door_stop = FALSE; + status(rs); + lastscore = purse; + move(hero.y, hero.x); + if ( rs->sleeptime != 0 ) + { + if (!((running || count) && jump)) + refresh(); /* Draw screen */ + } + take = 0; + after = TRUE; + /* + * Read command or continue run + */ #ifdef MASTER - if (wizard) - noscore = TRUE; + if (wizard) + noscore = TRUE; #endif - if (!no_command) - { - if (running || to_death) - ch = runch; - else if (count) - ch = countch; - else - { - ch = readchar(rs); - move_on = FALSE; - if (mpos != 0) /* Erase message if its there */ - msg(rs,""); - } - } - else - ch = '.'; - if (no_command) - { - if (--no_command == 0) - { - player.t_flags |= ISRUN; - msg(rs,"you can move again"); - } - } - else - { - /* - * check for prefixes - */ - newcount = FALSE; - if (isdigit(ch)) - { - count = 0; - newcount = TRUE; - while (isdigit(ch)) - { - count = count * 10 + (ch - '0'); - if (count > 255) - count = 255; - ch = readchar(rs); - } - countch = ch; - /* - * turn off count for commands which don't make sense - * to repeat - */ + if (!no_command) + { + if (running || to_death) + ch = runch; + else if (count) + ch = countch; + else + { + ch = readchar(rs); + move_on = FALSE; + if (mpos != 0) /* Erase message if its there */ + msg(rs,""); + } + } + else + ch = '.'; + if (no_command) + { + if (--no_command == 0) + { + player.t_flags |= ISRUN; + msg(rs,"you can move again"); + } + } + else + { + /* + * check for prefixes + */ + newcount = FALSE; + if (isdigit(ch)) + { + count = 0; + newcount = TRUE; + while (isdigit(ch)) + { + count = count * 10 + (ch - '0'); + if (count > 255) + count = 255; + ch = readchar(rs); + } + countch = ch; + /* + * turn off count for commands which don't make sense + * to repeat + */ switch (ch) { case CTRL('B'): case CTRL('H'): case CTRL('J'): @@ -317,9 +320,9 @@ over: if (chat(delta.y, delta.x) != TRAP) msg(rs,"no trap there"); else if (on(player, ISHALU)) - msg(rs,tr_name[rnd(NTRAPS)]); + msg(rs,(char *)tr_name[rnd(NTRAPS)]); else { - msg(rs,tr_name[*fp & F_TMASK]); + msg(rs,(char *)tr_name[*fp & F_TMASK]); *fp |= F_SEEN; } } @@ -521,9 +524,9 @@ foundone: if (!terse) addmsg(rs,"you found "); if (on(player, ISHALU)) - msg(rs,tr_name[rnd(NTRAPS)]); + msg(rs,(char *)tr_name[rnd(NTRAPS)]); else { - msg(rs,tr_name[*fp & F_TMASK]); + msg(rs,(char *)tr_name[*fp & F_TMASK]); *fp |= F_SEEN; } goto foundone; @@ -546,7 +549,7 @@ foundone: void help(struct rogue_state *rs) { - register struct h_list *strp; + register const struct h_list *strp; register char helpch; register int numprint, cnt; msg(rs,"character you want help for (* for all): "); @@ -617,9 +620,9 @@ void identify(struct rogue_state *rs) { register int ch; - register struct h_list *hp; + register const struct h_list *hp; register char *str; - static struct h_list ident_list[] = { + static const struct h_list ident_list[] = { {'|', "wall of a room", FALSE}, {'-', "wall of a room", FALSE}, {GOLD, "gold", FALSE}, @@ -729,9 +732,9 @@ void call(struct rogue_state *rs) { register THING *obj; - register struct obj_info *op = NULL; - register char **guess, *elsewise = NULL; - register bool *know; + register const struct obj_info *op = NULL; + register char **guess; const char *elsewise = NULL; + register const bool *know; obj = get_item(rs,"call", CALLABLE); /* @@ -758,7 +761,7 @@ call(struct rogue_state *rs) elsewise = ws_made[obj->o_which]; norm: know = &op->oi_know; - guess = &op->oi_guess; + guess = (char **)&op->oi_guess; if (*guess != NULL) elsewise = *guess; when FOOD: diff --git a/src/cc/rogue/extern.c b/src/cc/rogue/extern.c index fb732dfde..b84e6fa7b 100644 --- a/src/cc/rogue/extern.c +++ b/src/cc/rogue/extern.c @@ -13,6 +13,8 @@ #include #include "rogue.h" + + bool after; /* True if we want after daemons */ bool again; /* Repeating the last command */ int noscore; /* Was a wizard sometime */ @@ -50,41 +52,21 @@ bool pack_used[26] = { /* Is the character used in the pack? */ }; char dir_ch; /* Direction from last get_dir() call */ +char runch; /* Direction player is running */ +char take; /* Thing she is taking */ + +int orig_dsusp; /* Original dsusp char */ char file_name[MAXSTR]; /* Save file name */ char huh[MAXSTR]; /* The last message printed */ -char *p_colors[MAXPOTIONS]; /* Colors of the potions */ char prbuf[2*MAXSTR]; /* buffer for sprintfs */ -char *r_stones[MAXRINGS]; /* Stone settings of the rings */ -char runch; /* Direction player is running */ -char *s_names[MAXSCROLLS]; /* Names of the scrolls */ -char take; /* Thing she is taking */ char whoami[MAXSTR]; /* Name of player */ -char *ws_made[MAXSTICKS]; /* What sticks are made of */ -char *ws_type[MAXSTICKS]; /* Is it a wand or a staff */ -int orig_dsusp; /* Original dsusp char */ char fruit[MAXSTR] = /* Favorite fruit */ { 's', 'l', 'i', 'm', 'e', '-', 'm', 'o', 'l', 'd', '\0' }; char home[MAXSTR] = { '\0' }; /* User's home directory */ -char *inv_t_name[] = { - "Overwrite", - "Slow", - "Clear" -}; char l_last_comm = '\0'; /* Last last_comm */ char l_last_dir = '\0'; /* Last last_dir */ char last_comm = '\0'; /* Last command typed */ char last_dir = '\0'; /* Last direction given */ -char *tr_name[] = { /* Names of the traps */ - "a trapdoor", - "an arrow trap", - "a sleeping gas trap", - "a beartrap", - "a teleport trap", - "a poison dart trap", - "a rust trap", - "a mysterious trap" -}; - int n_objs; /* # items listed in inventory() call */ int ntraps; /* Number of traps on this level */ @@ -96,19 +78,8 @@ int max_hit; /* Max damage done to her in to_death */ int max_level; /* Deepest player has gone */ int mpos = 0; /* Where cursor is on top line */ int no_food = 0; /* Number of levels without food */ -int a_class[MAXARMORS] = { /* Armor class for each armor type */ - 8, /* LEATHER */ - 7, /* RING_MAIL */ - 7, /* STUDDED_LEATHER */ - 6, /* SCALE_MAIL */ - 5, /* CHAIN_MAIL */ - 4, /* SPLINT_MAIL */ - 4, /* BANDED_MAIL */ - 3, /* PLATE_MAIL */ -}; int count = 0; /* Number of times to repeat command */ -FILE *scoreboard = NULL; /* File descriptor for score file */ int food_left; /* Amount of food in hero's stomach */ int lastscore = -1; /* Score before this turn */ int no_command = 0; /* Number of turns asleep */ @@ -117,31 +88,9 @@ int purse = 0; /* How much gold he has */ int quiet = 0; /* Number of quiet turns */ int vf_hit = 0; /* Number of time flytrap has hit */ -int dnum; /* Dungeon number */ + +//int dnum; /* Dungeon number */ uint64_t seed; /* Random number seed */ -int e_levels[] = { - 10L, - 20L, - 40L, - 80L, - 160L, - 320L, - 640L, - 1300L, - 2600L, - 5200L, - 13000L, - 26000L, - 50000L, - 100000L, - 200000L, - 400000L, - 800000L, - 2000000L, - 4000000L, - 8000000L, - 0L -}; coord delta; /* Change indicated to get_dir() */ coord oldpos; /* Position before last look() call */ @@ -149,6 +98,11 @@ coord stairs; /* Location of staircase */ PLACE places[MAXLINES*MAXCOLS]; /* level map */ +const char *p_colors[MAXPOTIONS]; /* Colors of the potions */ +const char *r_stones[MAXRINGS]; /* Stone settings of the rings */ +const char *ws_made[MAXSTICKS]; /* What sticks are made of */ +const char *ws_type[MAXSTICKS]; /* Is it a wand or a staff */ + THING *cur_armor; /* What he is wearing */ THING *cur_ring[2]; /* Which rings are being worn */ THING *cur_weapon; /* Which weapon he is weilding */ @@ -156,18 +110,36 @@ THING *l_last_pick = NULL; /* Last last_pick */ THING *last_pick = NULL; /* Last object picked in get_item() */ THING *lvl_obj = NULL; /* List of objects on this level */ THING *mlist = NULL; /* List of monsters on the level */ +struct room *oldrp; /* Roomin(&oldpos) */ THING player; /* His stats */ - /* restart of game */ - WINDOW *hw = NULL; /* used as a scratch window */ +char *s_names[MAXSCROLLS]; /* Names of the scrolls */ +FILE *scoreboard = NULL; /* File descriptor for score file */ #define INIT_STATS { 16, 0, 1, 10, 12, "1x4", 12 } struct stats max_stats = INIT_STATS; /* The maximum for the player */ +struct stats orig_max_stats = INIT_STATS; -struct room *oldrp; /* Roomin(&oldpos) */ -struct room rooms[MAXROOMS]; /* One for each room -- A level */ -struct room passages[MAXPASS] = /* One for each passage */ +struct monster monsters[26]; +struct room passages[MAXPASS],rooms[MAXROOMS]; /* One for each room -- A level */ +struct obj_info things[NUMTHINGS],ring_info[MAXRINGS],pot_info[MAXPOTIONS],arm_info[MAXARMORS],scr_info[MAXSCROLLS],weap_info[MAXWEAPONS + 1],ws_info[MAXSTICKS]; + +////////////// constants +#define ___ 1 +#define XX 10 + +const struct obj_info origthings[NUMTHINGS] = { + { 0, 26 }, /* potion */ + { 0, 36 }, /* scroll */ + { 0, 16 }, /* food */ + { 0, 7 }, /* weapon */ + { 0, 7 }, /* armor */ + { 0, 4 }, /* ring */ + { 0, 4 }, /* stick */ +}; + +const struct room origpassages[MAXPASS] = /* One for each passage */ { { {0, 0}, {0, 0}, {0, 0}, 0, ISGONE|ISDARK, 0, {{0,0}} }, { {0, 0}, {0, 0}, {0, 0}, 0, ISGONE|ISDARK, 0, {{0,0}} }, @@ -182,10 +154,7 @@ struct room passages[MAXPASS] = /* One for each passage */ { {0, 0}, {0, 0}, {0, 0}, 0, ISGONE|ISDARK, 0, {{0,0}} }, { {0, 0}, {0, 0}, {0, 0}, 0, ISGONE|ISDARK, 0, {{0,0}} } }; - -#define ___ 1 -#define XX 10 -struct monster monsters[26] = +const struct monster origmonsters[26] = { /* Name CARRY FLAG str, exp, lvl, amr, hpt, dmg */ { "aquator", 0, ISMEAN, { XX, 20, 5, 2, ___, "0x0/0x0" } }, @@ -220,17 +189,7 @@ struct monster monsters[26] = #undef ___ #undef XX -struct obj_info things[NUMTHINGS] = { - { 0, 26 }, /* potion */ - { 0, 36 }, /* scroll */ - { 0, 16 }, /* food */ - { 0, 7 }, /* weapon */ - { 0, 7 }, /* armor */ - { 0, 4 }, /* ring */ - { 0, 4 }, /* stick */ -}; - -struct obj_info arm_info[MAXARMORS] = { +const struct obj_info origarm_info[MAXARMORS] = { { "leather armor", 20, 20, NULL, FALSE }, { "ring mail", 15, 25, NULL, FALSE }, { "studded leather armor", 15, 20, NULL, FALSE }, @@ -240,7 +199,7 @@ struct obj_info arm_info[MAXARMORS] = { { "banded mail", 10, 90, NULL, FALSE }, { "plate mail", 5, 150, NULL, FALSE }, }; -struct obj_info pot_info[MAXPOTIONS] = { +const struct obj_info origpot_info[MAXPOTIONS] = { { "confusion", 7, 5, NULL, FALSE }, { "hallucination", 8, 5, NULL, FALSE }, { "poison", 8, 5, NULL, FALSE }, @@ -256,7 +215,7 @@ struct obj_info pot_info[MAXPOTIONS] = { { "blindness", 5, 5, NULL, FALSE }, { "levitation", 6, 75, NULL, FALSE }, }; -struct obj_info ring_info[MAXRINGS] = { +const struct obj_info origring_info[MAXRINGS] = { { "protection", 9, 400, NULL, FALSE }, { "add strength", 9, 400, NULL, FALSE }, { "sustain strength", 5, 280, NULL, FALSE }, @@ -272,7 +231,7 @@ struct obj_info ring_info[MAXRINGS] = { { "stealth", 7, 470, NULL, FALSE }, { "maintain armor", 5, 380, NULL, FALSE }, }; -struct obj_info scr_info[MAXSCROLLS] = { +const struct obj_info origscr_info[MAXSCROLLS] = { { "monster confusion", 7, 140, NULL, FALSE }, { "magic mapping", 4, 150, NULL, FALSE }, { "hold monster", 2, 180, NULL, FALSE }, @@ -292,7 +251,7 @@ struct obj_info scr_info[MAXSCROLLS] = { { "aggravate monsters", 3, 20, NULL, FALSE }, { "protect armor", 2, 250, NULL, FALSE }, }; -struct obj_info weap_info[MAXWEAPONS + 1] = { +const struct obj_info origweap_info[MAXWEAPONS + 1] = { { "mace", 11, 8, NULL, FALSE }, { "long sword", 11, 15, NULL, FALSE }, { "short bow", 12, 15, NULL, FALSE }, @@ -304,7 +263,7 @@ struct obj_info weap_info[MAXWEAPONS + 1] = { { "spear", 12, 5, NULL, FALSE }, { NULL, 0 }, /* DO NOT REMOVE: fake entry for dragon's breath */ }; -struct obj_info ws_info[MAXSTICKS] = { +const struct obj_info origws_info[MAXSTICKS] = { { "light", 12, 250, NULL, FALSE }, { "invisibility", 6, 5, NULL, FALSE }, { "lightning", 3, 330, NULL, FALSE }, @@ -321,7 +280,7 @@ struct obj_info ws_info[MAXSTICKS] = { { "cancellation", 5, 280, NULL, FALSE }, }; -struct h_list helpstr[] = { +const struct h_list helpstr[] = { {'?', " prints help", TRUE}, {'/', " identify object", TRUE}, {'h', " left", TRUE}, @@ -389,3 +348,169 @@ struct h_list helpstr[] = { {'v', " print version number", TRUE}, {0, NULL } }; + +const char *inv_t_name[] = { + "Overwrite", + "Slow", + "Clear" +}; + +const char *tr_name[] = { /* Names of the traps */ + "a trapdoor", + "an arrow trap", + "a sleeping gas trap", + "a beartrap", + "a teleport trap", + "a poison dart trap", + "a rust trap", + "a mysterious trap" +}; + +const int32_t a_class[MAXARMORS] = { /* Armor class for each armor type */ + 8, /* LEATHER */ + 7, /* RING_MAIL */ + 7, /* STUDDED_LEATHER */ + 6, /* SCALE_MAIL */ + 5, /* CHAIN_MAIL */ + 4, /* SPLINT_MAIL */ + 4, /* BANDED_MAIL */ + 3, /* PLATE_MAIL */ +}; + +const int32_t e_levels[] = { + 10L, + 20L, + 40L, + 80L, + 160L, + 320L, + 640L, + 1300L, + 2600L, + 5200L, + 13000L, + 26000L, + 50000L, + 100000L, + 200000L, + 400000L, + 800000L, + 2000000L, + 4000000L, + 8000000L, + 0L +}; + +#include +extern int between; +extern int group; +extern coord nh; + +void externs_clear() +{ + int i; + after = 0; /* True if we want after daemons */ + again = 0; /* Repeating the last command */ + noscore = 0; /* Was a wizard sometime */ + seenstairs = 0; /* Have seen the stairs (for lsd) */ + amulet = FALSE; /* He found the amulet */ + door_stop = FALSE; /* Stop running when we pass a door */ + fight_flush = FALSE; /* True if toilet input */ + firstmove = FALSE; /* First move after setting door_stop */ + got_ltc = FALSE; /* We have gotten the local tty chars */ + has_hit = FALSE; /* Has a "hit" message pending in msg */ + in_shell = FALSE; /* True if executing a shell */ + inv_describe = TRUE; /* Say which way items are being used */ + jump = FALSE; /* Show running as series of jumps */ + kamikaze = FALSE; /* to_death really to DEATH */ + lower_msg = FALSE; /* Messages should start w/lower case */ + move_on = FALSE; /* Next move shouldn't pick up items */ + msg_esc = FALSE; /* Check for ESC from msg's --More-- */ + passgo = FALSE; /* Follow passages */ + playing = TRUE; /* True until he quits */ + q_comm = FALSE; /* Are we executing a 'Q' command? */ + running = FALSE; /* True if player is running */ + save_msg = TRUE; /* Remember last msg */ + see_floor = TRUE; /* Show the lamp illuminated floor */ + stat_msg = FALSE; /* Should status() print as a msg() */ + terse = FALSE; /* True if we should be short */ + to_death = FALSE; /* Fighting is to the death! */ + tombstone = TRUE; /* Print out tombstone at end */ +#ifdef MASTER + int wizard = FALSE; /* True if allows wizard commands */ +#endif + for (i=0; i<26; i++) + pack_used[i] = FALSE; + for (i=0; io_type = FOOD; - obj->o_count = 1; - add_pack(rs,obj, TRUE); - /* - * And his suit of armor - */ - obj = new_item(); - obj->o_type = ARMOR; - obj->o_which = RING_MAIL; - obj->o_arm = a_class[RING_MAIL] - 1; - obj->o_flags |= ISKNOW; - obj->o_count = 1; - cur_armor = obj; - add_pack(rs,obj, TRUE); - /* - * Give him his weaponry. First a mace. - */ - obj = new_item(); - init_weapon(obj, MACE); - obj->o_hplus = 1; - obj->o_dplus = 1; - obj->o_flags |= ISKNOW; - add_pack(rs,obj, TRUE); - cur_weapon = obj; - /* - * Now a +1 bow - */ - obj = new_item(); - init_weapon(obj, BOW); - obj->o_hplus = 1; - obj->o_flags |= ISKNOW; - add_pack(rs,obj, TRUE); - /* - * Now some arrows - */ - obj = new_item(); - init_weapon(obj, ARROW); - obj->o_count = rnd(15) + 25; - obj->o_flags |= ISKNOW; - add_pack(rs,obj, TRUE); + + if ( 0 && rogue_restorepack(rs) == 0 ) + { + //rs->P.gold = purse; + max_hp = rs->P.hitpoints; + max_stats.s_str = rs->P.strength; + pstats.s_lvl = rs->P.level; + pstats.s_exp = rs->P.experience; + for (i=0; iP.packsize; i++) + { + obj = new_item(); + rogue_restoreobject(obj,&rs->P.roguepack[i]); + add_pack(rs,obj,TRUE); + } + // duplicate rng usage of normal case + obj = new_item(); + init_weapon(obj, MACE); + init_weapon(obj, BOW); + init_weapon(obj, ARROW); + obj->o_count = rnd(15) + 25; + free(obj); + } + else + { + /* + * Give him some food + */ + obj = new_item(); + obj->o_type = FOOD; + obj->o_count = 1; + add_pack(rs,obj, TRUE); + /* + * And his suit of armor + */ + obj = new_item(); + obj->o_type = ARMOR; + obj->o_which = RING_MAIL; + obj->o_arm = a_class[RING_MAIL] - 1; + obj->o_flags |= ISKNOW; + obj->o_count = 1; + cur_armor = obj; + add_pack(rs,obj, TRUE); + /* + * Give him his weaponry. First a mace. + */ + obj = new_item(); + init_weapon(obj, MACE); + obj->o_hplus = 1; + obj->o_dplus = 1; + obj->o_flags |= ISKNOW; + add_pack(rs,obj, TRUE); + cur_weapon = obj; + /* + * Now a +1 bow + */ + obj = new_item(); + init_weapon(obj, BOW); + obj->o_hplus = 1; + obj->o_flags |= ISKNOW; + add_pack(rs,obj, TRUE); + /* + * Now some arrows + */ + obj = new_item(); + init_weapon(obj, ARROW); + obj->o_count = rnd(15) + 25; + obj->o_flags |= ISKNOW; + add_pack(rs,obj, TRUE); + //fprintf(stderr,"initial o_count.%d\n",obj->o_count); sleep(3); + } } /* @@ -78,7 +105,7 @@ init_player(struct rogue_state *rs) * potions and scrolls */ -char *rainbow[] = { +const char *rainbow[] = { "amber", "aquamarine", "black", @@ -111,7 +138,7 @@ char *rainbow[] = { #define NCOLORS (sizeof rainbow / sizeof (char *)) int cNCOLORS = NCOLORS; -static char *sylls[] = { +static const char *sylls[] = { "a", "ab", "ag", "aks", "ala", "an", "app", "arg", "arze", "ash", "bek", "bie", "bit", "bjor", "blu", "bot", "bu", "byt", "comp", "con", "cos", "cre", "dalf", "dan", "den", "do", "e", "eep", "el", @@ -130,7 +157,7 @@ static char *sylls[] = { "zok", "zon", "zum", }; -STONE stones[] = { +const STONE stones[] = { { "agate", 25}, { "alexandrite", 40}, { "amethyst", 50}, @@ -162,7 +189,7 @@ STONE stones[] = { #define NSTONES (sizeof stones / sizeof (STONE)) int cNSTONES = NSTONES; -char *wood[] = { +const char *wood[] = { "avocado wood", "balsa", "bamboo", @@ -201,7 +228,7 @@ char *wood[] = { #define NWOOD (sizeof wood / sizeof (char *)) int cNWOOD = NWOOD; -char *metal[] = { +const char *metal[] = { "aluminum", "beryllium", "bone", @@ -240,16 +267,16 @@ void init_colors() { register int i, j; - + memset(used,0,sizeof(used)); for (i = 0; i < NCOLORS; i++) - used[i] = FALSE; + used[i] = FALSE; for (i = 0; i < MAXPOTIONS; i++) { - do - j = rnd(NCOLORS); - until (!used[j]); - used[j] = TRUE; - p_colors[i] = rainbow[j]; + do + j = rnd(NCOLORS); + until (!used[j]); + used[j] = TRUE; + p_colors[i] = rainbow[j]; } } @@ -263,7 +290,7 @@ void init_names() { register int nsyl; - register char *cp, *sp; + register char *cp; const char *sp; register int i, nwords; for (i = 0; i < MAXSCROLLS; i++) @@ -297,17 +324,16 @@ void init_stones() { register int i, j; - for (i = 0; i < NSTONES; i++) - used[i] = FALSE; + used[i] = FALSE; for (i = 0; i < MAXRINGS; i++) { - do - j = rnd(NSTONES); - until (!used[j]); - used[j] = TRUE; - r_stones[i] = stones[j].st_name; - ring_info[i].oi_worth += stones[j].st_value; + do + j = rnd(NSTONES); + until (!used[j]); + used[j] = TRUE; + r_stones[i] = stones[j].st_name; + ring_info[i].oi_worth += stones[j].st_value; } } @@ -319,39 +345,39 @@ void init_materials() { register int i, j; - register char *str; + register const char *str; static bool metused[NMETAL]; - + memset(metused,0,sizeof(metused)); for (i = 0; i < NWOOD; i++) - used[i] = FALSE; + used[i] = FALSE; for (i = 0; i < NMETAL; i++) - metused[i] = FALSE; + metused[i] = FALSE; for (i = 0; i < MAXSTICKS; i++) { - for (;;) - if (rnd(2) == 0) - { - j = rnd(NMETAL); - if (!metused[j]) - { - ws_type[i] = "wand"; - str = metal[j]; - metused[j] = TRUE; - break; - } - } - else - { - j = rnd(NWOOD); - if (!used[j]) - { - ws_type[i] = "staff"; - str = wood[j]; - used[j] = TRUE; - break; - } - } - ws_made[i] = str; + for (;;) + if (rnd(2) == 0) + { + j = rnd(NMETAL); + if (!metused[j]) + { + ws_type[i] = "wand"; + str = metal[j]; + metused[j] = TRUE; + break; + } + } + else + { + j = rnd(NWOOD); + if (!used[j]) + { + ws_type[i] = "staff"; + str = wood[j]; + used[j] = TRUE; + break; + } + } + ws_made[i] = str; } } @@ -380,18 +406,17 @@ init_materials() void sumprobs(struct obj_info *info, int bound #ifdef MASTER - , char *name + , char *name #endif ) { #ifdef MASTER - struct obj_info *start = info; + struct obj_info *start = info; #endif struct obj_info *endp; - endp = info + bound; while (++info < endp) - info->oi_prob += (info - 1)->oi_prob; + info->oi_prob += (info - 1)->oi_prob; #ifdef MASTER badcheck(name, start, bound); #endif @@ -443,5 +468,5 @@ badcheck(char *name, struct obj_info *info, int bound) char * pick_color(char *col) { - return (on(player, ISHALU) ? rainbow[rnd(NCOLORS)] : col); + return (on(player, ISHALU) ? (char *)rainbow[rnd(NCOLORS)] : col); } diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index bdf3c515c..f4a859b38 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -24,16 +24,16 @@ int msg(struct rogue_state *rs,char *fmt, ...) { va_list args; - + /* * if the string is "", just clear the line */ if (*fmt == '\0') { - move(0, 0); - clrtoeol(); - mpos = 0; - return ~ESCAPE; + move(0, 0); + clrtoeol(); + mpos = 0; + return ~ESCAPE; } /* * otherwise add to the message and flush it out @@ -70,39 +70,41 @@ endmsg(struct rogue_state *rs) char ch; if (save_msg) - strcpy(huh, msgbuf); + strcpy(huh, msgbuf); if (mpos) { - look(rs,FALSE); - mvaddstr(0, mpos, "--More--"); - refresh(); - if (!msg_esc) - wait_for(rs,' '); - else - { - while ((ch = readchar(rs)) != ' ') - if (ch == ESCAPE) - { - msgbuf[0] = '\0'; - mpos = 0; - newpos = 0; - msgbuf[0] = '\0'; - return ESCAPE; - } - } + look(rs,FALSE); + mvaddstr(0, mpos, "--More--"); + if ( rs->sleeptime != 0 ) + refresh(); + if (!msg_esc) + wait_for(rs,' '); + else + { + while ((ch = readchar(rs)) != ' ') + if (ch == ESCAPE) + { + msgbuf[0] = '\0'; + mpos = 0; + newpos = 0; + msgbuf[0] = '\0'; + return ESCAPE; + } + } } /* * All messages should start with uppercase, except ones that * start with a pack addressing character */ if (islower(msgbuf[0]) && !lower_msg && msgbuf[1] != ')') - msgbuf[0] = (char) toupper(msgbuf[0]); + msgbuf[0] = (char) toupper(msgbuf[0]); mvaddstr(0, 0, msgbuf); clrtoeol(); mpos = newpos; newpos = 0; msgbuf[0] = '\0'; - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); return ~ESCAPE; } @@ -188,35 +190,6 @@ readchar(struct rogue_state *rs) return(ch); } -/*char readchar() -{ - static FILE *keystrokefp; int c; - - if ( keystrokefp == 0 ) - keystrokefp = fopen("keystrokes","rb"); - if ( keystrokefp != 0 ) - { - if ( (c= fgetc(keystrokefp)) == EOF ) - eofflag = 1; - else return(c); - } else eofflag = 1; - ch = (char) md_readchar(); - - if (ch == 3) - { - quit(0); - return(27); - } - { - static FILE *replayfp; - if ( replayfp == 0 ) - replayfp = fopen("replay","wb"); - if ( replayfp != 0 ) - fputc(ch,replayfp), fflush(replayfp); - } - return(ch); -}*/ - /* * status: * Display the important stats line. Keep the cursor where it was. diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index f571be628..6affc662c 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -12,6 +12,7 @@ #include #include +#include #include "rogue.h" #ifdef MASTER @@ -81,19 +82,50 @@ _free_list(THING **ptr) * Free up an item */ +int32_t itemcounter; +THING *thingptrs[100000]; +int32_t numptrs; + void discard(THING *item) { #ifdef MASTER total--; #endif + if ( 0 ) + { + int32_t i; + for (i=0; i_t._t_type,thingptrs[i]->o_type,thingptrs[i]->o_type); + free(thingptrs[i]); + } + memset(thingptrs,0,sizeof(thingptrs)); + numptrs = 0; +} + /* * new_item * Get a new item with a specified size */ + THING * new_item(void) { @@ -107,6 +139,12 @@ new_item(void) #else item = (THING *)calloc(1, sizeof *item); #endif + if ( 0 ) + { + thingptrs[numptrs++] = item; + if ( (++itemcounter % 100) == 0 ) + fprintf(stderr,"itemcounter.%d\n",itemcounter); + } item->l_next = NULL; item->l_prev = NULL; return item; diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index d2805ed73..7efdebc8d 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -13,6 +13,7 @@ * * ******************************************************************************/ + #include #include #include diff --git a/src/cc/rogue/misc.c b/src/cc/rogue/misc.c index 775878450..168886b6b 100644 --- a/src/cc/rogue/misc.c +++ b/src/cc/rogue/misc.c @@ -350,17 +350,17 @@ chg_str(int amt) { //auto jl777: strange compiler error str_t comp; - + if (amt == 0) return; add_str(&pstats.s_str, amt); comp = pstats.s_str; if (ISRING(LEFT, R_ADDSTR)) - add_str(&comp, -cur_ring[LEFT]->o_arm); + add_str(&comp, -cur_ring[LEFT]->o_arm); if (ISRING(RIGHT, R_ADDSTR)) - add_str(&comp, -cur_ring[RIGHT]->o_arm); + add_str(&comp, -cur_ring[RIGHT]->o_arm); if (comp > max_stats.s_str) - max_stats.s_str = comp; + max_stats.s_str = comp; } /* diff --git a/src/cc/rogue/monsters.c b/src/cc/rogue/monsters.c index c9441efa3..4649de9a2 100644 --- a/src/cc/rogue/monsters.c +++ b/src/cc/rogue/monsters.c @@ -218,7 +218,10 @@ void give_pack(struct rogue_state *rs,THING *tp) { if (level >= max_level && rnd(100) < monsters[tp->t_type-'A'].m_carry) - attach(tp->t_pack, new_thing(rs)); + { + //fprintf(stderr,"give_pack\n"); + attach(tp->t_pack, new_thing(rs)); + } } /* diff --git a/src/cc/rogue/move.c b/src/cc/rogue/move.c index b402f4fa1..87276e8e2 100644 --- a/src/cc/rogue/move.c +++ b/src/cc/rogue/move.c @@ -230,7 +230,8 @@ turnref() if (jump) { leaveok(stdscr, TRUE); - refresh(); + if ( globalR.sleeptime != 0 ) + refresh(); leaveok(stdscr, FALSE); } pp->p_flags |= F_SEEN; diff --git a/src/cc/rogue/new_level.c b/src/cc/rogue/new_level.c index 2c0ae7b51..9b2348b3f 100644 --- a/src/cc/rogue/new_level.c +++ b/src/cc/rogue/new_level.c @@ -26,25 +26,25 @@ new_level(struct rogue_state *rs) PLACE *pp; char *sp; int i; - + player.t_flags &= ~ISHELD; /* unhold when you go down just in case */ if (level > max_level) - max_level = level; + max_level = level; /* * Clean things off from last level */ for (pp = places; pp < &places[MAXCOLS*MAXLINES]; pp++) { - pp->p_ch = ' '; - pp->p_flags = F_REAL; - pp->p_monst = NULL; + pp->p_ch = ' '; + pp->p_flags = F_REAL; + pp->p_monst = NULL; } clear(); /* * Free up the monsters on the last level */ for (tp = mlist; tp != NULL; tp = next(tp)) - free_list(tp->t_pack); + free_list(tp->t_pack); free_list(mlist); /* * Throw away stuff left on the previous level (if anything) @@ -53,32 +53,33 @@ new_level(struct rogue_state *rs) do_rooms(rs); /* Draw rooms */ do_passages(rs); /* Draw passages */ no_food++; + //fprintf(stderr,"new_level.%d\n",level); put_things(rs); /* Place objects (if any) */ /* * Place the traps */ if (rnd(10) < level) { - ntraps = rnd(level / 4) + 1; - if (ntraps > MAXTRAPS) - ntraps = MAXTRAPS; - i = ntraps; - while (i--) - { - /* - * not only wouldn't it be NICE to have traps in mazes - * (not that we care about being nice), since the trap - * number is stored where the passage number is, we - * can't actually do it. - */ - do - { - find_floor((struct room *) NULL, &stairs, FALSE, FALSE); - } while (chat(stairs.y, stairs.x) != FLOOR); - sp = &flat(stairs.y, stairs.x); - *sp &= ~F_REAL; - *sp |= rnd(NTRAPS); - } + ntraps = rnd(level / 4) + 1; + if (ntraps > MAXTRAPS) + ntraps = MAXTRAPS; + i = ntraps; + while (i--) + { + /* + * not only wouldn't it be NICE to have traps in mazes + * (not that we care about being nice), since the trap + * number is stored where the passage number is, we + * can't actually do it. + */ + do + { + find_floor((struct room *) NULL, &stairs, FALSE, FALSE); + } while (chat(stairs.y, stairs.x) != FLOOR); + sp = &flat(stairs.y, stairs.x); + *sp &= ~F_REAL; + *sp |= rnd(NTRAPS); + } } /* * Place the staircase down. @@ -86,17 +87,17 @@ new_level(struct rogue_state *rs) find_floor((struct room *) NULL, &stairs, FALSE, FALSE); chat(stairs.y, stairs.x) = STAIRS; seenstairs = FALSE; - + for (tp = mlist; tp != NULL; tp = next(tp)) - tp->t_room = roomin(rs,&tp->t_pos); - + tp->t_room = roomin(rs,&tp->t_pos); + find_floor((struct room *) NULL, &hero, FALSE, TRUE); enter_room(rs,&hero); mvaddch(hero.y, hero.x, PLAYER); if (on(player, SEEMONST)) - turn_see(FALSE); + turn_see(FALSE); if (on(player, ISHALU)) - visuals(rs,0); + visuals(rs,0); } /* @@ -147,7 +148,8 @@ put_things(struct rogue_state *rs) * Pick a new object and link it in the list */ obj = new_thing(rs); - attach(lvl_obj, obj); + //fprintf(stderr,"put_things i.%d obj.%p\n",i,obj); + attach(lvl_obj, obj); /* * Put it somewhere */ @@ -200,6 +202,7 @@ treas_room(struct rogue_state *rs) while (nm--) { find_floor(rp, &mp, 2 * MAXTRIES, FALSE); + //fprintf(stderr,"treas_room\n"); tp = new_thing(rs); tp->o_pos = mp; attach(lvl_obj, tp); diff --git a/src/cc/rogue/options.c b/src/cc/rogue/options.c index 667d83248..6907da598 100644 --- a/src/cc/rogue/options.c +++ b/src/cc/rogue/options.c @@ -403,7 +403,7 @@ parse_opts(char *str) char *sp; OPTION *op; int len; - char **i; + const char **i; char *start; while (*str) diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index 8385f95dd..ee628b4f0 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -252,25 +252,25 @@ inventory(struct rogue_state *rs,THING *list, int type) n_objs = 0; for (; list != NULL; list = next(list)) { - if (type && type != list->o_type && !(type == CALLABLE && - list->o_type != FOOD && list->o_type != AMULET) && - !(type == R_OR_S && (list->o_type == RING || list->o_type == STICK))) - continue; - n_objs++; + if (type && type != list->o_type && !(type == CALLABLE && + list->o_type != FOOD && list->o_type != AMULET) && + !(type == R_OR_S && (list->o_type == RING || list->o_type == STICK))) + continue; + n_objs++; #ifdef MASTER - if (!list->o_packch) - strcpy(inv_temp, "%s"); - else + if (!list->o_packch) + strcpy(inv_temp, "%s"); + else #endif - sprintf(inv_temp, "%c) %%s", list->o_packch); - msg_esc = TRUE; - if (add_line(rs,inv_temp, inv_name(list, FALSE)) == ESCAPE) - { - msg_esc = FALSE; - msg(rs,""); - return TRUE; - } - msg_esc = FALSE; + sprintf(inv_temp, "%c) %%s", list->o_packch); + msg_esc = TRUE; + if (add_line(rs,inv_temp, inv_name(list, FALSE)) == ESCAPE) + { + msg_esc = FALSE; + msg(rs,""); + return TRUE; + } + msg_esc = FALSE; } if (n_objs == 0) { diff --git a/src/cc/rogue/rip.c b/src/cc/rogue/rip.c index dc22566e9..69eb89751 100644 --- a/src/cc/rogue/rip.c +++ b/src/cc/rogue/rip.c @@ -218,6 +218,7 @@ score(int amount, int flags, char monst) signal(SIGINT, fp); } } + free(top_ten); } /* diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 8acdf8844..554c0ae4e 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -21,10 +21,48 @@ * The main program, of course */ struct rogue_state globalR; +void garbage_collect(); + +void purge_obj_guess(struct obj_info *array,int32_t n) +{ + int32_t i; + for (i=0; iseed; + //clear(); + purge_obj_guess(things,NUMTHINGS); + purge_obj_guess(ring_info,MAXRINGS); + purge_obj_guess(pot_info,MAXPOTIONS); + purge_obj_guess(arm_info,MAXARMORS); + purge_obj_guess(scr_info,MAXSCROLLS); + purge_obj_guess(weap_info,MAXWEAPONS + 1); + purge_obj_guess(ws_info,MAXSTICKS); + free_list(player._t._t_pack); + for (tp = mlist; tp != NULL; tp = next(tp)) + free_list(tp->t_pack); + free_list(mlist); + free_list(lvl_obj); + garbage_collect(); + + externs_clear(); + memset(d_list,0,sizeof(d_list)); + + memcpy(passages,origpassages,sizeof(passages)); + memcpy(monsters,origmonsters,sizeof(monsters)); + memcpy(things,origthings,sizeof(things)); + + memcpy(ring_info,origring_info,sizeof(ring_info)); + memcpy(pot_info,origpot_info,sizeof(pot_info)); + memcpy(arm_info,origarm_info,sizeof(arm_info)); + memcpy(scr_info,origscr_info,sizeof(scr_info)); + memcpy(weap_info,origweap_info,sizeof(weap_info)); + memcpy(ws_info,origws_info,sizeof(ws_info)); initscr(); /* Start up cursor package */ init_probs(); /* Set up prob tables for objects */ @@ -45,7 +83,8 @@ void rogueiterate(struct rogue_state *rs) my_exit(1); } // Set up windows - hw = newwin(LINES, COLS, 0, 0); + if ( hw == NULL ) + hw = newwin(LINES, COLS, 0, 0); idlok(stdscr, TRUE); idlok(hw, TRUE); #ifdef MASTER @@ -80,7 +119,7 @@ int32_t flushkeystrokes(struct rogue_state *rs) fclose(fp); if ( (fp= fopen("savefile","wb")) != 0 ) { - save_file(fp,0); + save_file(rs,fp,0); if ( 0 && (fp= fopen("savefile","rb")) != 0 ) { for (i=0; i<0x150; i++) @@ -145,11 +184,27 @@ int32_t rogue_replay(uint64_t seed,int32_t sleeptime) rs->seed = seed; rs->keystrokes = keystrokes; rs->numkeys = num; - rs->sleeptime = sleeptime; + rs->sleeptime = 1; + uint32_t starttime = (uint32_t)time(NULL); rogueiterate(rs); + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); + sleep(2); + + starttime = (uint32_t)time(NULL); + for (i=0; i<2000; i++) + { + memset(rs,0,sizeof(*rs)); + rs->seed = seed; + rs->keystrokes = keystrokes; + rs->numkeys = num; + rs->sleeptime = 0; + rogueiterate(rs); + } + fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL)-starttime); + sleep(1); if ( (fp= fopen("checkfile","wb")) != 0 ) { - save_file(fp,0); + save_file(rs,fp,0); if ( 0 && (fp= fopen("checkfile","rb")) != 0 ) { for (i=0; i<0x150; i++) @@ -160,7 +215,6 @@ int32_t rogue_replay(uint64_t seed,int32_t sleeptime) } free(rs); mvaddstr(LINES - 2, 0, (char *)"replay completed"); - refresh(); endwin(); } if ( keystrokes != 0 ) @@ -176,6 +230,7 @@ int rogue(int argc, char **argv, char **envp) rs->seed = atol(argv[1]); else rs->seed = 777; rs->guiflag = 1; + rs->sleeptime = 1; // non-zero to allow refresh() md_init(); #ifdef MASTER @@ -209,14 +264,14 @@ int rogue(int argc, char **argv, char **envp) lowtime = (int) time(NULL); #ifdef MASTER if (wizard && getenv("SEED") != NULL) - dnum = atoi(getenv("SEED")); + rs->seed = atoi(getenv("SEED")); else #endif - dnum = lowtime + md_getpid(); + //dnum = lowtime + md_getpid(); if ( rs != 0 ) seed = rs->seed; else seed = 777; - dnum = (int)seed; + //dnum = (int)seed; open_score(); @@ -242,8 +297,8 @@ int rogue(int argc, char **argv, char **envp) } else if (strcmp(argv[1], "-d") == 0) { - dnum = rnd(100); /* throw away some rnd()s to break patterns */ - while (--dnum) + rs->seed = rnd(100); /* throw away some rnd()s to break patterns */ + while (--rs->seed) rnd(100); purse = rnd(100) + 1; level = rnd(100) + 1; @@ -448,7 +503,8 @@ quit(int sig) clear(); mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse); move(LINES - 1, 0); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); score(purse, 1, 0); flushkeystrokes(rs); my_exit(0); @@ -459,7 +515,8 @@ quit(int sig) clrtoeol(); status(rs); move(oy, ox); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); mpos = 0; count = 0; to_death = FALSE; diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 3c500439c..e66362a10 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -313,19 +313,35 @@ /* * Now we define the structures and types */ +struct rogue_packitem +{ + int32_t type,launch,count,which,hplus,dplus,arm,flags,group; + char damage[8],hurldmg[8]; +}; + +struct rogue_player +{ + int32_t gold,hitpoints,strength,level,experience,packsize; + struct rogue_packitem roguepack[MAXPACK]; +}; + struct rogue_state { uint64_t seed; char *keystrokes; uint32_t needflush,replaydone; int32_t numkeys,ind,num,guiflag,counter,sleeptime; + struct rogue_player P; char buffered[512]; }; +extern struct rogue_state globalR; + int rogue(int argc, char **argv, char **envp); void rogueiterate(struct rogue_state *rs); int32_t roguefname(char *fname,uint64_t seed,int32_t counter); int32_t flushkeystrokes(struct rogue_state *rs); +int32_t rogue_restorepack(struct rogue_state *rs); /* * Help list @@ -476,6 +492,18 @@ struct monster { /* * External variables */ +extern const char *tr_name[],*inv_t_name[]; +extern const int32_t a_class[], e_levels[]; +extern const struct h_list helpstr[]; +extern const char *h_names[],*m_names[]; + + +extern const struct monster origmonsters[26]; +extern const struct room origpassages[MAXPASS]; +extern const struct obj_info origthings[NUMTHINGS],origring_info[MAXRINGS],origpot_info[MAXPOTIONS],origarm_info[MAXARMORS],origscr_info[MAXSCROLLS],origws_info[MAXSTICKS],origweap_info[MAXWEAPONS + 1]; +extern struct monster monsters[26]; +extern struct room passages[MAXPASS]; +extern struct obj_info things[NUMTHINGS],ring_info[MAXRINGS],pot_info[MAXPOTIONS],arm_info[MAXARMORS],scr_info[MAXSCROLLS],weap_info[MAXWEAPONS + 1],ws_info[MAXSTICKS]; extern bool after, again, allscore, amulet, door_stop, fight_flush, firstmove, has_hit, inv_describe, jump, kamikaze, @@ -483,19 +511,18 @@ extern bool after, again, allscore, amulet, door_stop, fight_flush, passgo, playing, q_comm, running, save_msg, see_floor, seenstairs, stat_msg, terse, to_death, tombstone; -extern char dir_ch, file_name[], home[], huh[], *inv_t_name[], +extern char dir_ch, file_name[], home[], huh[], l_last_comm, l_last_dir, last_comm, last_dir, *Numname, - outbuf[], *p_colors[], *r_stones[], *release, runch, - *s_names[], take, *tr_name[], *ws_made[], *ws_type[]; + outbuf[], *release, *s_names[], runch, take; +extern const char *ws_made[], *r_stones[], *p_colors[], *ws_type[]; -extern int a_class[], count, food_left, hungry_state, inpack, +extern int count, food_left, hungry_state, inpack, inv_type, lastscore, level, max_hit, max_level, mpos, n_objs, no_command, no_food, no_move, noscore, ntraps, purse, quiet, vf_hit; extern unsigned int numscores; -extern int dnum, e_levels[]; extern uint64_t seed; extern WINDOW *hw; @@ -507,16 +534,11 @@ extern PLACE places[]; extern THING *cur_armor, *cur_ring[], *cur_weapon, *l_last_pick, *last_pick, *lvl_obj, *mlist, player; -extern struct h_list helpstr[]; -extern struct room *oldrp, passages[], rooms[]; +extern struct room *oldrp, rooms[]; extern struct stats max_stats; -extern struct monster monsters[]; - -extern struct obj_info arm_info[], pot_info[], ring_info[], - scr_info[], things[], ws_info[], weap_info[]; /* * Function types @@ -617,7 +639,7 @@ void money(struct rogue_state *rs,int value); int move_monst(struct rogue_state *rs,THING *tp); void move_msg(struct rogue_state *rs,THING *obj); int msg(struct rogue_state *rs,char *fmt, ...); -void nameit(THING *obj, char *type, char *which, struct obj_info *op, char *(*prfunc)(THING *)); +void nameit(THING *obj, const char *type, const char *which, struct obj_info *op, char *(*prfunc)(THING *)); void new_level(struct rogue_state *rs); void new_monster(struct rogue_state *rs,THING *tp, char type, coord *cp); void numpass(int y, int x); @@ -651,12 +673,12 @@ void ring_off(struct rogue_state *rs); int rnd(int range); int rnd_room(void); int roll(int number, int sides); -int rs_save_file(FILE *savef); +int rs_save_file(struct rogue_state *rs,FILE *savef); int rs_restore_file(FILE *inf); void runto(struct rogue_state *rs,coord *runner); void rust_armor(struct rogue_state *rs,THING *arm); int save(int which); -void save_file(FILE *savef,int32_t guiflag); +void save_file(struct rogue_state *rs,FILE *savef,int32_t guiflag); void save_game(struct rogue_state *rs); int save_throw(int which, THING *tp); void score(int amount, int flags, char monst); @@ -778,13 +800,13 @@ extern int total; extern int between; extern int group; extern coord nh; -extern char *rainbow[]; +extern const char *rainbow[]; extern int cNCOLORS; -extern STONE stones[]; +extern const STONE stones[]; extern int cNSTONES; -extern char *wood[]; +extern const char *wood[]; extern int cNWOOD; -extern char *metal[]; +extern const char *metal[]; extern int cNMETAL; #endif diff --git a/src/cc/rogue/rooms.c b/src/cc/rogue/rooms.c index 1dcf3019a..31991b08f 100644 --- a/src/cc/rogue/rooms.c +++ b/src/cc/rogue/rooms.c @@ -37,7 +37,7 @@ do_rooms(struct rogue_state *rs) static coord top; coord bsze; /* maximum room size */ coord mp; - + bsze.x = NUMCOLS / 3; bsze.y = NUMLINES / 3; /* @@ -45,101 +45,101 @@ do_rooms(struct rogue_state *rs) */ for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) { - rp->r_goldval = 0; - rp->r_nexits = 0; - rp->r_flags = 0; + rp->r_goldval = 0; + rp->r_nexits = 0; + rp->r_flags = 0; } /* * Put the gone rooms, if any, on the level */ left_out = rnd(4); for (i = 0; i < left_out; i++) - rooms[rnd_room()].r_flags |= ISGONE; + rooms[rnd_room()].r_flags |= ISGONE; /* * dig and populate all the rooms on the level */ for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) { - /* - * Find upper left corner of box that this room goes in - */ - top.x = (i % 3) * bsze.x + 1; - top.y = (i / 3) * bsze.y; - if (rp->r_flags & ISGONE) - { - /* - * Place a gone room. Make certain that there is a blank line - * for passage drawing. - */ - do - { - rp->r_pos.x = top.x + rnd(bsze.x - 2) + 1; - rp->r_pos.y = top.y + rnd(bsze.y - 2) + 1; - rp->r_max.x = -NUMCOLS; - rp->r_max.y = -NUMLINES; - } until (rp->r_pos.y > 0 && rp->r_pos.y < NUMLINES-1); - continue; - } - /* - * set room type - */ - if (rnd(10) < level - 1) - { - rp->r_flags |= ISDARK; /* dark room */ - if (rnd(15) == 0) - rp->r_flags = ISMAZE; /* maze room */ - } - /* - * Find a place and size for a random room - */ - if (rp->r_flags & ISMAZE) - { - rp->r_max.x = bsze.x - 1; - rp->r_max.y = bsze.y - 1; - if ((rp->r_pos.x = top.x) == 1) - rp->r_pos.x = 0; - if ((rp->r_pos.y = top.y) == 0) - { - rp->r_pos.y++; - rp->r_max.y--; - } - } - else - do - { - rp->r_max.x = rnd(bsze.x - 4) + 4; - rp->r_max.y = rnd(bsze.y - 4) + 4; - rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); - rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); - } until (rp->r_pos.y != 0); - draw_room(rp); - /* - * Put the gold in - */ - if (rnd(2) == 0 && (!amulet || level >= max_level)) - { - THING *gold; - - gold = new_item(); - gold->o_goldval = rp->r_goldval = GOLDCALC; - find_floor(rp, &rp->r_gold, FALSE, FALSE); - gold->o_pos = rp->r_gold; - chat(rp->r_gold.y, rp->r_gold.x) = GOLD; - gold->o_flags = ISMANY; - gold->o_group = GOLDGRP; - gold->o_type = GOLD; - attach(lvl_obj, gold); - } - /* - * Put the monster in - */ - if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) - { - tp = new_item(); - find_floor(rp, &mp, FALSE, TRUE); - new_monster(rs,tp, randmonster(FALSE), &mp); - give_pack(rs,tp); - } + /* + * Find upper left corner of box that this room goes in + */ + top.x = (i % 3) * bsze.x + 1; + top.y = (i / 3) * bsze.y; + if (rp->r_flags & ISGONE) + { + /* + * Place a gone room. Make certain that there is a blank line + * for passage drawing. + */ + do + { + rp->r_pos.x = top.x + rnd(bsze.x - 2) + 1; + rp->r_pos.y = top.y + rnd(bsze.y - 2) + 1; + rp->r_max.x = -NUMCOLS; + rp->r_max.y = -NUMLINES; + } until (rp->r_pos.y > 0 && rp->r_pos.y < NUMLINES-1); + continue; + } + /* + * set room type + */ + if (rnd(10) < level - 1) + { + rp->r_flags |= ISDARK; /* dark room */ + if (rnd(15) == 0) + rp->r_flags = ISMAZE; /* maze room */ + } + /* + * Find a place and size for a random room + */ + if (rp->r_flags & ISMAZE) + { + rp->r_max.x = bsze.x - 1; + rp->r_max.y = bsze.y - 1; + if ((rp->r_pos.x = top.x) == 1) + rp->r_pos.x = 0; + if ((rp->r_pos.y = top.y) == 0) + { + rp->r_pos.y++; + rp->r_max.y--; + } + } + else + do + { + rp->r_max.x = rnd(bsze.x - 4) + 4; + rp->r_max.y = rnd(bsze.y - 4) + 4; + rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); + rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); + } until (rp->r_pos.y != 0); + draw_room(rp); + /* + * Put the gold in + */ + if (rnd(2) == 0 && (!amulet || level >= max_level)) + { + THING *gold; + + gold = new_item(); + gold->o_goldval = rp->r_goldval = GOLDCALC; + find_floor(rp, &rp->r_gold, FALSE, FALSE); + gold->o_pos = rp->r_gold; + chat(rp->r_gold.y, rp->r_gold.x) = GOLD; + gold->o_flags = ISMANY; + gold->o_group = GOLDGRP; + gold->o_type = GOLD; + attach(lvl_obj, gold); + } + /* + * Put the monster in + */ + if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) + { + tp = new_item(); + find_floor(rp, &mp, FALSE, TRUE); + new_monster(rs,tp, randmonster(FALSE), &mp); + give_pack(rs,tp); + } } } diff --git a/src/cc/rogue/save.c b/src/cc/rogue/save.c index 8dcb65194..eec85b930 100644 --- a/src/cc/rogue/save.c +++ b/src/cc/rogue/save.c @@ -64,7 +64,8 @@ over: if (c == 'y' || c == 'Y') { addstr("Yes\n"); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); strcpy(buf, file_name); goto gotfile; } @@ -109,7 +110,7 @@ gotfile: msg(rs,strerror(errno)); } while (savef == NULL); - save_file(savef,1); + save_file(rs,savef,1); /* NOTREACHED */ } @@ -128,7 +129,7 @@ auto_save(int sig) md_ignoreallsignals(); if (file_name[0] != '\0' && ((savef = fopen(file_name, "w")) != NULL || (md_unlink_open_file(file_name, savef) >= 0 && (savef = fopen(file_name, "w")) != NULL))) - save_file(savef,1); + save_file(&globalR,savef,1); exit(0); } @@ -137,10 +138,17 @@ auto_save(int sig) * Write the saved game on the file */ -void -save_file(FILE *savef,int32_t guiflag) +char *rogue_packfname(struct rogue_state *rs,char *fname) { - char buf[80]; + sprintf(fname,"rogue.%llu.pack",(long long)rs->seed); + return(fname); +} + +void +save_file(struct rogue_state *rs,FILE *savef,int32_t guiflag) +{ + char buf[80],fname[512]; int32_t i,n,nonz,histo[0x100]; FILE *fp; + memset(&rs->P,0,sizeof(rs->P)); mvcur(0, COLS - 1, LINES - 1, 0); putchar('\n'); endwin(); @@ -152,13 +160,53 @@ save_file(FILE *savef,int32_t guiflag) sprintf(buf,"%d x %d\n", LINES, COLS); encwrite(buf,80,savef); } - rs_save_file(savef); + rs_save_file(rs,savef); + n = sizeof(rs->P) - sizeof(rs->P.roguepack) + sizeof(rs->P.roguepack[0])*rs->P.packsize; + memset(histo,0,sizeof(histo)); + for (i=0; iP)[i]); + histo[((uint8_t *)&rs->P)[i]]++; + } + fprintf(stderr," packsize.%d n.%d\n",rs->P.packsize,n); + if ( (fp= fopen(rogue_packfname(rs,fname),"wb")) != 0 ) + { + fwrite(&rs->P,1,n,fp); + fclose(fp); + } + for (i=nonz=0; i<0x100; i++) + if ( histo[i] != 0 ) + fprintf(stderr,"(%d %d) ",i,histo[i]), nonz++; + fprintf(stderr,"nonz.%d\n",nonz); fflush(savef); fclose(savef); if ( guiflag != 0 ) exit(0); } +int32_t rogue_restorepack(struct rogue_state *rs) +{ + FILE *fp; char fname[512]; int32_t retflag = -1; + memset(&rs->P,0,sizeof(rs->P)); + if ( (fp= fopen(rogue_packfname(rs,fname),"rb")) != 0 ) + { + if ( fread(&rs->P,1,sizeof(rs->P) - sizeof(rs->P.roguepack),fp) == sizeof(rs->P) - sizeof(rs->P.roguepack) ) + { + if ( rs->P.packsize > 0 && rs->P.packsize <= MAXPACK ) + { + if ( fread(&rs->P.roguepack,1,rs->P.packsize*sizeof(rs->P.roguepack[0]),fp) == rs->P.packsize*sizeof(rs->P.roguepack[0]) ) + { + fprintf(stderr,"roguepack[%d] restored\n",rs->P.packsize); + retflag = 0; + } + } + } + } + if ( retflag < 0 ) + memset(&rs->P,0,sizeof(rs->P)); + return(retflag); +} + /* * restore: * Restore a saved game from a file with elaborate checks for file diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index f18ee1e5f..d99f1b0dc 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -97,7 +97,7 @@ rs_read(FILE *inf, void *ptr, size_t size) } int -rs_write_int(FILE *savef, int c) +rs_write_int(FILE *savef, int32_t c) { unsigned char bytes[4]; unsigned char *buf = (unsigned char *) &c; @@ -120,7 +120,7 @@ rs_write_int(FILE *savef, int c) } int -rs_read_int(FILE *inf, int *i) +rs_read_int(FILE *inf, int32_t *i) { unsigned char bytes[4]; int input = 0; @@ -198,7 +198,7 @@ rs_read_chars(FILE *inf, char *i, int count) } int -rs_write_ints(FILE *savef, int *c, int count) +rs_write_ints(FILE *savef, int32_t *c, int count) { int n = 0; @@ -215,7 +215,7 @@ rs_write_ints(FILE *savef, int *c, int count) } int -rs_read_ints(FILE *inf, int *i, int count) +rs_read_ints(FILE *inf, int32_t *i, int count) { int n, value; @@ -300,7 +300,7 @@ rs_read_booleans(FILE *inf, bool *i, int count) } int -rs_write_short(FILE *savef, short c) +rs_write_short(FILE *savef, int16_t c) { unsigned char bytes[2]; unsigned char *buf = (unsigned char *) &c; @@ -321,7 +321,7 @@ rs_write_short(FILE *savef, short c) } int -rs_read_short(FILE *inf, short *i) +rs_read_short(FILE *inf, int16_t *i) { unsigned char bytes[2]; short input; @@ -345,7 +345,7 @@ rs_read_short(FILE *inf, short *i) } int -rs_write_shorts(FILE *savef, short *c, int count) +rs_write_shorts(FILE *savef, int16_t *c, int count) { int n = 0; @@ -362,7 +362,7 @@ rs_write_shorts(FILE *savef, short *c, int count) } int -rs_read_shorts(FILE *inf, short *i, int count) +rs_read_shorts(FILE *inf, int16_t *i, int count) { int n = 0, value = 0; @@ -382,7 +382,7 @@ rs_read_shorts(FILE *inf, short *i, int count) } int -rs_write_ushort(FILE *savef, unsigned short c) +rs_write_ushort(FILE *savef, uint16_t c) { unsigned char bytes[2]; unsigned char *buf = (unsigned char *) &c; @@ -403,7 +403,7 @@ rs_write_ushort(FILE *savef, unsigned short c) } int -rs_read_ushort(FILE *inf, unsigned short *i) +rs_read_ushort(FILE *inf, uint16_t *i) { unsigned char bytes[2]; unsigned short input; @@ -427,7 +427,7 @@ rs_read_ushort(FILE *inf, unsigned short *i) } int -rs_write_uint(FILE *savef, unsigned int c) +rs_write_uint(FILE *savef, uint32_t c) { unsigned char bytes[4]; unsigned char *buf = (unsigned char *) &c; @@ -450,7 +450,7 @@ rs_write_uint(FILE *savef, unsigned int c) } int -rs_read_uint(FILE *inf, unsigned int *i) +rs_read_uint(FILE *inf, uint32_t *i) { unsigned char bytes[4]; int input; @@ -476,7 +476,7 @@ rs_read_uint(FILE *inf, unsigned int *i) } int -rs_write_marker(FILE *savef, int id) +rs_write_marker(FILE *savef, int32_t id) { if (write_error) return(WRITESTAT); @@ -487,7 +487,7 @@ rs_write_marker(FILE *savef, int id) } int -rs_read_marker(FILE *inf, int id) +rs_read_marker(FILE *inf, int32_t id) { int nid; @@ -891,7 +891,7 @@ rs_write_scrolls(FILE *savef) return(WRITESTAT); for(i = 0; i < MAXSCROLLS; i++) - rs_write_string(savef, s_names[i]); + rs_write_string(savef, (char *)s_names[i]); return(READSTAT); } @@ -905,7 +905,7 @@ rs_read_scrolls(FILE *inf) return(READSTAT); for(i = 0; i < MAXSCROLLS; i++) - rs_read_new_string(inf, &s_names[i]); + rs_read_new_string(inf, (char **)&s_names[i]); return(READSTAT); } @@ -919,7 +919,7 @@ rs_write_potions(FILE *savef) return(WRITESTAT); for(i = 0; i < MAXPOTIONS; i++) - rs_write_string_index(savef, rainbow, cNCOLORS, p_colors[i]); + rs_write_string_index(savef, (char **)rainbow, cNCOLORS, (char *)p_colors[i]); return(WRITESTAT); } @@ -933,7 +933,7 @@ rs_read_potions(FILE *inf) return(READSTAT); for(i = 0; i < MAXPOTIONS; i++) - rs_read_string_index(inf, rainbow, cNCOLORS, &p_colors[i]); + rs_read_string_index(inf, (char **)rainbow, cNCOLORS, (char **)&p_colors[i]); return(READSTAT); } @@ -947,7 +947,7 @@ rs_write_rings(FILE *savef) return(WRITESTAT); for(i = 0; i < MAXRINGS; i++) - rs_write_stone_index(savef, stones, cNSTONES, r_stones[i]); + rs_write_stone_index(savef, (STONE *)stones, cNSTONES, (char *)r_stones[i]); return(WRITESTAT); } @@ -961,7 +961,7 @@ rs_read_rings(FILE *inf) return(READSTAT); for(i = 0; i < MAXRINGS; i++) - rs_read_stone_index(inf, stones, cNSTONES, &r_stones[i]); + rs_read_stone_index(inf, (STONE *)stones, cNSTONES, (char **)&r_stones[i]); return(READSTAT); } @@ -979,12 +979,12 @@ rs_write_sticks(FILE *savef) if (strcmp(ws_type[i],"staff") == 0) { rs_write_int(savef,0); - rs_write_string_index(savef, wood, cNWOOD, ws_made[i]); + rs_write_string_index(savef, (char **)wood, cNWOOD, (char *)ws_made[i]); } else { rs_write_int(savef,1); - rs_write_string_index(savef, metal, cNMETAL, ws_made[i]); + rs_write_string_index(savef, (char **)metal, cNMETAL, (char *)ws_made[i]); } } @@ -1005,12 +1005,12 @@ rs_read_sticks(FILE *inf) if (list == 0) { - rs_read_string_index(inf, wood, cNWOOD, &ws_made[i]); + rs_read_string_index(inf, (char **)wood, cNWOOD, (char **)&ws_made[i]); ws_type[i] = "staff"; } else { - rs_read_string_index(inf, metal, cNMETAL, &ws_made[i]); + rs_read_string_index(inf, (char **)metal, cNMETAL, (char **)&ws_made[i]); ws_type[i] = "wand"; } } @@ -1336,13 +1336,65 @@ rs_read_monsters(FILE *inf, struct monster *m, int count) return(READSTAT); } -int -rs_write_object(FILE *savef, THING *o) +void rogue_restoreobject(THING *o,struct rogue_packitem *item) { + o->_o._o_type = item->type; + o->_o._o_launch = item->launch; + memcpy(o->_o._o_damage,item->damage,sizeof(item->damage)); + memcpy(o->_o._o_hurldmg,item->hurldmg,sizeof(item->hurldmg)); + o->_o._o_count = item->count; + o->_o._o_which = item->which; + o->_o._o_hplus = item->hplus; + o->_o._o_dplus = item->dplus; + o->_o._o_arm = item->arm; + o->_o._o_flags = item->flags; + o->_o._o_group = item->group; +} + +int32_t packsave(struct rogue_packitem *item,int32_t type,int32_t launch,char *damage,int32_t damagesize,char *hurldmg,int32_t hurlsize,int32_t count,int32_t which,int32_t hplus,int32_t dplus,int32_t arm,int32_t flags,int32_t group) +{ + if ( damagesize != 8 || hurlsize != 8 ) + { + fprintf(stderr,"unexpected damagesize.%d or hurlsize.%d != 8\n",damagesize,hurlsize); + return(-1); + } + item->type = type; + item->launch = launch; + memcpy(item->damage,damage,damagesize); + memcpy(item->hurldmg,hurldmg,hurlsize); + item->count = count; + item->which = which; + item->hplus = hplus; + item->dplus = dplus; + item->arm = arm; + item->flags = flags; + item->group = group; + return(0); +} + +int +rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) +{ + struct rogue_packitem *item; if (write_error) return(WRITESTAT); - //fprintf(stderr,"object %ld -> ",ftell(savef)); - + if ( o->_o._o_packch != 0 ) + { + item = &rs->P.roguepack[rs->P.packsize]; + if ( rs->P.packsize++ == 0 ) + { + rs->P.gold = purse; + rs->P.hitpoints = max_hp; + rs->P.strength = max_stats.s_str; + rs->P.level = pstats.s_lvl; + rs->P.experience = pstats.s_exp; + fprintf(stderr,"%ld gold.%d hp.%d strength.%d level.%d exp.%d\n",ftell(savef),purse,max_hp,max_stats.s_str,pstats.s_lvl,pstats.s_exp); + }; + fprintf(stderr,"object (%s) x.%d y.%d type.%d pack.(%c:%d)\n",inv_name(o,FALSE),o->_o._o_pos.x,o->_o._o_pos.y,o->_o._o_type,o->_o._o_packch,o->_o._o_packch); + if ( rs->P.packsize < MAXPACK ) + packsave(item,o->_o._o_type,o->_o._o_launch,o->_o._o_damage,sizeof(o->_o._o_damage),o->_o._o_hurldmg,sizeof(o->_o._o_hurldmg),o->_o._o_count,o->_o._o_which,o->_o._o_hplus,o->_o._o_dplus,o->_o._o_arm,o->_o._o_flags,o->_o._o_group); + } + rs_write_marker(savef, RSID_OBJECT); rs_write_int(savef, o->_o._o_type); rs_write_coord(savef, o->_o._o_pos); @@ -1358,7 +1410,6 @@ rs_write_object(FILE *savef, THING *o) rs_write_int(savef, o->_o._o_flags); rs_write_int(savef, o->_o._o_group); rs_write_string(savef, o->_o._o_label); - //fprintf(stderr,"%ld\n",ftell(savef)); return(WRITESTAT); } @@ -1388,7 +1439,7 @@ rs_read_object(FILE *inf, THING *o) } int -rs_write_object_list(FILE *savef, THING *l) +rs_write_object_list(struct rogue_state *rs,FILE *savef, THING *l) { if (write_error) return(WRITESTAT); @@ -1398,7 +1449,7 @@ rs_write_object_list(FILE *savef, THING *l) rs_write_int(savef, list_size(l)); for( ;l != NULL; l = l->l_next) - rs_write_object(savef, l); + rs_write_object(rs,savef, l); //fprintf(stderr,"%ld\n",ftell(savef)); return(WRITESTAT); @@ -1526,7 +1577,7 @@ find_object_coord(THING *objlist, coord *c) } int -rs_write_thing(FILE *savef, THING *t) +rs_write_thing(struct rogue_state *rs,FILE *savef, THING *t) { int i = -1; @@ -1610,7 +1661,7 @@ rs_write_thing(FILE *savef, THING *t) rs_write_short(savef, t->_t._t_flags); rs_write_stats(savef, &t->_t._t_stats); rs_write_room_reference(savef, t->_t._t_room); - rs_write_object_list(savef, t->_t._t_pack); + rs_write_object_list(rs,savef, t->_t._t_pack); //fprintf(stderr,"%ld\n",ftell(savef)); return(WRITESTAT); @@ -1712,7 +1763,7 @@ rs_fix_thing(THING *t) } int -rs_write_thing_list(FILE *savef, THING *l) +rs_write_thing_list(struct rogue_state *rs,FILE *savef, THING *l) { int cnt = 0; @@ -1729,7 +1780,7 @@ rs_write_thing_list(FILE *savef, THING *l) return(WRITESTAT); while (l != NULL) { - rs_write_thing(savef, l); + rs_write_thing(rs,savef, l); l = l->l_next; } @@ -1888,7 +1939,7 @@ rs_read_places(FILE *inf, PLACE *places, int count) } int -rs_save_file(FILE *savef) +rs_save_file(struct rogue_state *rs,FILE *savef) { if (write_error) return(WRITESTAT); @@ -1941,12 +1992,12 @@ rs_save_file(FILE *savef) rs_write_int(savef,orig_dsusp); rs_write_chars(savef, fruit, MAXSTR); //rs_write_chars(savef, home, MAXSTR); - rs_write_strings(savef,inv_t_name,3); + rs_write_strings(savef,(char **)inv_t_name,3); rs_write_char(savef,l_last_comm); rs_write_char(savef,l_last_dir); rs_write_char(savef,last_comm); rs_write_char(savef,last_dir); - rs_write_strings(savef,tr_name,8); + rs_write_strings(savef,(char **)tr_name,8); rs_write_int(savef,n_objs); rs_write_int(savef, ntraps); rs_write_int(savef, hungry_state); @@ -1956,7 +2007,7 @@ rs_save_file(FILE *savef) rs_write_int(savef, max_level); rs_write_int(savef, mpos); rs_write_int(savef, no_food); - rs_write_ints(savef,a_class,MAXARMORS); + rs_write_ints(savef,(int32_t *)a_class,MAXARMORS); rs_write_int(savef, count); rs_write_int(savef, food_left); rs_write_int(savef, lastscore); @@ -1968,11 +2019,11 @@ rs_save_file(FILE *savef) //rs_write_int(savef, dnum); rs_write_int(savef, (int32_t)(seed&0xffffffff)); rs_write_int(savef, (int32_t)((seed>>32)&0xffffffff)); - rs_write_ints(savef, e_levels, 21); + rs_write_ints(savef, (int32_t *)e_levels, 21); rs_write_coord(savef, delta); rs_write_coord(savef, oldpos); rs_write_coord(savef, stairs); - rs_write_thing(savef, &player); + rs_write_thing(rs,savef, &player); rs_write_object_reference(savef, player.t_pack, cur_armor); rs_write_object_reference(savef, player.t_pack, cur_ring[0]); rs_write_object_reference(savef, player.t_pack, cur_ring[1]); @@ -1980,8 +2031,8 @@ rs_save_file(FILE *savef) rs_write_object_reference(savef, player.t_pack, l_last_pick); rs_write_object_reference(savef, player.t_pack, last_pick); - rs_write_object_list(savef, lvl_obj); - rs_write_thing_list(savef, mlist); + rs_write_object_list(rs,savef, lvl_obj); + rs_write_thing_list(rs,savef, mlist); rs_write_places(savef,places,MAXLINES*MAXCOLS); @@ -2073,12 +2124,12 @@ rs_restore_file(FILE *inf) rs_read_int(inf,&orig_dsusp); rs_read_chars(inf, fruit, MAXSTR); //rs_read_chars(inf, home, MAXSTR); - rs_read_new_strings(inf,inv_t_name,3); + rs_read_new_strings(inf,(char **)inv_t_name,3); rs_read_char(inf, &l_last_comm); rs_read_char(inf, &l_last_dir); rs_read_char(inf, &last_comm); rs_read_char(inf, &last_dir); - rs_read_new_strings(inf,tr_name,8); + rs_read_new_strings(inf,(char **)tr_name,8); rs_read_int(inf, &n_objs); rs_read_int(inf, &ntraps); rs_read_int(inf, &hungry_state); @@ -2088,7 +2139,7 @@ rs_restore_file(FILE *inf) rs_read_int(inf, &max_level); rs_read_int(inf, &mpos); rs_read_int(inf, &no_food); - rs_read_ints(inf,a_class,MAXARMORS); + rs_read_ints(inf,(int32_t *)a_class,MAXARMORS); rs_read_int(inf, &count); rs_read_int(inf, &food_left); rs_read_int(inf, &lastscore); @@ -2102,7 +2153,7 @@ rs_restore_file(FILE *inf) rs_read_int(inf, &lownum); rs_read_int(inf, &highnum); seed = ((uint64_t)highnum<<32) | (lownum&0xffffffff); - rs_read_ints(inf,e_levels,21); + rs_read_ints(inf,(int32_t *)e_levels,21); rs_read_coord(inf, &delta); rs_read_coord(inf, &oldpos); rs_read_coord(inf, &stairs); diff --git a/src/cc/rogue/sticks.c b/src/cc/rogue/sticks.c index 7b01fe34c..7f9dc6ec2 100644 --- a/src/cc/rogue/sticks.c +++ b/src/cc/rogue/sticks.c @@ -405,7 +405,8 @@ def: msg(rs,"the %s whizzes by you", name); } mvaddch(pos.y, pos.x, dirch); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); } } for (c2 = spotpos; c2 < c1; c2++) diff --git a/src/cc/rogue/things.c b/src/cc/rogue/things.c index 2247c67e8..660e0720e 100644 --- a/src/cc/rogue/things.c +++ b/src/cc/rogue/things.c @@ -220,6 +220,7 @@ new_thing(struct rogue_state *rs) int r; cur = new_item(); + // 7th new_thing orphaned fprintf(stderr,"new_thing.%p\n",cur); cur->o_hplus = 0; cur->o_dplus = 0; strncpy(cur->o_damage, "0x0", sizeof(cur->o_damage)); @@ -499,7 +500,8 @@ add_line(struct rogue_state *rs,char *fmt, char *arg) if (inv_type == INV_OVER && fmt == NULL && !newpage) { msg(rs,""); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); tw = newwin(line_cnt + 1, maxlen + 2, 0, COLS - maxlen - 3); sw = subwin(tw, line_cnt + 1, maxlen + 1, 0, COLS - maxlen - 2); for (y = 0; y <= line_cnt; y++) @@ -615,7 +617,7 @@ nothing(char type) */ void -nameit(THING *obj, char *type, char *which, struct obj_info *op, +nameit(THING *obj, const char *type,const char *which, struct obj_info *op, char *(*prfunc)(THING *)) { char *pb; @@ -633,7 +635,7 @@ nameit(THING *obj, char *type, char *which, struct obj_info *op, sprintf(pb, "called %s%s(%s)", op->oi_guess, (*prfunc)(obj), which); } else if (obj->o_count == 1) - sprintf(prbuf, "A%s %s %s", vowelstr(which), which, type); + sprintf(prbuf, "A%s %s %s", vowelstr((char *)which), which, type); else sprintf(prbuf, "%d %s %ss", obj->o_count, which, type); } diff --git a/src/cc/rogue/weapons.c b/src/cc/rogue/weapons.c index 51a4b7730..6693f0814 100644 --- a/src/cc/rogue/weapons.c +++ b/src/cc/rogue/weapons.c @@ -105,7 +105,8 @@ do_motion(struct rogue_state *rs,THING *obj, int ydelta, int xdelta) if (cansee(rs,unc(obj->o_pos)) && !terse) { mvaddch(obj->o_pos.y, obj->o_pos.x, obj->o_type); - refresh(); + if ( rs->sleeptime != 0 ) + refresh(); } continue; } @@ -161,7 +162,6 @@ void init_weapon(THING *weap, int which) { struct init_weaps *iwp; - weap->o_type = WEAPON; weap->o_which = which; iwp = &init_dam[which]; diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 499b4d48c..b5538d87a 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -71,9 +71,9 @@ //////////////////////// start of CClib interface //./komodod -ac_name=ROGUE -ac_supply=1000000 -pubkey= -addnode=5.9.102.210 -ac_cclib=rogue -ac_perc=10000000 -ac_reward=100000000 -ac_cc=60001 -ac_script=2ea22c80203d1579313abe7d8ea85f48c65ea66fc512c878c0d0e6f6d54036669de940febf8103120c008203000401cc & -// cclib newgame 17 \"[maxplayers,buyin]\" +// cclib newgame 17 \"[3,100]\" // cclib pending 17 -// cclib txidinfo 17 \"[%2235e99df53c981a937bfa2ce7bfb303cea0249dba34831592c140d1cb729cb19f%22]\" +// cclib gameinfo 17 \"[%22783369750c2c7003d3dcee327b830025c560b594f65648c0abbac733a661ea39%22]\" // ./rogue gui -> creates keystroke files // cclib register 17 \"[%2235e99df53c981a937bfa2ce7bfb303cea0249dba34831592c140d1cb729cb19f%22,%22%22]\" // cclib keystrokes 17 \"[]\" @@ -452,8 +452,7 @@ UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param if ( n > 0 ) { UniValue pobj(UniValue::VOBJ); - t = jbits256(jitem(params,0),0); - memcpy(&playertxid,&t,sizeof(playertxid));; + playertxid = juint256(jitem(params,0)); if ( rogue_playerdata(cp,origplayergame,pk,playerdata,playertxid) < 0 ) return(cclib_error(result,"invalid playerdata")); result.push_back(Pair("rogue",rogue_playerobj(pobj,playerdata))); @@ -481,14 +480,12 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { if ( n > 0 ) { - t = jbits256(jitem(params,0),0); - memcpy(&gametxid,&t,sizeof(gametxid)); + gametxid = juint256(jitem(params,0)); if ( rogue_isvalidgame(cp,tx,buyin,maxplayers,gametxid) == 0 ) { if ( n > 1 && maxplayers > 1 ) { - t = jbits256(jitem(params,0),0); - memcpy(&playertxid,&t,sizeof(playertxid)); + playertxid = juint256(jitem(params,1)); if ( rogue_playerdata(cp,origplayergame,pk,playerdata,playertxid) < 0 ) return(cclib_error(result,"couldnt extract valid playerdata")); } @@ -522,8 +519,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param rogue_univalue(result,"keystrokes",-1,-1); if ( (params= cclib_reparse(&n,params)) != 0 && n == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) { - t = jbits256(jitem(params,0),0); - memcpy(&gametxid,&t,sizeof(gametxid)); + gametxid = juint256(jitem(params,0)); keystrokes = ParseHex(keystrokestr); mypk = pubkey2pk(Mypubkey()); roguepk = GetUnspendable(cp,0); @@ -588,8 +584,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { if ( n > 0 ) { - t = jbits256(jitem(params,0),0); - memcpy(&txid,&t,sizeof(txid)); + txid = juint256(jitem(params,0)); result.push_back(Pair("txid",txid.GetHex())); if ( rogue_isvalidgame(cp,tx,buyin,maxplayers,txid) == 0 ) {