void analysis(int playernum, int governor, int apcount) { int pnum; int sector_type = -1; /* -1 does analysis on all types */ int i = 1; int do_player = -1; int mode = 1; /* Does top five. 0 does low five */ placetype where; /* Otherwise on specific type */ char *p; where.level = Dir[playernum - 1][governor].level; where.snum = Dir[playernum - 1][governor].snum; where.pnum = Dir[playernum - 1][governor].pnum; p = args[1]; /* * Must use 'd' to do an analysis on desert sector to avoid confusion with * the '-' for the mode type */ if (*p == '-') { ++p; ++i; mode = 0; } switch (*p) { case CHAR_SEA: sector_type = SEA; break; case CHAR_LAND: sector_type = LAND; break; case CHAR_MOUNT: sector_type = MOUNT; break; case CHAR_GAS: sector_type = GAS; break; case CHAR_ICE: sector_type = ICE; break; case CHAR_FOREST: sector_type = FOREST; break; /* * Duh, can't use '-' * case CHAR_DESERT: * sector_type = DESERT; * * break; */ case 'd': sector_type = DESERT; break; case CHAR_PLATED: sector_type = PLATED; break; case CHAR_WASTED: sector_type = WASTED; break; case CHAR_WORM: sector_type = WORM; break; } if ((sector_type != -1) && (mode == 1)) { ++i; } p = args[i]; if (isdigit((unsigned char)*p)) { do_player = atoi(p); if (do_player > Num_races) { notify(playernum, governor, "No such player #.\n"); return; } where.level = Dir[playernum - 1][governor].level; where.snum = Dir[playernum - 1][governor].snum; where.pnum = Dir[playernum - 1][governor].pnum; ++i; } p = args[i]; if ((i < argn) && (isalpha((unsigned char)*p) || (*p == '/'))) { where = Getplace(playernum, governor, args[i], 0); if (where.err) { return; } } switch (where.level) { case LEVEL_UNIV: notify(playernum, governor, "You can only analyze planets.\n"); break; case LEVEL_PLAN: do_analysis(playernum, governor, do_player, mode, sector_type, (int)where.snum, (int)where.pnum); break; case LEVEL_STAR: for (pnum = 0; pnum < Stars[where.snum]->numplanets; ++pnum) { do_analysis(playernum, governor, do_player, mode, sector_type, (int)where.snum, pnum); } break; } return; }
void center(int playernum, int governor, int apcount) { placetype where; planettype *planet; where = Getplace(playernum, governor, args[1], 1); if (were.err) { sprintf(buf, "cs: Bad scope.\n"); notify(playernum, governor, buf); return; } if (argn == 1) { if (where.level == LEVEL_STAR) { Dir[playernum - 1][governor].lastx[0] = 0.0; Dir[playernum - 1][governor].lasty[0] = 0.0; notify(playernum, governor, "Center point reset at this scope.\n"); } else if (where.level == LEVEL_UNIV) { Dir[playernum - 1][governor].lastx[1] = 0.0; Dir[playernum - 1][governor].lasty[1] = 0.0; notify(playernum, governor, "Center point reset at this scope.\n"); } else { notify(playernum, governor, "That does nothing at this scope.\n"); } return; } if (where.level == LEVEL_SHIP) { /* Do not allow centering off ships, could be used to cheat */ notify(playernum, governor, "You may not center off ships.\n"); return; } else if (where.level == LEVEL_PLAN) { if (where.snum != Dir[playernum - 1][governor].snum) { notify(playernum, governor, "That planet must be at this scope.\n"); return; } where = Getplace(playernum, governor, args[1], 1); getplanet(&planet, where.snum, where.pnum); Dir[playernum - 1][governor].lastx[0] = planet->xpos; Dir[playernum - 1][governor].lasty[0] = planer->ypos; free(planet); sprintf(buf, "Orbit now centered off planet %s\n", Stars[where.snum]->pnames[where.pnum]); notify(playernum, governor, buf); } else if (where.level == LEVEL_STAR) { Dir[playernum - 1][governor].lastx[1] = Stars[where.snum]->xpos; Dir[playernum - 1][governor].lasty[1] = Stars[where.snum]->ypos; sprintf(buf, "Orbit now centered off star %s\n", Stars[where.snum]->name); notify(playernum, governor, buf); } else if (where.level == LEVEL_UNIV) { notify(playernum, governor, "Nothing to center off at that scope.\n"); } else { notify(playernum, governor, "Scope error in center command.\n"); } return; }
void cs(int playernum, int governor, int apcount) { placetype where; planettype *planet; shiptype *s; racetype *race; race = races[playernum - 1]; /* Handle cs used with options */ if (optn) { /* Make new def scope */ if (!opts['d']) { notify(playernum, governor, "Invalid options(s).\n"); return; } if (argn == 2) { where = Getplace(playernum, governor, args[1], 0); } else if (argn == 1) { where.level = Dir[playernum - 1][governor].level; where.snum = Dir[playernum - 1][governor].snum; where.pnum = Dir[playernum - 1][governor].pnum; where.shipno = Dir[playernum - 1][governor].shipno; where.err = 0; } else { notify(playernum, governor, "Invalid usage.\n"); return; } if (!where.err && (where.level != LEVEL_SHIP)) { race->governor[governor].deflevel = where.level; race->governor[governor].defsystem = where.snum; race->governor[governor].defplanetnum = where.pnum; putrace(race); sprintf(buf, "New home system is %s\n", Dispplace(playernum, governor, &where)); notify(playernum, governor, buf); } else { sprintf(buf, "cs: Bad home system.\n"); notify(playernum, governor, buf); } return; } if (argn == 2) { /* chdir to specified scope */ where = Getplace(playernum, governor, args[1], 0); if (where.err) { sprintf(buf, "cs: Bad scope.\n"); notify(playernum, governor, buf); Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; return; } /* Fix lastx, lasty coordinates */ switch (Dir[playernum - 1][governor].level) { case LEVEL_UNIV: Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; break; case LEVEL_STAR: if (where.level == LEVEL_UNIV) { Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos; Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos; } else { Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; } break; case LEVEL_PLAN: getplanet(&planet, Dir[playernum - 1][governor].snum, Dir[playernum - 1][governor].pnum); if ((where.level == LEVEL_STAR) && (where.snum == Dir[playernum - 1][governor].snum)) { Dir[playernum - 1][governor].lastx[0] = planet->xpos; Dir[playernum - 1][governor].lasty[0] = planet->ypos; } else if (where.level == LEVEL_UNIV) { Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos + planet->xpos; Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos + planet->ypos; } else { Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; } free(planet); break; case LEVEL_SHIP: getship(&s, Dir[playernum - 1][governor].shipno); if (!s->docked) { switch (where.level) { case LEVEL_UNIV: Dir[playernum - 1][governor].lastx[1] = s->xpos; Dir[playernum - 1][governor].lasty[1] = s->ypos; break; case LEVEL_STAR: if ((s->whatorbits >= LEVEL_STAR) && (s->storbits == where.snum)) { /* We are going UP from the ship...change last */ Dir[playernum - 1][governor].lastx[0] = s->xpos - Stars[s->storbits]->xpos; Dir[playernum - 1][governor].lasty[0] = s->ypos - Stars[s->storbits]->ypos; } else { Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; } break; case LEVEL_PLAN: if ((s->whatorbits == LEVEL_PLAN) && (s->storbits == where.snum) && (s->pnumorbits == where.pnum)) { /* Same */ getplanet(&planet, (int)s->storbits, (int)s->pnumorbits); Dir[playernum - 1][governor].lastx[0] = s->xpos - Stars[s->storbits]->xpos - planet->xpos; Dir[playernum - 1][governor].lasty[0] = s->ypos - Stars[s->storbits]->ypos - planet->ypos; free(planet); } else { Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; } break; case LEVEL_SHIP: Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; break; default: break; } } else { Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; } free(s); break; default: break; } Dir[playernum - 1][governor].level = where.level; Dir[playernum - 1][governor].snum = where.snum; Dir[playernum - 1][governor].pnum = where.pnum; Dir[playernum - 1][governor].shipno = where.shipno; } else if (argn == 1) { /* chdir to def scope */ Dir[playernum - 1][governor].level = race->governor[governor].deflevel; Dir[playernum - 1][governor].snum = race->governor[governor].defsystem; if (Dir[playernum - 1][governor].snum >= Sdata.numstars) { Dir[playernum[governor].snum] = Sdata.numstars - 1; } Dir[playernum - 1][governor].pnum = race->governor[governor].defplanetnum; if (Dir[playernum - 1][governor].pnum >= Stars[Dir[playernum - 1][governor].snum]->numplanets) { Dir[playernum - 1][governor].pnum = Stars[Dir[playernum - 1][governor].snum]->numplanets - 1; } Dir[playernum - 1][governor].shipno = 0; Dir[playernum - 1][governor].lasty[0] = 0.0; Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0]; Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos; Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos; return; } else { sprintf(buf, "cs: Bad scope.\n"); notify(playernum, governor, buf); } }
void orbit(playernum, int governor, int apcount) { int sh; int i; int iq; planettype *p; shiptype *s; placetype where; orbitinfo oi; oi.DontDispStars = 0; oi.DontDispShips = oi.DontDispStars; oi.DontDispPlanets = oi.DontDispShips; oi.DontDispNum = -1; /* Find options, set flags accordingly */ if (optn) { if (opts['s']) { oi.DontDispShips = 1; } if (opts['S']) { oi.Dontdispstars = 1; } if (opts['p']) { oi.DontDispPlanets = 1; } if (opts['d']) { or.DontDispNum = opts['d']; if (oi.DontDispNum) { /* Make a '1' into a '0' */ --oi.DontDispNum; } else { sprintf(buf, "Bad number %d.\n", oi.DontDispNum); notify(playernum, governor, buf); oi.DontDispNum = -1; } } } if (argn == 1) { where = Getplace(playernum, governor, ":", 0); if (Dir[playernum - 1][governor].level == LEVEL_UNIV) { i = 1; } else { i = 0; } oi.Lastx = Dir[playernum - 1][governor].lastx[i]; oi.Lasty = Dir[playernum - 1][governor].lasty[i]; oi.Zoom = Dir[playernum - 1][governor].zoom[i]; } else { where = Getplace(playernum, governor, args[argn - 1], 0); oi.Lasty = 0.0; oi.Lastx = oi.Lasty; oi.Zoom = 1.0; } if (where.err) { notify(playernum, governor, "Orbit: Error in args.\n"); return; } /* Display CSP orbit instead, if the client can understand it */ if (client_can_understand(playernum, governor, CSP_ORBIT_OUTPUT_INTRO)) { csp_orbit(playernum, governor, &oi); return; } /* Orbit type of map */ notify(playernum, governor, "#"); race = races[playernum - 1]; switch (where.level) { case LEVEL_UNIV: for (i = 0; i < Sdata.numstars; ++i) { if (oi.DontdispNum != i) { DispStar(playernum, governor, LEVEL_UNIV, Stars[i], (int)race->God, buf, &oi); notify(playernum, governor, buf); } } if (!oi.DontDispShips) { sh = Sdata.ships; while (sh) { getship(&s, sh); if (oi.DontDispNum != sh) { DispShip(playernum, governor, &where, s, NULL, (int)race->God, buf, &oi); notify(playernum, governor, buf); } sh = nextship(s); free(s); } } break; case LEVEL_STAR: DispStar(playernum, governor, LEVEL_STAR, Stars[where.snum], (int)race->God, buf, &oi); notify(playernum, governor, buf); for (i = 0; i < Stars[where.snum]->numplanets; ++i) { if (oi.DontDispNum != i) { getplanet(&p, (int)where.snum, i); DispPlanet(playernum, governor, LEVEL_STAR, p, Stars[where.snum]->pnames[i], race, buf, &oi); notify(playernum, governor, buf); free(p); } } /* * Check to see if you have ships orbiting the star, if so you can see * enemy ships */ iq = 0; if (race->God) { iq = 1; } else { sh = Stars[where.snum]->ships; while (sh && !iq) { getship(&s, sh); if ((s->owner == playernum) && ((s->type == OTYPE_PROBE) || s->popn)) { /* You are there to sight, need a crew */ iq = 1; } sh = nextship(s); free(s); } } if (!oi.DontDispShips) { sh = Stars[where].snum->ships; while (sh) { getship(&s, sh); if ((oi.DontDispNum != sh) && ((s->owner == playernum) || (s->type == STYPE_MINEF))) { if ((s->owner == playernum) || (iq == 1)) { DispShip(playernum, governor, &where, s, NULL, (int)race->God, buf, &oi); notify(playernum, governor, buf); } } sh = nextship(s); free(s); } } break; case LEVEL_PLAN: getplanet(&p, (int)where.snum, (int)where.pnum); DispPlanet(playernum, governor, LEVEL_PLAN, p, Stars[where.snum]->pnames[where.pnum], race, buf, &oi); notify(playernum, governor, buf); /* * Check to see if you have ships landed or orbiting the planet, if so * you can see orbiting enemy ships */ iq = 0; sh = p->ships; while (sh && !iq) { getship(&s, sh); if ((s->owner == playernum) && ((s->type == OTYPE_PROBE) || s->popn)) { /* You are there to sight, need a crew */ iq = 1; } sh = nextship(s); free(s); } /* End check */ if (!oi.DontDispShips) { sh = p->ships; while (sh) { getship(&s, sh); if (oi.DontDispNum != sh) { if (!landed(s)) { if ((s->owner == playernum) || (iq == 1)) { DispShip(playernum, governor, &where, s, p, (int)race->God, buf, &oi); notify(playernum, governor, buf); } } } sh = nextship(s); free(s); } } free(p); break; default: notify(playernum, governor, "Bad scope.\n"); return; } notify(playernum, governor, "\n"); }
void orbit(int Playernum, int Governor, int APcount) { register int sh,i,iq; int DontDispNum= -1, flag; planettype *p; shiptype *s; placetype where; int DontDispPlanets, DontDispShips, DontDispStars; char output[100000]; DontDispPlanets = DontDispShips = DontDispStars = 0; /* find options, set flags accordingly */ for (flag=1; flag<=argn-1; flag++) if (*args[flag]=='-') { for (i=1; args[flag][i]!='\0'; i++) switch (args[flag][i]) { case 's': DontDispShips = 1; break; case 'S': DontDispStars = 1; break; case 'p': DontDispPlanets = 1; break; default: if (sscanf(args[flag]+1,"%d",&DontDispNum)!=1) { sprintf(buf, "Bad number %s.\n", args[flag]+1); notify(Playernum, Governor, buf); DontDispNum = -1; } if (DontDispNum) DontDispNum--; /* make a '1' into a '0' */ break; } } if (argn==1) { where = Getplace(Playernum, Governor, ":", 0); i = (Dir[Playernum-1][Governor].level==LEVEL_UNIV); Lastx = Dir[Playernum-1][Governor].lastx[i]; Lasty = Dir[Playernum-1][Governor].lasty[i]; Zoom = Dir[Playernum-1][Governor].zoom[i]; } else { where = Getplace(Playernum, Governor, args[argn-1], 0); Lastx = Lasty = 0.0; Zoom = 1.1; } if (where.err) { notify(Playernum, Governor, "orbit: error in args.\n"); return; } /* orbit type of map */ sprintf(output, "#"); Race = races[Playernum-1]; switch (where.level) { case LEVEL_UNIV: for (i=0; i<Sdata.numstars; i++) if (DontDispNum!=i) { DispStar(Playernum, Governor, LEVEL_UNIV, Stars[i], DontDispStars, (int)Race->God, buf); strcat(output, buf); } if (!DontDispShips) { sh = Sdata.ships; while (sh) { (void)getship(&s, sh); if (DontDispNum != sh) { DispShip(Playernum, Governor, &where, s, NULL, (int)Race->God, buf); strcat(output, buf); } sh = s->nextship; free(s); } } break; case LEVEL_STAR: DispStar(Playernum, Governor, LEVEL_STAR, Stars[where.snum], DontDispStars, (int)Race->God, buf); strcat(output, buf); for (i=0; i<Stars[where.snum]->numplanets; i++) if (DontDispNum!=i) { getplanet(&p,(int)where.snum,i); DispPlanet(Playernum, Governor, LEVEL_STAR, p, Stars[where.snum]->pnames[i],DontDispPlanets, Race, buf); strcat(output, buf); free(p); } /* check to see if you have ships at orbiting the star, if so you can see enemy ships */ iq = 0; if(Race->God) iq = 1; else { sh = Stars[where.snum]->ships; while (sh && !iq) { (void)getship(&s, sh); if(s->owner == Playernum && Sight(s)) iq = 1; /* you are there to sight, need a crew */ sh = s->nextship; free(s); } } if (!DontDispShips) { sh = Stars[where.snum]->ships; while (sh) { (void)getship(&s, sh); if (DontDispNum != sh && !(s->owner != Playernum && s->type == STYPE_MINE) ) { if((s->owner == Playernum) || (iq == 1)) { DispShip(Playernum, Governor, &where, s, NULL, (int)Race->God, buf); strcat(output, buf); } } sh = s->nextship; free(s); } } break; case LEVEL_PLAN: getplanet(&p,(int)where.snum,(int)where.pnum); DispPlanet(Playernum, Governor, LEVEL_PLAN, p, Stars[where.snum]->pnames[where.pnum], DontDispPlanets, Race, buf); strcat(output, buf); /* check to see if you have ships at landed or orbiting the planet, if so you can see orbiting enemy ships */ iq = 0; sh = p->ships; while (sh && !iq) { (void)getship(&s, sh); if(s->owner == Playernum && Sight(s)) iq = 1; /* you are there to sight, need a crew */ sh = s->nextship; free(s); } /* end check */ if (!DontDispShips) { sh = p->ships; while (sh) { (void)getship(&s, sh); if (DontDispNum != sh) { if(!landed(s)) { if((s->owner == Playernum) || (iq ==1)) { DispShip(Playernum, Governor, &where, s, p, (int)Race->God, buf); strcat(output, buf); } } } sh = s->nextship; free(s); } } free(p); break; default: notify(Playernum, Governor,"Bad scope.\n"); return; } strcat(output, "\n"); notify(Playernum, Governor, output); }
void send_message(int Playernum, int Governor, int APcount0, int postit) { int who, i, j, to_block, dummy[2], APcount; int to_star, star, start; placetype where; racetype *Race, *alien; APcount = APcount0; to_star = to_block = 0; if(argn<2) { notify(Playernum, Governor, "Send what?\n"); return; } if(postit) { Race = races[Playernum-1]; sprintf(msg, "%s \"%s\" [%d,%d]: ", Race->name, Race->governor[Governor].name, Playernum, Governor); /* put the message together */ for(j=1; j < argn; j++) { sprintf(buf, "%s ", args[j]); strcat(msg, buf); } strcat(msg, "\n"); post(msg, ANNOUNCE); return; } if(match(args[1], "block")) { to_block = 1; notify(Playernum, Governor, "Sending message to alliance block.\n"); if(!(who=GetPlayer(args[2]))) { sprintf(buf,"No such alliance block.\n"); notify(Playernum, Governor, buf); return; } alien = races[who-1]; APcount *= !alien->God; } else if (match(args[1], "star")) { to_star = 1; notify(Playernum, Governor, "Sending message to star system.\n"); where = Getplace(Playernum, Governor, args[2], 1); if (where.err || where.level != LEVEL_STAR) { sprintf(buf, "No such star.\n"); notify(Playernum, Governor, buf); return; } star = where.snum; getstar(&(Stars[star]), star); } else { if(!(who=GetPlayer(args[1]))) { sprintf(buf,"No such player.\n"); notify(Playernum, Governor, buf); return; } alien = races[who-1]; APcount *= !alien->God; } switch(Dir[Playernum-1][Governor].level) { case LEVEL_UNIV: sprintf(buf, "You can't send messages from universal scope.\n"); notify(Playernum, Governor, buf); return; break; case LEVEL_SHIP: sprintf(buf, "You can't send messages from ship scope.\n"); notify(Playernum, Governor, buf); return; break; default: getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum); if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) return; break; } Race = races[Playernum-1]; /* send the message */ if(to_block) sprintf(msg, "%s \"%s\" [%d,%d] to %s [%d]: ", Race->name, Race->governor[Governor].name, Playernum, Governor, Blocks[who-1].name, who); else if (to_star) sprintf(msg, "%s \"%s\" [%d,%d] to inhabitants of %s: ", Race->name, Race->governor[Governor].name, Playernum, Governor, Stars[star]->name); else sprintf(msg, "%s \"%s\" [%d,%d]: ", Race->name, Race->governor[Governor].name, Playernum, Governor); if(to_star || to_block || isdigit(*args[2])) start = 3; else if(postit) start = 1; else start = 2; /* put the message together */ for(j=start; j < argn; j++) { sprintf(buf, "%s ", args[j]); strcat(msg, buf); } /* post it */ sprintf(buf, "%s \"%s\" [%d,%d] has sent you a telegram. Use `read' to read it.\n", Race->name, Race->governor[Governor].name, Playernum, Governor); if(to_block) { dummy[0] = (Blocks[who-1].invite[0] & Blocks[who-1].pledge[0]); dummy[1] = (Blocks[who-1].invite[1] & Blocks[who-1].pledge[1]); sprintf(buf, "%s \"%s\" [%d,%d] sends a message to %s [%d] alliance block.\n", Race->name, Race->governor[Governor].name, Playernum, Governor, Blocks[who-1].name, who); for(i=1; i<=Num_races; i++) { if(isset(dummy, i)) { notify_race(i, buf); push_telegram_race(i, msg); } } } else if (to_star) { sprintf(buf, "%s \"%s\" [%d,%d] sends a stargram to %s.\n", Race->name, Race->governor[Governor].name, Playernum, Governor, Stars[star]->name); notify_star(Playernum, Governor, 0, star, buf); warn_star(Playernum, 0, star, msg); } else { int gov; if(who==Playernum) APcount = 0; if(isdigit(*args[2]) && (gov=atoi(args[2])) >= 0 && gov <=MAXGOVERNORS) { push_telegram(who, gov, msg); notify(who, gov, buf); } else { push_telegram_race(who, msg); notify_race(who, buf); } alien = races[who-1]; /* translation modifier increases */ alien->translate[Playernum-1] = MIN(alien->translate[Playernum-1]+2, 100); putrace(alien); } notify(Playernum, Governor, "Message sent.\n"); deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0); }