void rawwriteimage( FILE *raw, psd_file_t psd, struct layer_info *li, struct channel_info *chan, int chancount, struct psd_header *h) { psd_pixels_t j; unsigned char *inrow, *rlebuf; int i; rlebuf = checkmalloc(chan->rowbytes*2); inrow = checkmalloc(chan->rowbytes); // write channels in a series of planes, not interleaved for(i = 0; i < chancount; ++i){ UNQUIET("## rawwriteimage: channel %d\n", i); for(j = 0; j < chan[i].rows; ++j){ /* get row data */ readunpackrow(psd, chan, j, inrow, rlebuf); if((psd_pixels_t)fwrite(inrow, 1, chan[i].rowbytes, raw) != chan->rowbytes){ alwayswarn("# error writing raw data, aborting\n"); goto err; } } } err: fclose(raw); free(rlebuf); free(inrow); }
/* makes a log npc for houses and hovels */ void make_house_npc(int i, int j) { pml ml = ((pml) checkmalloc(sizeof(mltype))); pob ob; ml->m = ((pmt) checkmalloc(sizeof(montype))); *(ml->m) = Monsters[NPC]; make_log_npc(ml->m); if (ml->m->id == NPC) mprint("You detect signs of life in this house."); else mprint("An eerie shiver runs down your spine as you enter...."); /* if not == NPC, then we got a ghost off the npc list */ ml->m->x = i; ml->m->y = j; Level->site[i][j].creature = ml->m; ml->m->click = (Tick + 1) % 50; ml->next = Level->mlist; Level->mlist = ml; m_status_set(ml->m,HOSTILE); if (nighttime()) m_status_reset(ml->m,AWAKE); else m_status_set(ml->m,AWAKE); if (ml->m->startthing > -1) { ob = ((pob) checkmalloc(sizeof(objtype))); *ob = Objects[ml->m->startthing]; m_pickup(ml->m,ob); } }
void cavern_level(void) { int i,fx,fy,tx,ty,t,l,e; char rsi; Level->numrooms = 1; if ((Current_Dungeon == E_CAVES) && (Level->depth == CAVELEVELS)) rsi = RS_GOBLINKING; else rsi = RS_CAVERN; t = random_range((Level->level_length)/2); l = random_range((Level->level_width)/2); e = random_range((Level->level_width)/8)+(Level->level_width)/8; build_square_room(t,l,e,rsi,0); for (i=0; i<16; i++) { findspace(&tx,&ty,-1); fx = random_range((Level->level_width)-2)+1; fy = random_range((Level->level_length)-2)+1; straggle_corridor(fx,fy,tx,ty,FLOOR,RS_CORRIDOR); } while (random_range(3)==1) { findspace(&tx,&ty,-1); fx = random_range((Level->level_width)-2)+1; fy = random_range((Level->level_length)-2)+1; straggle_corridor(fx,fy,tx,ty,WATER,RS_PONDS); } if (Current_Dungeon == E_CAVES) { if ((Level->depth == CAVELEVELS) && (State.getCompletedCaves() == false)) { findspace(&tx,&ty,-1); Level->mlist = ((MonsterList*) checkmalloc(sizeof(MonsterList))); Level->mlist->next = NULL; Level->mlist->monster = Level->site[tx][ty].creature = ((Monster*) make_creature(GOBLIN_KING)); /* goblin king */ Level->mlist->monster->x = tx; Level->mlist->monster->y = ty; } } else if (Current_Environment == E_VOLCANO) { if (Level->depth == VOLCANOLEVELS) { findspace(&tx,&ty,-1); Level->mlist = ((MonsterList*) checkmalloc(sizeof(MonsterList))); Level->mlist->next = NULL; Level->mlist->monster = Level->site[tx][ty].creature = ((Monster*) make_creature(DEMON_EMP)); /* The demon emp */ Level->mlist->monster->x = tx; Level->mlist->monster->y = ty; } } }
/* makes a hiscore npc for mansions */ void make_justiciar(int i, int j) { pml ml = ((pml) checkmalloc(sizeof(mltype))); ml->m = ((pmt) checkmalloc(sizeof(montype))); *(ml->m) = Monsters[NPC]; make_hiscore_npc(ml->m,15); ml->m->x = i; ml->m->y = j; Level->site[i][j].creature = ml->m; ml->m->click = (Tick + 1) % 60; ml->next = Level->mlist; Level->mlist = ml; m_status_reset(ml->m,AWAKE); }
/* make a random new object, returning pointer */ Object* create_object(int itemlevel) { Object* newObject; int r; int ok = false; while (! ok) { newObject = ((Object*) checkmalloc(sizeof(Object))); r= random_range(135); if (r < 20) make_thing(newObject,-1); else if (r < 40) make_food(newObject,-1); else if (r < 50) make_scroll(newObject,-1); else if (r < 60) make_potion(newObject,-1); else if (r < 70) make_weapon(newObject,-1); else if (r < 80) make_armor(newObject,-1); else if (r < 90) make_shield(newObject,-1); else if (r < 100) make_stick(newObject,-1); else if (r < 110) make_boots(newObject,-1); else if (r < 120) make_cloak(newObject,-1); else if (r < 130) make_ring(newObject,-1); else make_artifact(newObject,-1); /* not ok if object is too good for level, or if unique and already made */ /* 1/100 chance of finding object if too good for level */ ok = ((newObject->uniqueness < UNIQUE_MADE) && ((newObject->level < itemlevel+random_range(3)) || (random_range(100)==23))); if (!ok) { free_obj( newObject, true ); } } if (newObject->uniqueness == UNIQUE_UNMADE) Objects[newObject->id].uniqueness=UNIQUE_MADE; return(newObject); }
static long doirb(psd_file_t f){ static struct dictentry resource = {0, NULL, "RESOURCE", "dummy", NULL}; char type[4], name[0x100]; int id, namelen; long size; size_t padded_size; struct dictentry *d; fread(type, 1, 4, f); id = get2B(f); namelen = fgetc(f); fread(name, 1, PAD2(1+namelen)-1, f); name[namelen] = 0; size = get4B(f); padded_size = PAD2(size); d = findbyid(id); if((verbose || print_rsrc || resdump) && !xmlout){ printf(" resource '%c%c%c%c' (%5d,\"%s\"):%5ld bytes", type[0],type[1],type[2],type[3], id, name, size); if(d) printf(" [%s]", d->desc); putchar('\n'); } if(d && d->tag){ if(xml){ fprintf(xml, "\t<RESOURCE TYPE='%c%c%c%c' ID='%d'", type[0],type[1],type[2],type[3], id); if(namelen) fprintf(xml, " NAME='%s'", name); } if(d->func){ if(xml) fputs(">\n", xml); entertag(f, 2, size, &resource, d, 1); if(xml) fputs("\t</RESOURCE>\n\n", xml); } else if(xml){ fputs(" /> <!-- not parsed -->\n", xml); } } if(resdump){ char *temp_buf = checkmalloc(padded_size); if(fread(temp_buf, 1, padded_size, f) < padded_size) fatal("did not read expected bytes in image resource\n"); dumphex((unsigned char*)temp_buf, size); putchar('\n'); free(temp_buf); } else fseeko(f, padded_size, SEEK_CUR); // skip resource block data return 4+2+PAD2(1+namelen)+4+padded_size; /* returns total bytes in block */ }
/* makes a hiscore npc for mansions */ void make_mansion_npc(int i, int j) { pml ml = ((pml) checkmalloc(sizeof(mltype))); ml->m = ((pmt) checkmalloc(sizeof(montype))); *(ml->m) = Monsters[NPC]; make_hiscore_npc(ml->m,random_range(14) + 1); mprint("You detect signs of life in this house."); ml->m->x = i; ml->m->y = j; Level->site[i][j].creature = ml->m; ml->m->click = (Tick + 1) % 50; ml->next = Level->mlist; Level->mlist = ml; m_status_set(ml->m,HOSTILE); if (nighttime()) m_status_reset(ml->m,AWAKE); else m_status_set(ml->m,AWAKE); }
void sewer_level(void) { int i,tx,ty,t,l,e; char rsi; Symbol lchar; Level->numrooms = random_range(3)+3; rsi = RS_DRAINED_SEWER; for (i=0; i<Level->numrooms; i++) { do { t = random_range((Level->level_length)-10)+1; l = random_range((Level->level_width)-10)+1; e = 4; } while ((Level->site[l][t].roomnumber == rsi) || (Level->site[l+e][t].roomnumber == rsi) || (Level->site[l][t+e].roomnumber == rsi) || (Level->site[l+e][t+e].roomnumber == rsi)); if (random_range(5)) { lchar = FLOOR; rsi = RS_DRAINED_SEWER; } else { lchar = WATER; rsi = RS_DROWNED_SEWER; } build_room(l,t,e,rsi,i); sewer_corridor(l,t,-1,-1,lchar); sewer_corridor(l+e,t,1,-1,lchar); sewer_corridor(l,t+e,-1,1,lchar); sewer_corridor(l+e,t+e,1,1,lchar); } if (Current_Dungeon == E_SEWERS) { if ((Level->depth == SEWERLEVELS) && (State.getCompletedSewers() == false)) { findspace(&tx,&ty,-1); Level->mlist = ((MonsterList*) checkmalloc(sizeof(MonsterList))); Level->mlist->next = NULL; Level->mlist->monster = Level->site[tx][ty].creature = ((Monster*) make_creature(GREAT_WYRM)); /* The Great Wyrm */ Level->mlist->monster->x = tx; Level->mlist->monster->y = ty; } } }
void dolayerinfo(psd_file_t f, struct psd_header *h){ int i; // layers structure h->nlayers = get2B(f); h->mergedalpha = h->nlayers < 0; if(h->mergedalpha){ h->nlayers = - h->nlayers; VERBOSE(" (first alpha is transparency for merged image)\n"); } UNQUIET("\n%d layers:\n", h->nlayers); //if( h->nlayers*(18+6*h->channels) > layerlen ){ // sanity check // alwayswarn("### unlikely number of layers, giving up.\n"); // return; //} h->linfo = checkmalloc(h->nlayers*sizeof(struct layer_info)); // load linfo[] array with each layer's info for(i = 0; i < h->nlayers; ++i) readlayerinfo(f, h, i); }
/* Has all kinds of effects in different circumstances. Eventually will be more interesting */ void s_ritual(void) { pob symbol; int i,roomno; int x,y; mprint("You begin your ritual...."); mprint("You enter a deep trance. Time Passes..."); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); if (RitualHour == hour()) mprint("Your mental fatigue prevents from completing the ritual!"); else if (random_range(100) > Player.iq+Player.pow+Player.level) mprint("Your concentration was broken -- the ritual fails!"); else { mprint("You charge the ritual with magical energy and focus your will."); mprint("Time Passes..."); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); setgamestatus(SKIP_PLAYER); time_clock(FALSE); RitualHour = hour(); /* set of random conditions for different ritual effects */ if (Current_Environment == E_CITY) { mprint("Flowing waves of mystical light congeal all around you."); mprint("'Like wow, man! Colors!'"); mprint("Appreciative citizens throw you spare change."); Player.cash +=random_range(50); } else if ( (roomno=Level->site[Player.x][Player.y].roomnumber) >= ROOMBASE ) { if (RitualRoom == roomno) mprint("For some reason the ritual doesn't work this time..."); else { RitualRoom = roomno; switch (RitualRoom) { case RS_TREASURE: /* ransacked treasure chamber */ mprint("Your spell sets off frenetic growth all around you!"); for(i=0; i<8; i++) { Level->site[Player.x+Dirs[0][i]][Player.y+Dirs[1][i]].locchar = HEDGE; Level->site[Player.x+Dirs[0][i]][Player.y+Dirs[1][i]].p_locf = L_TRIFID; lset(Player.x+Dirs[0][i], Player.y+Dirs[1][i], CHANGED); } break; case RS_HAREM: /* harem */ case RS_BOUDOIR: /* boudoir */ mprint("A secret panel opens next to the bed...."); if (random_range(2)) summon(0,INCUBUS); /* succubus/incubus */ else summon(0,SATYR); /* satyr/nymph */ break; case RS_SHRINE: /*shrine to high magic */ mprint("A storm of mana coaelesces around you."); mprint("You are buffeted by bursts of random magic."); p_damage(random_range(Player.pow),UNSTOPPABLE,"high magic"); mprint("Continue ritual? Could be dangerous.... [yn] "); if (ynq()=='y') s_wish(); else mprint("The mana fades away to nothingness."); x = Player.x; y = Player.y; while (x >= 0 && Level->site[x - 1][y].roomnumber == RS_SHRINE) x--; while (y >= 0 && Level->site[x][y - 1].roomnumber == RS_SHRINE) y--; for (i = 0; Level->site[x][y].roomnumber == RS_SHRINE;) { Level->site[x][y].roomnumber = RS_ZORCH; lset(x, y, CHANGED); x++; i++; if (Level->site[x][y].roomnumber != RS_SHRINE) { x -= i; i = 0; y++; } } break; case RS_MAGIC_LAB: /* magician's lab */ mprint("Your magical activity sets off a latent spell in the lab!"); cast_spell(random_range(NUMSPELLS)); break; case RS_PENTAGRAM: /* pentagram room */ mprint("A smoky form begins to coalesce...."); summon(-1,-1); mprint("Fortunately, it seems confined to the pentagram."); m_status_reset(Level->mlist->m,MOBILE); break; case RS_OMEGA_DAIS: /* blue omega room */ mprint("The Lords of Destiny look upon you...."); if (Player.level > 10) { mprint("A curtain of blue flames leaps up from the omega."); morewait(); l_adept(); } else { if (Player.patron == DESTINY) { mprint("Your patrons take pity on you."); if ((Player.rank[PRIESTHOOD]<SPRIEST) && (! find_item(&symbol,OB_SYMBOL_DESTINY,-1))) { symbol = ((pob) checkmalloc(sizeof(objtype))); *symbol = Objects[OB_SYMBOL_DESTINY]; symbol->known = 2; symbol->charge = 17; gain_item(symbol); mprint("You feel uplifted."); } else gain_experience(min(1000,Player.xp)); } else if (random_range(3)==1) { mprint("You feel Fated."); gain_experience(Player.level*Player.level*10); Player.hp = max(Player.hp, Player.maxhp); } else if (random_range(2)) { mprint("You feel Doomed."); Player.hp = 1; Player.mana = 0; Player.xp = 0; } else mprint("The Lords of Destiny laugh at you!"); } break; default: mprint("Well, not much effect. Chalk it up to experience."); gain_experience(Player.level*5); break; } } } else { if (RitualRoom == Level->site[Player.x][Player.y].roomnumber) mprint("The ritual fails for some unexplainable reason."); else { mprint("The ritual seems to be generating some spell effect."); RitualRoom = Level->site[Player.x][Player.y].roomnumber; switch (RitualRoom) { case RS_WALLSPACE: shadowform(); break; case RS_CORRIDOR: haste(0); break; case RS_PONDS: breathe(0); break; case RS_ADEPT: hero(1); break; default: mprint("The ritual doesn't seem to produce any tangible results..."); gain_experience(Player.level*6); } } } } }
/* loads the house level into Level*/ void load_house(int kind, int populate) { map *home; int i,j; char site; int stops; TempLevel = Level; initrand(Current_Environment, Player.x + Player.y + hour()*10); if (ok_to_free(TempLevel)) { #ifndef SAVE_LEVELS free_level(TempLevel); #endif TempLevel = NULL; } #ifndef SAVE_LEVELS Level = ((plv) checkmalloc(sizeof(levtype))); #else msdos_changelevel(TempLevel,0,-1); Level = &TheLevel; #endif clear_level(Level); switch(kind) { case E_HOUSE: home = map_open(MAP_house); break; case E_MANSION: home = map_open(MAP_mansion); break; default: case E_HOVEL: home = map_open(MAP_hovel); break; } Level->level_width=map_getWidth(home); Level->level_length=map_getLength(home); map_setLevel(home, 0); stops = 0; for(j=0;j<Level->level_length;j++) { for(i=0;i<Level->level_width;i++) { if (kind == E_HOVEL) Level->site[i][j].lstatus = SEEN; else Level->site[i][j].lstatus = 0; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].p_locf = L_NO_OP; site = map_getSiteChar(home,i,j); switch(site) { case 'N': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; if (random_range(2) && populate) make_house_npc(i,j); break; case 'H': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; if (random_range(2) && populate) make_mansion_npc(i,j); break; case 'D': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_DININGROOM; break; case '.': Level->site[i][j].locchar = FLOOR; if (stops) { lset(i,j,STOPS); stops = 0; } break; case 'c': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CLOSET; break; case 'G': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BATHROOM; break; case 'B': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_BEDROOM; break; case 'K': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_KITCHEN; break; case 'S': Level->site[i][j].locchar = FLOOR; Level->site[i][j].showchar = WALL; lset(i,j,SECRET); Level->site[i][j].roomnumber = RS_SECRETPASSAGE; break; case '3': Level->site[i][j].locchar = SAFE; Level->site[i][j].showchar = WALL; lset(i,j,SECRET); Level->site[i][j].p_locf = L_SAFE; break; case '^': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS); break; case 'P': Level->site[i][j].locchar = PORTCULLIS; Level->site[i][j].p_locf = L_PORTCULLIS; break; case 'R': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_RAISE_PORTCULLIS; break; case 'p': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS; break; case 'T': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS_TRAP; break; case 'X': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_HOUSE_EXIT; stops = 1; break; case '#': Level->site[i][j].locchar = WALL; switch (kind) { case E_HOVEL: Level->site[i][j].aux = 10; break; case E_HOUSE: Level->site[i][j].aux = 50; break; case E_MANSION: Level->site[i][j].aux = 150; break; } break; case '|': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; lset(i,j,STOPS); break; case '+': Level->site[i][j].locchar = CLOSED_DOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].aux = LOCKED; lset(i,j,STOPS); break; case 'd': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; if (populate) make_site_monster(i,j,DOBERMAN); break; case 'a': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; Level->site[i][j].p_locf = L_TRAP_SIREN; break; case 'A': Level->site[i][j].locchar = FLOOR; Level->site[i][j].roomnumber = RS_CORRIDOR; if (populate) make_site_monster(i,j,AUTO_MINOR); /* automaton */ break; } Level->site[i][j].showchar = ' '; } } map_close(home); initrand(E_RESTORE, 0); }
/* loads the city level */ void load_city(int populate) { int i,j; pml ml; char site; map *city; map *maze; initrand(E_CITY, 0); /* Get the hedge maze (which is in the city). */ maze = map_open(MAP_hedges); /* Choose a random level from it. */ map_setLevel(maze, random_range(map_getDepth(maze))); /* Get the city. */ city = map_open(MAP_city); map_setLevel(city,0); TempLevel = Level; if (ok_to_free(TempLevel)) { #ifndef SAVE_LEVELS free_level(TempLevel); #endif TempLevel = NULL; } #ifndef SAVE_LEVELS Level = ((plv) checkmalloc(sizeof(levtype))); #else msdos_changelevel(TempLevel,0,-1); Level = &TheLevel; #endif clear_level(Level); Level->depth = 0; Level->environment = E_CITY; /* WDT: Rampart, as a special case, has its width stored in a * global variable. */ WIDTH = Level->level_width = map_getWidth(city); LENGTH = Level->level_length = map_getLength(city); for(j=0; j<Level->level_length; j++) { for(i=0; i<Level->level_width; i++) { lset(i,j,SEEN); site = map_getSiteChar(city,i,j); switch(site) { /* case '@': Player.x = i; Player.y = j; Level->site[i][j].locchar = FLOOR; break; */ case 'g': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_GARDEN; break; case 'y': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_CEMETARY; break; case 'p': /* WDT: each of these places needs to be assigned * a function (or replaced with an 'x' in the map) */ case '!': case 'I': case 'E': case 'e': case 'x': assign_city_function(i,j); break; case 't': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_TEMPLE; CitySiteList[L_TEMPLE-CITYSITEBASE][0] = TRUE; CitySiteList[L_TEMPLE-CITYSITEBASE][1] = i; CitySiteList[L_TEMPLE-CITYSITEBASE][2] = j; break; #if 0 /* WDT: HACK! The new city doesn't use portcullis traps, but has other * uses for 'T'. Um... I'd rather have a use for them (that's what * the jail is supposed to be), so this will stay only for now; with * any luck we'll have things fixed up before the next release. */ case 'T': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS_TRAP; Level->site[i][j].aux = NOCITYMOVE; break; #endif /* end of hack */ case 'R': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_RAISE_PORTCULLIS; Level->site[i][j].aux = NOCITYMOVE; break; case '7': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_PORTCULLIS; Level->site[i][j].aux = NOCITYMOVE; break; case 'C': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_COLLEGE; CitySiteList[L_COLLEGE-CITYSITEBASE][0] = TRUE; CitySiteList[L_COLLEGE-CITYSITEBASE][1] = i; CitySiteList[L_COLLEGE-CITYSITEBASE][2] = j; break; case 's': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_SORCERORS; CitySiteList[L_SORCERORS-CITYSITEBASE][0] = TRUE; CitySiteList[L_SORCERORS-CITYSITEBASE][1] = i; CitySiteList[L_SORCERORS-CITYSITEBASE][2] = j; break; case 'M': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_MERC_GUILD; CitySiteList[L_MERC_GUILD-CITYSITEBASE][0] = TRUE; CitySiteList[L_MERC_GUILD-CITYSITEBASE][1] = i; CitySiteList[L_MERC_GUILD-CITYSITEBASE][2] = j; break; case 'K': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_MONASTERY; CitySiteList[L_MONASTERY-CITYSITEBASE][0] = TRUE; CitySiteList[L_MONASTERY-CITYSITEBASE][1] = i; CitySiteList[L_MONASTERY-CITYSITEBASE][2] = j; break; case 'c': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_CASTLE; CitySiteList[L_CASTLE-CITYSITEBASE][0] = TRUE; CitySiteList[L_CASTLE-CITYSITEBASE][1] = i; CitySiteList[L_CASTLE-CITYSITEBASE][2] = j; break; case '?': { static int myI = -1, myJ; char site; if ( myI == -1 ) { /* If this is the first time we've seen the hedge maze, * set this as its corner. */ myI = i; myJ = j; } site = map_getSiteChar(maze, i - myI, j - myJ); mazesite(site,i,j,populate); } break; case 'P': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_ORDER; CitySiteList[L_ORDER-CITYSITEBASE][0] = TRUE; CitySiteList[L_ORDER-CITYSITEBASE][1] = i; CitySiteList[L_ORDER-CITYSITEBASE][2] = j; break; case 'H': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_CHARITY; CitySiteList[L_CHARITY-CITYSITEBASE][0] = TRUE; CitySiteList[L_CHARITY-CITYSITEBASE][1] = i; CitySiteList[L_CHARITY-CITYSITEBASE][2] = j; break; case 'h': Level->site[i][j].locchar = FLOOR; if (populate) make_horse(i,j); /* from village.c */ break; case 'j': Level->site[i][j].locchar = FLOOR; if (populate) make_justiciar(i,j); break; case 'J': Level->site[i][j].locchar = CLOSED_DOOR; Level->site[i][j].p_locf = L_JAIL; break; case 'A': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_ARENA; CitySiteList[L_ARENA-CITYSITEBASE][0] = TRUE; CitySiteList[L_ARENA-CITYSITEBASE][1] = i; CitySiteList[L_ARENA-CITYSITEBASE][2] = j; break; case 'B': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_BANK; CitySiteList[L_BANK-CITYSITEBASE][0] = TRUE; CitySiteList[L_BANK-CITYSITEBASE][1] = i; CitySiteList[L_BANK-CITYSITEBASE][2] = j; lset(i,j,STOPS); lset(i,j+1,STOPS); lset(i+1,j,STOPS); lset(i-1,j,STOPS); lset(i,j-1,STOPS); break; case 'i': Level->site[i][j].locchar = OPEN_DOOR; Level->site[i][j].p_locf = L_TOURIST; CitySiteList[L_TOURIST-CITYSITEBASE][1] = i; CitySiteList[L_TOURIST-CITYSITEBASE][2] = j; lset(i,j,STOPS); lset(i,j+1,STOPS); lset(i+1,j,STOPS); lset(i-1,j,STOPS); lset(i,j-1,STOPS); break; case 'X': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_COUNTRYSIDE; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][0] = TRUE; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][1] = i; CitySiteList[L_COUNTRYSIDE-CITYSITEBASE][2] = j; break; case 'v': Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_VAULT; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case 'S': Level->site[i][j].locchar = FLOOR; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case 'G': Level->site[i][j].locchar = FLOOR; if (populate) { make_site_monster(i,j,GUARD); Level->site[i][j].creature->aux1 = i; Level->site[i][j].creature->aux2 = j; } break; case 'u': Level->site[i][j].locchar = FLOOR; if (populate) make_minor_undead(i,j); break; case 'U': Level->site[i][j].locchar = FLOOR; if (populate) make_major_undead(i,j); break; case 'V': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_VAULT; if (populate) make_site_treasure(i,j,5); Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '%': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = L_TRAP_SIREN; if (populate) make_site_treasure(i,j,5); Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '$': Level->site[i][j].locchar = FLOOR; if (populate) make_site_treasure(i,j,5); break; case '2': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = ODIN; break; case '3': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = SET; break; case '4': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = ATHENA; break; case '5': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = HECATE; break; case '6': Level->site[i][j].locchar = ALTAR; Level->site[i][j].p_locf = L_ALTAR; Level->site[i][j].aux = DESTINY; break; case '^': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].p_locf = TRAP_BASE+random_range(NUMTRAPS); lset(i,j,SECRET); break; case '"': Level->site[i][j].locchar = HEDGE; break; case '~': Level->site[i][j].locchar = WATER; Level->site[i][j].p_locf = L_WATER; break; case '=': Level->site[i][j].locchar = WATER; Level->site[i][j].p_locf = L_MAGIC_POOL; break; case '*': Level->site[i][j].locchar = WALL; Level->site[i][j].aux = 10; break; case '#': Level->site[i][j].locchar = WALL; Level->site[i][j].aux = 500; break; case 'T':/* currently meaningless in large city map. */ case '>': /* currently meaningless outside of maze.*/ case '.': Level->site[i][j].locchar = FLOOR; break; case ',': Level->site[i][j].showchar = WALL; Level->site[i][j].locchar = FLOOR; Level->site[i][j].aux = NOCITYMOVE; lset(i,j,SECRET); break; case '-': case 'D': /* WDT: should all Ds be changed to -, or should D be given * special treatment? */ Level->site[i][j].locchar = CLOSED_DOOR; break; case '1': Level->site[i][j].locchar = STATUE; break; default: printf("\nOops... missed a case [%d,%d]: '%c' (%d)\n", i,j,site,site); morewait(); } if (loc_statusp(i,j,SEEN)) { if (loc_statusp(i,j,SECRET)) Level->site[i][j].showchar = WALL; else Level->site[i][j].showchar = Level->site[i][j].locchar; } } } map_close(maze); map_close(city); City = Level; /* make all city monsters asleep, and shorten their wakeup range to 2 */ /* to prevent players from being molested by vicious monsters on */ /* the streets */ for(ml=Level->mlist; ml!=NULL; ml=ml->next) { m_status_reset(ml->m,AWAKE); ml->m->wakeup = 2; } initrand(E_RESTORE, 0); }
/* [SS] 2013-04-10 */ void read_custom_stress_file (char *filename) { FILE *inhandle; char name[32]; char meter[6]; char str[4]; int index; int nseg, nval; int gain; float expand; char **p; int i, j; init_stresspat (); inhandle = fopen (filename, "r"); if (inhandle == NULL) { printf ("Failed to open file %s\n", filename); exit (1); } if (verbose > 0) printf("reading %s\n",filename); while (!feof (inhandle)) { if (feof (inhandle)) break; j = fscanf (inhandle, "%s", &name); if (j == -1) break; j = fscanf (inhandle, "%s", &meter); index = stress_locator (&name[0], &meter[0]); if (verbose > 1) printf ("%s %s index = %d\n",name,meter,index); j = fscanf (inhandle, "%d %d", &nseg, &nval); if (verbose > 2) printf ("j = %d nseg = %d nval = %d\n", j, nseg, nval); if (j != 2) exit(-1); if (nval > 16) { printf("stresspat.c: nval = %d is too large for structure %s\n",nval,name); exit(-1); } /* copy model to stresspat[] */ if (index <0) { /*creating new model, must include name and meter */ index = nmodels; if (index > 47) { printf ("used up all available space for stress models\n"); return; } nmodels++; stresspat[index].name = (char *) checkmalloc ((strlen (name) + 1) * sizeof (char)); stresspat[index].meter = (char *) checkmalloc ((strlen (meter) + 1) * sizeof (char)); stresspat[index].name = name; stresspat[index].meter = meter; } stresspat[index].nseg = nseg; stresspat[index].nval = nval; for (i = 0; i < nval; i++) { j = fscanf (inhandle, "%d %f", &gain, &expand); if(verbose > 2) printf ("%d %f\n", gain, expand); if (j != 2) exit(1); if (feof (inhandle)) break; } fgets (str, 3, inhandle); } }
/* gain for an item */ void acquire(int blessing) { char otype; int index,id = ABORT; pob newthing; if (blessing < 0) { index = random_item(); if (index == ABORT) mprint("You feel fortunate."); else { print1("Smoke drifts out of your pack.... "); print2("Destroyed: "); nprint2(itemid(Player.possessions[index])); morewait(); dispose_lost_objects(1,Player.possessions[index]); } } else { newthing = ((pob) checkmalloc(sizeof(objtype))); /* DAG this assignment looks unneccessary */ newthing->id = -1; if (gamestatusp(CHEATED)) print1("Acquire which kind of item: !?][}{)/=%%\\& "); else print1("Acquire which kind of item: !?][}{)/=%%\\ "); otype = mgetc(); switch (otype) { case (POTION&0xff): if (blessing > 0) id = itemlist(POTIONID,NUMPOTIONS); else id = random_range(NUMPOTIONS); if (id < 0) print2("You feel stupid."); else make_potion(newthing,id); break; case (SCROLL&0xff): if (blessing > 0) id = itemlist(SCROLLID,NUMSCROLLS); else id = random_range(NUMSCROLLS); if (id < 0) print2("You feel stupid."); else make_scroll(newthing,id); break; case (RING&0xff): if (blessing > 0) id = itemlist(RINGID,NUMRINGS); else id = random_range(NUMRINGS); if (id < 0) print2("You feel stupid."); else make_ring(newthing,id); break; case (STICK&0xff): if (blessing > 0) id = itemlist(STICKID,NUMSTICKS); else id = random_range(NUMSTICKS); if (id < 0) print2("You feel stupid."); else make_stick(newthing,id); break; case (ARMOR&0xff): if (blessing > 0) id = itemlist(ARMORID,NUMARMOR); else id = random_range(NUMARMOR); if (id < 0) print2("You feel stupid."); else make_armor(newthing,id); break; case (SHIELD&0xff): if (blessing > 0) id = itemlist(SHIELDID,NUMSHIELDS); else id = random_range(NUMSHIELDS); if (id < 0) print2("You feel stupid."); else make_shield(newthing,id); break; case (WEAPON&0xff): if (blessing > 0) id = itemlist(WEAPONID,NUMWEAPONS); else id = random_range(NUMWEAPONS); if (id < 0) print2("You feel stupid."); else make_weapon(newthing,id); break; case (BOOTS&0xff): if (blessing > 0) id = itemlist(BOOTID,NUMBOOTS); else id = random_range(NUMBOOTS); if (id < 0) print2("You feel stupid."); else make_boots(newthing,id); break; case (CLOAK&0xff): if (blessing > 0) id = itemlist(CLOAKID,NUMCLOAKS); else id = random_range(NUMCLOAKS); if (id < 0) print2("You feel stupid."); else make_cloak(newthing,id); break; case (FOOD&0xff): if (blessing > 0) id = itemlist(FOODID,NUMFOODS); else id = random_range(NUMFOODS); if (id < 0) print2("You feel stupid."); else make_food(newthing,id); break; case (THING&0xff): if (blessing > 0) id = itemlist(THINGID,NUMTHINGS); else id = random_range(NUMTHINGS); if (id < 0) print2("You feel stupid."); else make_thing(newthing,id); break; case (ARTIFACT&0xff): if (gamestatusp(CHEATED)) id = itemlist(ARTIFACTID,NUMARTIFACTS); else id = -1; if (id < 0) print2("You feel stupid."); else make_artifact(newthing,id); break; default: print2("You feel stupid."); } xredraw(); if (id != ABORT) { if (blessing > 0) { newthing->known = 2; Objects[id].known = 1; } newthing->used = FALSE; gain_item(newthing); } else { /* DAG newthing allocated but was not freed... was YA memory leak */ /* use free() rather than free_obj() since newthing not initialized */ free( (char *) newthing ); } } }
void l_order(void) { pob newitem; pml ml; print1("The Headquarters of the Order of Paladins."); morewait(); if ((Player.rank[ORDER]==PALADIN) && (Player.level > Justiciarlevel) && gamestatusp(GAVE_STARGEM) && Player.alignment > 300) { print1("You have succeeded in your quest!"); morewait(); print1("The previous Justiciar steps down in your favor."); print2("You are now the Justiciar of Rampart and the Order!"); strcpy(Justiciar,Player.name); for (ml = Level->mlist; ml && (ml->m->id != HISCORE_NPC || ml->m->aux2 != 15); ml = ml->next) /* just scan for current Justicar */; if (ml) { m_remove(ml->m); /* signals "death" -- no credit to player, though */ } Justiciarlevel = Player.level; morewait(); Justiciarbehavior = fixnpc(4); save_hiscore_npc(15); clearmsg(); print1("You are awarded a blessed shield of deflection!"); morewait(); newitem = ((pob) checkmalloc(sizeof(objtype))); *newitem = Objects[OB_DEFLECT]; /* shield of deflection */ newitem->blessing = 9; gain_item(newitem); morewait(); Player.rank[ORDER] = JUSTICIAR; Player.maxstr += 5; Player.str += 5; Player.maxpow += 5; Player.pow += 5; } if (Player.alignment < 1) { if (Player.rank[ORDER] > 0) { print1("You have been tainted by chaos!"); print2("You are stripped of your rank in the Order!"); morewait(); Player.rank[ORDER]= -1; send_to_jail(); } else print1("Get thee hence, minion of chaos!"); } else if (Player.rank[ORDER] == -1) print1("Thou again? Get thee hence, minion of chaos!"); else if (Player.rank[ORDER] == 0) { if (Player.rank[ARENA] != 0) print1("We do not accept bloodstained gladiators into our Order."); else if (Player.rank[LEGION] != 0) print1("Go back to your barracks, mercenary!"); else { print1("Dost thou wish to join our Order? [yn] "); if (ynq1()=='y') { print1("Justiciar "); nprint1(Justiciar); nprint1(" welcomes you to the Order."); print2("'Mayest thou always follow the sublime path of Law.'"); morewait(); print1("You are now a Gallant in the Order."); print2("You are given a horse and a blessed spear."); morewait(); Player.rank[ORDER] = GALLANT; Player.guildxp[ORDER] = 1; setgamestatus(MOUNTED); newitem = ((pob) checkmalloc(sizeof(objtype))); *newitem = Objects[OB_SPEAR]; /* spear */ newitem->blessing = 9; newitem->plus = 1; newitem->known = 2; gain_item(newitem); } } } else { print1("'Welcome back, Paladin.'"); if (!gamestatusp(MOUNTED)) { print2("You are given a new steed."); setgamestatus(MOUNTED); } morewait(); clearmsg(); if ((Player.hp < Player.maxhp) || (Player.status[DISEASED]) || (Player.status[POISONED])) print1("Your wounds are treated by a medic."); cleanse(0); Player.hp = Player.maxhp; if ( Player.food <= 40 ) { Player.food = 40; print2("You get a hot meal from the refectory."); } morewait(); clearmsg(); if (Player.rank[ORDER]==PALADIN) { if (Player.level <= Justiciarlevel) print2("You are not experienced enough to advance."); else if (Player.alignment < 300) print2("You are not sufficiently Lawful as yet to advance."); else print2("You must give the Star Gem to the LawBringer."); } else if (Player.rank[ORDER]==CHEVALIER) { if (Player.guildxp[ORDER] < 4000) print2("You are not experienced enough to advance."); else if (Player.alignment < 200) print2("You are not sufficiently Lawful as yet to advance."); else { print1("You are made a Paladin of the Order!"); print2("You learn the Spell of Heroism and get Mithril Plate!"); morewait(); newitem = ((pob) checkmalloc(sizeof(objtype))); *newitem = Objects[OB_MITHRIL_PLATE]; /* mithril plate armor */ newitem->blessing = 9; newitem->known = 2; gain_item(newitem); morewait(); clearmsg(); print1("To advance you must rescue the Star Gem and return it"); print2("to its owner, the LawBringer, who resides on Star Peak."); morewait(); print1("The Star Gem was stolen by the cursed Prime Sorceror,"); print2("whose headquarters may be found beyond the Astral Plane."); morewait(); print1("The Oracle will send you to the Astral Plane if you"); print2("prove yourself worthy to her."); morewait(); Spells[S_HERO].known = TRUE; Player.rank[ORDER] = PALADIN; } } else if (Player.rank[ORDER]==GUARDIAN) { if (Player.guildxp[ORDER] < 1500) print2("You are not experienced enough to advance."); else if (Player.alignment < 125) print2("You are not yet sufficiently Lawful to advance."); else { Player.rank[ORDER] = CHEVALIER; print1("You are made a Chevalier of the Order!"); print2("You are given a Mace of Disruption!"); morewait(); clearmsg(); newitem = ((pob) checkmalloc(sizeof(objtype))); *newitem = Objects[OB_MACE_DISRUPT]; /* mace of disruption */ newitem->known = 2; gain_item(newitem); } } else if (Player.rank[ORDER]==GALLANT) { if (Player.guildxp[ORDER] < 400) print2("You are not experienced enough to advance."); else if (Player.alignment < 50) print2("You are not Lawful enough to advance."); else { print1("You are made a Guardian of the Order of Paladins!"); print2("You are given a Holy Hand Grenade (of Antioch)."); morewait(); print1("You hear a nasal monotone in the distance...."); print2("'...and the number of thy counting shall be 3...'"); morewait(); clearmsg(); Player.rank[ORDER] = GUARDIAN; newitem = ((pob) checkmalloc(sizeof(objtype))); *newitem = Objects[OB_ANTIOCH]; /* holy hand grenade. */ newitem->known = 2; gain_item(newitem); } } } showflags(); }
void l_thieves_guild(void) { int fee,count,i,number,done=FALSE,dues=1000; char c,action; pob lockpick; print1("You have penetrated to the Lair of the Thieves' Guild."); if (! nighttime()) print2("There aren't any thieves around in the daytime."); else { if ((Player.rank[THIEVES]==TMASTER) && (Player.level > Shadowlordlevel) && find_and_remove_item(OB_JUSTICIAR_BADGE,-1)) { print2("You nicked the Justiciar's Badge!"); morewait(); print1("The Badge is put in a place of honor in the Guild Hall."); print2("You are now the Shadowlord of the Thieves' Guild!"); morewait(); print1("Who says there's no honor among thieves?"); strcpy(Shadowlord,Player.name); Shadowlordlevel = Player.level; morewait(); Shadowlordbehavior = fixnpc(4); save_hiscore_npc(7); clearmsg(); print1("You learn the Spell of Shadowform."); Spells[S_SHADOWFORM].known = TRUE; morewait(); clearmsg(); Player.rank[THIEVES]=SHADOWLORD; Player.maxagi += 2; Player.maxdex += 2; Player.agi += 2; Player.dex += 2; } while (! done) { menuclear(); if (Player.rank[THIEVES] == 0) menuprint("a: Join the Thieves' Guild.\n"); else menuprint("b: Raise your Guild rank.\n"); menuprint("c: Get an item identified.\n"); if (Player.rank[THIEVES] > 0) menuprint("d: Fence an item.\n"); menuprint("ESCAPE: Leave this Den of Iniquity."); showmenu(); action = mgetc(); if (action == ESCAPE) done = TRUE; else if (action == 'a') { done = TRUE; if (Player.rank[THIEVES]> 0) print2("You are already a member!"); else if (Player.alignment > 10) print2("You are too lawful to be a thief!"); else { dues += dues*(12-Player.dex)/9; dues += Player.alignment*5; dues = max(100,dues); clearmsg(); mprint("Dues are"); mnumprint(dues); mprint(" Au. Pay it? [yn] "); if (ynq1() =='y') { if (Player.cash < dues) { print1("You can't cheat the Thieves' Guild!"); print2("... but the Thieves' Guild can cheat you...."); Player.cash = 0; } else { print1("Shadowlord "); nprint1(Shadowlord); print2("enters your name into the roll of the Guild."); morewait(); clearmsg(); print1("As a special bonus, you get a free lockpick."); print2("You are taught the spell of Object Detection."); morewait(); Spells[S_OBJ_DET].known = TRUE; lockpick = ((pob) checkmalloc(sizeof(objtype))); *lockpick = Objects[OB_LOCK_PICK]; /* lock pick */ gain_item(lockpick); Player.cash -= dues; dataprint(); Player.guildxp[THIEVES]=1; Player.rank[THIEVES]=TMEMBER; Player.maxdex++;Player.dex++;Player.agi++;Player.maxagi++; } } } } else if (action == 'b') { if (Player.rank[THIEVES]==0) print2("You are not even a member!"); else if (Player.rank[THIEVES]==SHADOWLORD) print2("You can't get any higher than this!"); else if (Player.rank[THIEVES]==TMASTER) { if (Player.level <= Shadowlordlevel) print2("You are not experienced enough to advance."); else print2("You must bring back the Justiciar's Badge!"); } else if (Player.rank[THIEVES]==THIEF) { if (Player.guildxp[THIEVES] < 4000) print2("You are not experienced enough to advance."); else { print1("You are now a Master Thief of the Guild!"); print2("You are taught the Spell of Apportation."); morewait(); print1("To advance to the next level you must return with"); print2("the badge of the Justiciar (cursed be his name)."); morewait(); clearmsg(); print1("The Justiciar's office is just south of the gaol."); Spells[S_APPORT].known = TRUE; Player.rank[THIEVES]=TMASTER; Player.maxagi++; Player.maxdex++; Player.agi++; Player.dex++; } } else if (Player.rank[THIEVES]==ATHIEF) { if (Player.guildxp[THIEVES] < 1500) print2("You are not experienced enough to advance."); else { print1("You are now a ranking Thief of the Guild!"); print2("You learn the Spell of Invisibility."); Spells[S_INVISIBLE].known = TRUE; Player.rank[THIEVES]=THIEF; Player.agi++; Player.maxagi++; } } else if (Player.rank[THIEVES]==TMEMBER) { if (Player.guildxp[THIEVES] < 400) print2("You are not experienced enough to advance."); else { print1("You are now an Apprentice Thief!"); print2("You are taught the Spell of Levitation."); Spells[S_LEVITATE].known = TRUE; Player.rank[THIEVES]=ATHIEF; Player.dex++; Player.maxdex++; } } } else if (action == 'c') { if (Player.rank[THIEVES]==0) { print1("RTG, Inc, Appraisers. Identification Fee: 50Au/item."); fee = 50; } else { fee = 5; print1("The fee is 5Au per item."); } print2("Identify one item, or all possessions? [ip] "); if ((char) mcigetc()=='i') { if (Player.cash < fee) print2("Try again when you have the cash."); else { Player.cash -= fee; dataprint(); identify(0); } } else { count = 0; for(i=1;i<MAXITEMS;i++) if (Player.possessions[i] != NULL) if (Player.possessions[i]->known < 2) count++; for(i=0;i<Player.packptr;i++) if (Player.pack[i] != NULL) if (Player.pack[i]->known < 2) count++; clearmsg(); print1("The fee will be: "); mnumprint(max(count*fee,fee)); nprint1("Au. Pay it? [yn] "); if (ynq1()=='y') { if (Player.cash < max(count*fee,fee)) print2("Try again when you have the cash."); else { Player.cash -= max(count*fee,fee); dataprint(); identify(1); } } } } else if (action == 'd') { if (Player.rank[THIEVES]==0) print2("Fence? Who said anything about a fence?"); else { print1("Fence one item or go through pack? [ip] "); if ((char) mcigetc()=='i') { i = getitem(NULL_ITEM); if ((i==ABORT) || (Player.possessions[i] == NULL)) print2("Huh, Is this some kind of set-up?"); else if (Player.possessions[i]->blessing < 0) print2("I don't want to buy a cursed item!"); else { clearmsg(); print1("I'll give you "); mlongprint(2 * item_value(Player.possessions[i]) / 3); nprint1("Au each. OK? [yn] "); if (ynq1() == 'y') { number = getnumber(Player.possessions[i]->number); if ((number >= Player.possessions[i]->number) && Player.possessions[i]->used) { Player.possessions[i]->used = FALSE; item_use(Player.possessions[i]); } Player.cash += number*2*item_value(Player.possessions[i])/3; /* Fenced artifacts could turn up anywhere, really... */ if (Objects[Player.possessions[i]->id].uniqueness > UNIQUE_UNMADE) Objects[Player.possessions[i]->id].uniqueness = UNIQUE_UNMADE; dispose_lost_objects(number,Player.possessions[i]); dataprint(); } else print2("Hey, gimme a break, it was a fair price!"); } } else { for(i=0;i<Player.packptr;i++) { if (Player.pack[i]->blessing > -1) { clearmsg(); print1("Sell "); nprint1(itemid(Player.pack[i])); nprint1(" for "); mlongprint(2*item_value(Player.pack[i])/3); nprint1("Au each? [ynq] "); if ((c=ynq1())=='y') { number = getnumber(Player.pack[i]->number); Player.cash += 2*number * item_value(Player.pack[i]) / 3; Player.pack[i]->number -= number; if (Player.pack[i]->number < 1) { /* Fenced an artifact? You just might see it again. */ if (Objects[Player.pack[i]->id].uniqueness > UNIQUE_UNMADE) Objects[Player.pack[i]->id].uniqueness = UNIQUE_UNMADE; free((char *)Player.pack[i]); Player.pack[i] = NULL; } dataprint(); } else if (c=='q') break; } } fixpack(); } } } } } xredraw(); }
void readlayerinfo(psd_file_t f, struct psd_header *h, int i) { psd_bytes_t extralen, extrastart; int j, chid, namelen; char *chidstr, tmp[10]; struct layer_info *li = h->linfo + i; // process layer record li->top = get4B(f); li->left = get4B(f); li->bottom = get4B(f); li->right = get4B(f); li->channels = get2Bu(f); VERBOSE("\n"); UNQUIET(" layer %d: (%4d,%4d,%4d,%4d), %d channels (%4d rows x %4d cols)\n", i, li->top, li->left, li->bottom, li->right, li->channels, li->bottom-li->top, li->right-li->left); if( li->bottom < li->top || li->right < li->left || li->channels > 64 ) // sanity check { alwayswarn("### something's not right about that, trying to skip layer.\n"); fseeko(f, 6*li->channels+12, SEEK_CUR); skipblock(f, "layer info: extra data"); li->chan = NULL; li->chindex = NULL; li->nameno = li->name = li->unicode_name = NULL; } else { li->chan = checkmalloc(li->channels*sizeof(struct channel_info)); li->chindex = checkmalloc((li->channels+3)*sizeof(int)); li->chindex += 3; // so we can index array from [-3] (hackish) for(j = -3; j < li->channels; ++j) li->chindex[j] = -1; // fetch info on each of the layer's channels for(j = 0; j < li->channels; ++j){ li->chan[j].id = chid = get2B(f); li->chan[j].length = GETPSDBYTES(f); li->chan[j].rawpos = 0; li->chan[j].rowpos = NULL; li->chan[j].unzipdata = NULL; if(chid >= -3 && chid < li->channels) li->chindex[chid] = j; else warn_msg("unexpected channel id %d", chid); switch(chid){ case UMASK_CHAN_ID: chidstr = " (user layer mask)"; break; case LMASK_CHAN_ID: chidstr = " (layer mask)"; break; case TRANS_CHAN_ID: chidstr = " (transparency mask)"; break; default: if(h->mode != SCAVENGE_MODE && chid < (int)strlen(channelsuffixes[h->mode])) sprintf(chidstr = tmp, " (%c)", channelsuffixes[h->mode][chid]); // it's a mode-ish channel else chidstr = ""; // don't know } VERBOSE(" channel %2d: " LL_L("%7lld","%7ld") " bytes, id=%2d %s\n", j, li->chan[j].length, chid, chidstr); } fread(li->blend.sig, 1, 4, f); fread(li->blend.key, 1, 4, f); li->blend.opacity = fgetc(f); li->blend.clipping = fgetc(f); li->blend.flags = fgetc(f); fgetc(f); // padding // process layer's 'extra data' section extralen = get4B(f); extrastart = ftello(f); VERBOSE(" (extra data: " LL_L("%lld","%ld") " bytes @ " LL_L("%lld","%ld") ")\n", extralen, extrastart); // fetch layer mask data li->mask.size = get4B(f); if(li->mask.size >= 20){ off_t skip = li->mask.size; VERBOSE(" (has layer mask)\n"); li->mask.top = get4B(f); li->mask.left = get4B(f); li->mask.bottom = get4B(f); li->mask.right = get4B(f); li->mask.default_colour = fgetc(f); li->mask.flags = fgetc(f); skip -= 18; if(li->mask.size >= 36){ VERBOSE(" (has user layer mask)\n"); li->mask.real_flags = fgetc(f); li->mask.real_default_colour = fgetc(f); li->mask.real_top = get4B(f); li->mask.real_left = get4B(f); li->mask.real_bottom = get4B(f); li->mask.real_right = get4B(f); skip -= 18; } fseeko(f, skip, SEEK_CUR); // skip remainder }else VERBOSE(" (no layer mask)\n"); skipblock(f, "layer blending ranges"); // layer name li->nameno = checkmalloc(16); sprintf(li->nameno, "layer%d", i+1); namelen = fgetc(f); li->name = checkmalloc(PAD4(namelen+1)); fread(li->name, 1, PAD4(namelen+1)-1, f); li->name[namelen] = 0; if(namelen) UNQUIET(" name: \"%s\"\n", li->name); // process layer's 'additional info' li->additionalpos = ftello(f); li->additionallen = extrastart + extralen - li->additionalpos; // leave file positioned after extra data fseeko(f, extrastart + extralen, SEEK_SET); } }
void l_condo(void) { pol ol,prev=NULL; int i,done=FALSE,over=FALSE,weeksleep=FALSE; char response; if (! gamestatusp(SOLD_CONDO)) { response = cinema_interact ("rp","Rampart Arms. Weekly Condo Rentals and Purchases", "Which are you interested in [r,p, or ESCAPE] ", NULL); if (response == 'p') { print2("Only 50,000Au. Buy it? [yn] "); if (ynq2()=='y') { if (Player.cash < 50000) print3("No mortgages, buddy."); else { setgamestatus(SOLD_CONDO); Player.cash-=50000; dataprint(); print2("You are the proud owner of a luxurious condo penthouse."); Condoitems = NULL; } } } else if (response == 'r') { print2("Weekly Rental, 1000Au. Pay for it? [yn] "); if (ynq2()=='y') { if (Player.cash < 1000) print2("Hey, pay the rent or out you go...."); else { weeksleep = TRUE; Player.cash -=1000; dataprint(); } } } else print2("Please keep us in mind for your housing needs."); } else { while (! done) { menuclear(); menuprint("Home Sweet Home\n"); menuprint("a: Leave items in your safe.\n"); menuprint("b: Retrieve items.\n"); menuprint("c: Take a week off to rest.\n"); menuprint("d: Retire permanently.\n"); menuprint("ESCAPE: Leave this place.\n"); showmenu(); response = (char) mcigetc(); if (response == 'a') { i = getitem(NULL_ITEM); if (i != ABORT) { if (Player.possessions[i]->blessing < 0) print2("The item just doesn't want to be stored away..."); else { ol = ((pol) checkmalloc(sizeof(oltype))); ol->thing = Player.possessions[i]; ol->next = Condoitems; Condoitems = ol; conform_unused_object(Player.possessions[i]); Player.possessions[i] = NULL; } } } else if (response == 'b') { ol = Condoitems; while ((ol != NULL) && (! over)) { print1("Retrieve "); nprint1(itemid(ol->thing)); nprint1(" [ynq] "); response = (char) mcigetc(); /* DAG -- fix memory leak where object list nodes weren't deleted */ if (response == 'y') { gain_item(ol->thing); if (ol == Condoitems) { ol = ol->next; free( Condoitems ); Condoitems = ol; } else { ol=ol->next; free( prev->next ); prev->next = ol; } } else if (response == 'q') over = TRUE; else { prev = ol; ol = ol->next; } } } else if (response == 'c') { weeksleep = TRUE; print1("You take a week off to rest..."); morewait(); } else if (response == 'd') { clearmsg(); if (cinema_confirm("You ponder settling down here for good.") == 'y') { p_win(); } } else if (response == ESCAPE) done = TRUE; } xredraw(); } if (weeksleep) { clearmsg(); print1("Taking a week off to rest..."); morewait(); toggle_item_use(TRUE); Player.hp = Player.maxhp; Player.str = Player.maxstr; Player.agi = Player.maxagi; Player.con = Player.maxcon; Player.dex = Player.maxdex; Player.iq = Player.maxiq; Player.pow = Player.maxpow; for (i=0; i<NUMSTATI; i++) if (Player.status[i]<1000) Player.status[i]=0; toggle_item_use(FALSE); Player.food = 36; print2("You're once again fit and ready to continue your adventure."); Time += 60*24*7; Date += 7; moon_check(); timeprint(); } }
void l_merc_guild(void) { print1("Legion of Destiny, Mercenary Guild, Inc."); if (nighttime()) { print2("The barracks are under curfew right now."); return; } print2("You enter Legion HQ, "); if (Player.rank[LEGION] == COMMANDANT) { nprint2("Your aide follows you to the staff room."); morewait(); clearmsg(); } else if (Player.rank[LEGION] > 0) { nprint2("and report to your commander."); morewait(); } switch (Player.rank[LEGION]) { case 0: nprint2("and see the Recruiting Centurion."); morewait(); print2("Do you wish to join the Legion? [yn] "); if ('y' == ynq2()) { clearmsg(); if (Player.rank[ARENA] > 0) { print1("The Centurion checks your record, and gets angry:"); print2("'The legion don't need any Arena Jocks. Git!'"); } else if (Player.rank[ORDER] > 0) { print1("The Centurion checks your record, and is amused:"); print2("'A paladin in the ranks? You must be joking.'"); } else if (Player.con < 12) { print1("The Centurion looks you over, sadly."); print2("You are too fragile to join the legion."); } else if (Player.str < 10) { print1("The Centurion looks at you contemptuously."); print2("Your strength is too low to pass the physical!"); } else { Object* newitem; bank_account * account; print1("You are tested for strength and stamina..."); morewait(); nprint1(" and you pass!"); print2("Commandant "); nprint2(Commandant); nprint2(" shakes your hand."); morewait(); print1("You are also issued a shortsword and leather."); print2("You are now a Legionaire."); morewait(); clearmsg(); /* gain shortsword */ newitem = (Object*) checkmalloc(sizeof(Object)); *newitem = Objects[OB_SHORT_SWORD]; gain_item(newitem); /* gain leather armor */ newitem = (Object*) checkmalloc(sizeof(Object)); *newitem = Objects[OB_LEATHER]; gain_item(newitem); cinema_scene("Your starting salary will be 500 AU per month paid into an account the", "legion has set up for you. The password is \"loyalty\". Don't lose your card!", 0); /* gain bank card for salary account */ account = bank_create_account(true, 0, "loyalty"); account->balance = 500; Objects[OB_DEBIT_CARD].known = 1; newitem = bank_create_card(account->number, OB_DEBIT_CARD); gain_item(newitem); clearmsg(); SalaryAmount = 500; SalaryAccount = account->number; Player.rank[LEGION] = LEGIONAIRE; Player.guildxp[LEGION] = 1; Player.str++; Player.con++; Player.maxstr++; Player.maxcon++; } } break; case COMMANDANT: print1("You find the disposition of your forces satisfactory."); break; case COLONEL: if ((Player.level > Commandantlevel) && find_and_remove_item(CORPSEID, DEMON_EMP)) { print1("You liberated the Demon Emperor's Regalia!"); morewait(); clearmsg(); print1("The Legion is assembled in salute to you!"); print2("The Regalia is held high for all to see and admire."); morewait(); clearmsg(); print1("Commandant "); nprint1(Commandant); nprint1(" promotes you to replace him,"); print2("and announces his own overdue retirement."); morewait(); clearmsg(); print1("You are the new Commandant of the Legion!"); print2("The Emperor's Regalia is sold for a ridiculous sum."); morewait(); clearmsg(); print1("You now know the Spell of Regeneration."); print2("Your training is complete. You get top salary."); strcpy(Commandant, Player.name); Commandantlevel = Player.level; Commandantbehavior = fixnpc(4); save_hiscore_npc(8); Spells[S_REGENERATE].known = true; Player.rank[LEGION] = COMMANDANT; Player.str += 2; Player.con += 2; Player.maxstr += 2; Player.maxcon += 2; SalaryAmount = 10000; } else if (Player.level <= Commandantlevel) { clearmsg(); print1("Your CO expresses satisfaction with your progress."); print2("But your service record does not yet permit promotion."); } else { clearmsg(); print1("Why do you come empty handed?"); print2("You must return with the Regalia of the Demon Emperor!"); } break; case FORCE_LEADER: clearmsg(); print1("Your CO expresses satisfaction with your progress."); if (Player.guildxp[LEGION] < merc_xps[Player.rank[LEGION]]) { print2("But your service record does not yet permit promotion."); } else { print2("You have been promoted to Legion Colonel!"); morewait(); print1("Your next promotion is contingent on the return of"); print2("the Regalia of the Demon Emperor."); morewait(); print1("The Demon Emperor holds court at the base of a volcano"); print2("to the far south, in the heart of a swamp."); morewait(); clearmsg(); print1("You have been taught the spell of heroism!"); print2("You are given advanced training, and a raise."); Spells[S_HERO].known = true; Player.rank[LEGION]=COLONEL; Player.str++; Player.con++; Player.maxstr++; Player.maxcon++; SalaryAmount = 5000; } break; case CENTURION: clearmsg(); print1("Your CO expresses satisfaction with your progress."); if (Player.guildxp[LEGION] < merc_xps[Player.rank[LEGION]]) { print2("But your service record does not yet permit promotion."); } else { print2("You are now a Legion Force-Leader!"); morewait(); clearmsg(); print1("You receive more training, and another raise."); Player.rank[LEGION]=FORCE_LEADER; Player.maxstr++; Player.str++; SalaryAmount = 2000; } break; case LEGIONAIRE: clearmsg(); print1("Your CO expresses satisfaction with your progress."); if (Player.guildxp[LEGION] < merc_xps[Player.rank[LEGION]]) { print2("But your service record does not yet permit promotion."); } else { print2("You are promoted to Legion Centurion!"); morewait(); clearmsg(); print1("You get advanced training, and a higher salary."); Player.rank[LEGION] = CENTURION; Player.maxcon++; Player.con++; SalaryAmount = 1000; } break; } }
void change_level (char fromlevel, char tolevel, char rewrite_level) { struct level * thislevel = NULL; Player.sx = -1; Player.sy = -1; /* sanctuary effect dispelled */ thislevel = findlevel(Dungeon, tolevel); deepest[Current_Environment] = max(deepest[Current_Environment], tolevel); if (!thislevel) { thislevel = (level*) checkmalloc(sizeof(levtype)); clear_level(thislevel); Level = thislevel; Level->next = Dungeon; Dungeon = Level; } Level = thislevel; if ((!Level->generated) || rewrite_level) { initrand(Current_Environment, tolevel); Level->environment = Current_Environment; Level->depth = tolevel; Level->generated = true; switch (Current_Environment) { case E_CAVES: Level->level_width = CAVES_WIDTH; Level->level_length = CAVES_LENGTH; if ((0 == random_range(4)) && (tolevel < MaxDungeonLevels)) room_level(); else cavern_level(); break; case E_SEWERS: Level->level_width = SEWERS_WIDTH; Level->level_length = SEWERS_LENGTH; if ((0 == random_range(4)) && (tolevel < MaxDungeonLevels)) room_level(); else sewer_level(); break; case E_CASTLE: Level->level_width = CASTLE_WIDTH; Level->level_length = CASTLE_LENGTH; room_level(); break; case E_PALACE: /* PGM TODO */ Level->level_width = PALACE_WIDTH; Level->level_length = PALACE_LENGTH; room_level(); break; case E_ASTRAL: Level->level_width = ASTRAL_WIDTH; Level->level_length = ASTRAL_LENGTH; maze_level(); break; case E_VOLCANO: Level->level_width = VOLCANO_WIDTH; Level->level_length = VOLCANO_LENGTH; switch (random_range(3)) { case 0: cavern_level(); break; case 1: room_level(); break; case 2: maze_level(); break; } break; default: print3("This dungeon not implemented!"); assert(false); break; } install_traps(); install_specials(); make_stairs(fromlevel); make_stairs(fromlevel); initrand(E_RESTORE, 0); populate_level(Current_Environment); stock_level(); } find_stairs(fromlevel, tolevel); ScreenOffset = Player.y - (ScreenLength/2); show_screen(); screencheck(Player.x,Player.y); drawvision(Player.x,Player.y); /* synchronize with player on level change */ Player.click = (Tick+1)%60; roomcheck(); }
void l_arena(void) { char response; Object* newitem; int i,prize,monsterlevel; char *melee = NULL; print1("Rampart Coliseum"); if (Player.rank[ARENA] == 0) { print2("Enter the games, or Register as a Gladiator? [e,r,ESCAPE] "); do response = (char) mcigetc(); while ((response != 'e') && (response != 'r') && (response != ESCAPE)); } else { print2("Enter the games? [yn] "); response = ynq2(); if (response == 'y') response = 'e'; else response = ESCAPE; } if (response == 'r') { if (Player.rank[ARENA]>0) print2("You're already a gladiator...."); else if (Player.rank[ORDER]>0) print2("We don't let Paladins into our Guild."); else if (Player.rank[LEGION]>0) print2("We don't train no stinkin' mercs!"); else if (Player.str < 13) print2("Yer too weak to train!"); else if (Player.agi < 12) print2("Too clumsy to be a gladiator!"); else { print1("Ok, yer now an Arena Trainee."); print2("Here's a wooden sword, and a shield"); morewait(); clearmsg(); newitem = ((Object*) checkmalloc(sizeof(Object))); *newitem = Objects[OB_CLUB]; /* club */ gain_item(newitem); newitem = ((Object*) checkmalloc(sizeof(Object))); *newitem = Objects[OB_LRG_RND_SHIELD]; /* shield */ gain_item(newitem); Player.rank[ARENA] = TRAINEE; Arena_Opponent = 3; morewait(); clearmsg(); print1("You've got 5000Au credit at the Gym."); Gymcredit+=5000; } } else if (response == 'e') { print1("OK, we're arranging a match...."); morewait(); Arena_Monster = ((Monster*) checkmalloc(sizeof(Monster))); Arena_Victory = false; switch(Arena_Opponent) { case 0: *Arena_Monster = Monsters[GEEK]; break; case 1: *Arena_Monster = Monsters[HORNET]; break; case 2: *Arena_Monster = Monsters[HYENA]; break; case 3: *Arena_Monster = Monsters[GOBLIN]; break; case 4: *Arena_Monster = Monsters[GRUNT]; break; case 5: *Arena_Monster = Monsters[TOVE]; break; case 6: *Arena_Monster = Monsters[APPR_NINJA]; break; case 7: *Arena_Monster = Monsters[SALAMANDER]; break; case 8: *Arena_Monster = Monsters[ANT]; break; case 9: *Arena_Monster = Monsters[MANTICORE]; break; case 10: *Arena_Monster = Monsters[SPECTRE]; break; case 11: *Arena_Monster = Monsters[BANDERSNATCH]; break; case 12: *Arena_Monster = Monsters[LICHE]; break; case 13: *Arena_Monster = Monsters[AUTO_MAJOR]; break; case 14: *Arena_Monster = Monsters[JABBERWOCK]; break; case 15: *Arena_Monster = Monsters[JOTUN]; break; default: if ((Player.rank[ARENA] < 5) && (Player.rank[ARENA] > 0)) { strcpy(Str1,Champion); strcat(Str1,", the arena champion"); *Arena_Monster = Monsters[HISCORE_NPC]; Arena_Monster->name = salloc(Str1); strcpy(Str2,"The corpse of "); strcat(Str2,Str1); Arena_Monster->corpseString = salloc(Str2); m_status_set( Arena_Monster, ALLOC ); Arena_Monster->level = 20; Arena_Monster->hp = Championlevel*Championlevel*5; Arena_Monster->hit = Championlevel*4; Arena_Monster->ac = Championlevel*3; Arena_Monster->dmg = 100+Championlevel*2; Arena_Monster->xpv = Championlevel*Championlevel*5; Arena_Monster->speed = 3; melee = Arena_Monster->combatManeuvers = (char *) checkmalloc(30*sizeof(char)); strcpy(Arena_Monster->combatManeuvers,""); for(i=0; i<Championlevel/5; i++) strcat(Arena_Monster->combatManeuvers,"L?R?"); m_status_set(Arena_Monster, MOBILE); m_status_set(Arena_Monster, HOSTILE); } else { do i = random_range(ML9 - ML0) + ML0; while (i == NPC || i == HISCORE_NPC || i == ZERO_NPC || (Monsters[i].uniqueness != COMMON) || (Monsters[i].dmg == 0)); *Arena_Monster = Monsters[i]; } break; } monsterlevel = Arena_Monster->level; if (Arena_Monster->level != 20) { strcpy(Str1,nameprint()); strcat(Str1," the "); strcat(Str1,Arena_Monster->name); Arena_Monster->name = salloc(Str1); strcpy(Str2,"The corpse of "); strcat(Str2,Str1); Arena_Monster->corpseString = salloc(Str2); m_status_set( Arena_Monster, ALLOC ); } Arena_Monster->uniqueness = UNIQUE_MADE; print1("You have a challenger: "); print2(Arena_Monster->name); Arena_Monster->wasAttackedByPlayer = true; m_status_set(Arena_Monster,HOSTILE); /* DAG pump up the stats of the arena monster; from env.c */ /* DAG should we even do this for the champion? */ Arena_Monster->hp += Arena_Monster->level*10; Arena_Monster->hit += Arena_Monster->hit; Arena_Monster->dmg += Arena_Monster->dmg/2; morewait(); clearmsg(); change_environment(E_ARENA); print1("Let the battle begin...."); time_clock(true); while (Current_Environment == E_ARENA) time_clock(false); /* DAG all this nasty mess cleaned up... */ /* one process with m_status_set( Arena_Monster, ALLOC) */ /* free(name); */ /* free(corpse); */ if (melee) free(melee); if (! Arena_Victory) { print1("The crowd boos your craven behavior!!!"); if (Player.rank[ARENA] > 0) { print2("You are thrown out of the Gladiator's Guild!"); morewait(); clearmsg(); if (Gymcredit > 0) print1("Your credit at the gym is cut off!"); Gymcredit = 0; Player.rank[ARENA] = -1; } } else { Arena_Opponent++; if (monsterlevel == 20) { print1("The crowd roars its approval!"); if (Player.rank[ARENA]) { print2("You are the new Arena Champion!"); Championlevel = Player.level; strcpy(Champion,Player.name); Player.rank[ARENA] = 5; morewait(); Championbehavior = fixnpc(4); save_hiscore_npc(11); print1("You are awarded the Champion's Spear: Victrix!"); morewait(); newitem = ((Object*) checkmalloc(sizeof(Object))); *newitem = Objects[OB_VICTRIX]; gain_item(newitem); } else { print1("As you are not an official gladiator,"); nprint1("you are not made Champion."); morewait(); } } morewait(); clearmsg(); print1("Good fight! "); nprint1("Your prize is: "); prize = max(25,monsterlevel * 50); if (Player.rank[ARENA] > 0) prize *= 2; mnumprint(prize); nprint1("Au."); Player.cash+=prize; if ((Player.rank[ARENA]<4) && (Arena_Opponent>5) && (Arena_Opponent % 3 == 0)) { if (Player.rank[ARENA]>0) { Player.rank[ARENA]++; morewait(); print1("You've been promoted to a stronger class!"); print2("You are also entitled to additional training."); Gymcredit+=Arena_Opponent*1000; } } } xredraw(); } else clearmsg(); }