/* find apt char to display at some location */ Symbol getspot(int x, int y, int showmonster) { #ifdef CENTER_ON_PLAYER /* funny scrolling may cause this. PGM */ if (!inbounds(x,y ) ) { return SPACE; } #endif if (loc_statusp(x,y,SECRET)) { if ( Level->site[x][y].roomnumber == RS_DRUID ) return(HEDGE); /* secret doors in druid temple are brambles -DAG */ else return(WALL); } else switch (Level->site[x][y].locchar) { case WATER: if (Level->site[x][y].creature == NULL) return(WATER); else if (m_statusp(Level->site[x][y].creature,SWIMMING)) return(WATER); else if (showmonster) return(Level->site[x][y].creature->monchar); else return(WATER); /* these sites never show anything but their location char's */ case CLOSED_DOOR: case LAVA: case FIRE: case ABYSS: return(Level->site[x][y].locchar); /* rubble and hedge don't show items on their location */ case RUBBLE: case HEDGE: if (showmonster && (Level->site[x][y].creature != NULL)) { if ((m_statusp(Level->site[x][y].creature,M_INVISIBLE)) && (! Player.status[TRUESIGHT])) return(getspot(x,y,FALSE)); else return (Level->site[x][y].creature->monchar); } else return(Level->site[x][y].locchar); /* everywhere else, first try to show monster, next show items, next show location char */ default: if (showmonster && (Level->site[x][y].creature != NULL)) { if ((m_statusp(Level->site[x][y].creature,M_INVISIBLE)) && (! Player.status[TRUESIGHT])) return(getspot(x,y,FALSE)); else return (Level->site[x][y].creature->monchar); } else if (Level->site[x][y].things != NULL) { if (Level->site[x][y].things->next != NULL) return(PILE); else return(Level->site[x][y].things->thing->objchar); } else return(Level->site[x][y].locchar); } }
/* for displaying activity specifically at some point */ void plotspot(int x, int y, int showmonster) { if (loc_statusp(x,y,SEEN)) putspot(x,y,getspot(x,y,showmonster)); else putspot(x,y,SPACE); }
static void show_screen_level (int top, int left, int bottom, int right) { int j; int last_attr = 0; for (j = top; j < bottom; ++j) { int i; wmove(Levelw, screenmody(j), 0); for (i = left; i < right; ++i) { int c; if (loc_statusp(i, j, SEEN)) c = getspot(i, j, FALSE); else c = SPACE; if (optionp(SHOW_COLOUR) && CHARATTR(c) != last_attr) { last_attr = CHARATTR(c); wattrset(Levelw, last_attr); } waddch(Levelw, c & 0xff); } } }
/* illuminate one spot at x y */ void lightspot(int x, int y) { Symbol c; lset(x,y,LIT); lset(x,y,SEEN); lset(x, y, CHANGED); c = getspot(x,y,FALSE); Level->site[x][y].showchar = c; putspot(x,y,c); }
/* draws a particular spot regardless of line-of-sight */ void dodrawspot(int x, int y) { Symbol c; if (inbounds(x,y)) { c = getspot(x,y,FALSE); if (c != Level->site[x][y].showchar) { lset(x,y,SEEN); Level->site[x][y].showchar = c; putspot(x,y,c); } } }
/* draws a particular spot under if in line-of-sight */ void drawspot(int x, int y) { Symbol c; if (inbounds(x,y)) { c = getspot(x,y,FALSE); if (c != Level->site[x][y].showchar) if (view_los_p(Player.x,Player.y,x,y)) { lset(x,y,SEEN); Level->site[x][y].showchar = c; putspot(x,y,c); } } }
int main(void) { int i,j,col,xdir,ydir; int kx,ky; int x,y; int empty; int game = 0; int checkfound; while(1) { game++; empty = 1; for (i=0; i < 8; i++) { gets(line); sscanf(line, "%s", board[i]); if (empty && strcmp(board[i],"........")) empty = 0; } if (empty) break; gets(line); for (col=0; col < 2; col++) { if (col) { for (i=0; i < 8; i++) { for (j=0; j < 8; j++) { if ((board[i][j] >= 'a') && (board[i][j] <= 'z')) { board[i][j] = 'A' + (board[i][j] - 'a'); } else if ((board[i][j] >= 'A') && (board[i][j] <= 'Z')) { board[i][j] = 'a' + (board[i][j] - 'A'); } } } } checkfound = 0; kx = -1; for (i=0; i < 8; i++) { for (j=0; j < 8; j++) { if (board[i][j] == 'K') { kx = j; ky = i; break; } } if (kx >= 0) break; } if (col==0) { if (getspot(kx-1, ky-1) == 'p') goto incheck; if (getspot(kx+1, ky-1) == 'p') goto incheck; } else { if (getspot(kx-1, ky+1) == 'p') goto incheck; if (getspot(kx+1, ky+1) == 'p') goto incheck; } if (getspot(kx-2, ky-1) == 'n') goto incheck; if (getspot(kx-2, ky+1) == 'n') goto incheck; if (getspot(kx+2, ky-1) == 'n') goto incheck; if (getspot(kx+2, ky+1) == 'n') goto incheck; if (getspot(kx-1, ky-2) == 'n') goto incheck; if (getspot(kx+1, ky-2) == 'n') goto incheck; if (getspot(kx-1, ky+2) == 'n') goto incheck; if (getspot(kx+1, ky+2) == 'n') goto incheck; for (ydir=-1; ydir <= 1; ydir += 2) { x = kx; y = ky + ydir; while (valid(x,y)) { if (getspot(x,y) == 'r') goto incheck; if (getspot(x,y) == 'q') goto incheck; if (getspot(x,y) != '.') break; y += ydir; } } for (xdir=-1; xdir <= 1; xdir += 2) { x = kx + xdir; y = ky; while (valid(x,y)) { if (board[y][x] == 'r') goto incheck; if (board[y][x] == 'q') goto incheck; if (board[y][x] != '.') break; x += xdir; } } for (ydir=-1; ydir <= 1; ydir += 2) { for (xdir=-1; xdir <= 1; xdir += 2) { x = kx + xdir; y = ky + ydir; while (valid(x,y)) { if (board[y][x] == 'b') goto incheck; if (board[y][x] == 'q') goto incheck; if (board[y][x] != '.') break; x += xdir; y += ydir; } } } continue; incheck: if (col) { printf("Game #%d: black king is in check.\n", game); } else { printf("Game #%d: white king is in check.\n", game); } checkfound = 1; break; } if (!checkfound) { printf("Game #%d: no king is in check.\n", game); } } }
/* replace monster with what would be displayed if monster weren't there */ void erase_monster(pmt m) { if (loc_statusp(m->x,m->y,SEEN)) putspot(m->x,m->y,getspot(m->x,m->y,FALSE)); else blotspot(m->x,m->y); }
void m_death(struct monster *m) { pob corpse; pml ml; int x; int y; int found = FALSE; m->hp = -1; if(los_p(Player.x, Player.y, m->x, m->y)) { putspot(m->x, m->y, getspot(m->x, m->y, FALSE)); gain_experience(m->xpv); calc_melee(); if(m->uniqueness != COMMON) { strcpy(Str1, m->monstring); } else { strcpy(Str1, "The "); strcat(Str1, m->monstring); } strcat(Str1, " is dead!"); mprint(Str1); } m_dropstuff(m); /* Death */ if(m->id == (ML10 + 0)) { mprint("Death lies sprawled out on the ground..."); mprint("Death laughs ironically and gets back to his feet."); mprint("He gestures and another scythe appears in his hands."); switch(random_range(10)) { case 0: mprint("Death performs a little bow and goes back on guard."); break; case 1: mprint("\'A hit! A palpable hit!\' Death goes back on the attack."); break; case 2: mprint("\'Ah, if only it could be so simple!\' snickers Death."); break; case 3: mprint("\'This fool things he can slay death! What a jest!\' says Death."); break; case 4: mprint("\'You point is well taken.\' says Death, attacking again."); break; case 5: mprint("\'Oh, come now, stop delaying the inevitable.\' says Death."); break; case 6: mprint("\'Your destiny ends here with me.\' says Death, scythe raised."); break; case 7: mprint("\'I almost felt that.\' says Death, smiling."); break; case 8: mprint("\'Timeo Mortis?\' asks Death quizzically, \'Not me!\'"); break; case 9: mprint("Death sighs theatrically. \'They never learn.\'"); break; } strengthen_death(m); } else { Level->site[m->x][m->y].creature = NULL; if(random_range(2) || (m->uniqueness != COMMON)) { corpse = (pob)malloc(sizeof(objtype)); make_corpse(corpse, m); drop_at(m->x, m->y, corpse); } plotspot(m->x, m->y, FALSE); switch(m->id) { case ML0 + 8: /* Hiscore NPC */ switch(m->aux2) { case 0: mprint("You hear a faroff dirge. You feel a sense of triumph."); break; case 1: case 2: case 3: case 4: case 5: case 6: mprint("You hear a faroff sound like angels crying..."); strcpy(Priest[1], nameprint()); Priestbehavior[1] = 2933; break; case 7: mprint("A furtive figure dashes out of the shadows, takes a look at"); mprint("the corpse, and runs away!"); strcpy(Shadowlord, nameprint()); Shadowlordbehavior = 2912; break; case 8: mprint("An aide-de-camp approaches, removes the corpse's insignia,"); mprint("and departs."); strcpy(Commandant, nameprint()); Commandantbehavior = 2912; break; case 9: mprint("An odd glow surrounds the corpse, and slowly fades."); strcpy(Archmage, nameprint()); Archmagebehavior = 2933; break; case 10: mprint("A demon materializes, takes a quick look at the corpse,"); mprint("and teleports away with a faint popping noise."); strcpy(Prime, nameprint()); Primebehavior = 2932; break; case 11: mprint("A sports columnist rushes forward and takes a quick photo"); mprint("of the corpse and rushes off muttering about a deadline."); strcpy(Champion, nameprint()); Championbehavior = 2913; break; case 12: mprint("You hear a fanfare in the distance, and feel dismayed."); strcpy(Duke, nameprint()); Dukebehavior = 2911; break; case 13: if(Player.alignment > 10) { mprint("You feel smug."); } else if(Player.alignment < 10) { mprint("You feel ashamed."); } strcpy(Chaoslord, nameprint()); Chaoslordbehavior = 2912; break; case 14: if(Player.alignment < 10) { mprint("You feel smug."); } else if(Player.alignment > 10) { mprint("You feel ashamed."); } strcpy(Lawlord, nameprint()); Lawlordbehavior = 2911; break; case 15: /* * Just a tad complicated. Promote a new justiciar if * an guards are left in the city, otherwise destroy * the Order! */ Player.alignment -= 100; if(!gamestatusp(DESTROYED_ORDER)) { mprint("In the distance you hear a trumpet. A Servent of Law"); mprint("materializes, sheds a tear, and leaves."); strcpy(Justiciar, nameprint()); Justiciarbehavior = 2911; /* Promote one of the city guards to be justiciar */ ml = City->mlist; while(!found && (ml != NULL)) { if((ml->m->id == (ML0 + 3)) && (ml->m->hp > 0)) { found = 1; } else { found = 0; } if(!found) { ml = ml->next; } } if(ml != NULL) { mprint("A new justiciar has been promoted!"); x = ml->m->x; y = ml->m->y; ml->m->x = x; ml->m->y = y; ml->m->click = (Tick + 1) % 60; m_status_reset(ml->m, AWAKE); m_status_reset(ml->m, HOSTILE); } /* * Will cause order to be destroyed if no guards or justiciar */ alert_guards(); } else { mprint("A Servant of Chaos materializes, grabs the corpse,"); mprint("snickers a bit, and vanishes."); } } break; case ML0 + 3: /* Guard */ Player.alignment -= 10; if((Current_Environment == E_CITY) || (Current_Environment == E_VILLAGE)) { alert_guards(); } break; case ML3 + 5: /* Goblin king */ if(!gamestatusp(ATTACKED_ORACLE)) { mprint("You seem to hear a woman's voice from far off:"); mprint("\'Well don! Come to me now...\'"); } setgamestatus(COMPLETED_CAVES); break; case ML7 + 5: /* Great worm */ if(!gamestatusp(ATTACKED_ORACLE)) { mprint("A female voice sounds from just behind your ear:"); mprint("\'Well fought! I have some new advice for you...\'"); } setgamestatus(COMPLETED_SEWERS); break; case ML10 + 1: setgamestatus(KILLED_EATER); break; case ML10 + 2: setgamestatus(KILLED_LAWBRINGER); break; case ML10 + 3: setgamestatus(KILLED_DRAGONLORD); break; case ML10 + 4: setgamestatus(COMPLETED_VOLCANO); if(!gamestatusp(ATTACKED_ORACLE)) { mprint("You feel a soft touch on your shoulder..."); mprint("You turn around but there is no one there!"); mprint("You turn back and see a not: \'See me soon.\'"); mprint("The note vanishes in a burst of blue fire!"); } break; case ML10 + 9: /* Elemental master */ if(!gamestatusp(ATTACKED_ORACLE)) { mprint("Words appear before you, traced in blue flame!"); mprint("\'Return to the Prime Plane via the Circle of Sorcerors..."); } break; } } dodrawspot(m->x, m->y); }