void do_pod(shiptype *ship) { reg int i; if(ship->whatorbits==LEVEL_STAR) { if (ship->special.pod.temperature >= POD_THRESHOLD) { i = int_rand(0,(int)Stars[ship->storbits]->numplanets - 1); sprintf(telegram_buf, "%s has warmed and exploded at %s\n", Ship(ship), prin_ship_orbits(ship)); if(infect_planet((int)ship->owner, (int)ship->storbits, i)) { sprintf(buf,"\tmeta-colony established on %s.", Stars[ship->storbits]->pnames[i]); } else sprintf(buf,"\tno spores have survived."); strcat(telegram_buf, buf); push_telegram((int)(ship->owner), (int)ship->governor, telegram_buf); kill_ship((int)(ship->owner), ship); } else ship->special.pod.temperature += round_rand((double)Stars[ship->storbits]->temperature/ (double)segments); } else if(ship->whatorbits==LEVEL_PLAN) { if(ship->special.pod.decay >= POD_DECAY) { sprintf(telegram_buf, "%s has decayed at %s\n", Ship(ship), prin_ship_orbits(ship)); push_telegram((int)ship->owner, (int)ship->governor, telegram_buf); kill_ship((int)ship->owner, ship); } else { ship->special.pod.decay += round_rand(1.0/(double)segments); } } }
std::vector<uint16> CMysteryShopExt::GetGoodsList(uint32 level, uint32 count) { std::vector<uint16> ret; std::vector<S2UInt32> goods_list; for (UInt32MysteryShopMap::iterator iter = id_mysteryshop_map.begin(); iter != id_mysteryshop_map.end(); ++iter) { SData *p_data = iter->second; if (p_data->min_level <= level && level <= p_data->max_level) { S2UInt32 obj; obj.first = p_data->id; obj.second = p_data->rate; goods_list.push_back(obj); } } if (goods_list.size() < count) { LOG_ERROR("CMysteryShopExt::GetGoodsList %u level only got %zu goods", level, goods_list.size()); return ret; } while (count > 0) { S2UInt32 obj = round_rand(goods_list, goods_get_value); goods_list.erase(std::remove_if(goods_list.begin(), goods_list.end(), EqualMysteryId(obj.first)), goods_list.end()); uint16 id = obj.first; ret.push_back(id); count--; } return ret; }
void do_ap(shiptype *ship) { racetype *Race; /* if landed on planet, change conditions to be like race */ if (landed(ship) && ship->on) { int j,d,a; planettype *p; p = planets[ship->storbits][ship->pnumorbits]; Race = races[ship->owner-1]; if (ship->fuel >= 3.0) { use_fuel(ship, 3.0); for (j=RTEMP+1; j<=OTHER; j++) { d = round_rand(ap_planet_factor(p)*crew_factor(ship)* (double)(Race->conditions[j]-p->conditions[j])); if(d) p->conditions[j] += d; } } else if (!ship->notified) { ship->notified = 1; ship->on = 0; msg_OOF(ship); } } }
void do_habitat(shiptype *ship) { reg int sh; int add; double fuse; /* In v5.0+ Habitats make resources out of fuel */ if(ship->on) { fuse = ship->fuel * ((double)ship->popn / (double)ship->max_crew) * (1.0 - .01*(double)ship->damage); add = (int)fuse/20; if (ship->resource+add > ship->max_resource) add = ship->max_resource - ship->resource; fuse = 20.0*(double)add; rcv_resource(ship, add); use_fuel(ship, fuse); sh = ship->ships; while(sh) { if (ships[sh]->type==OTYPE_WPLANT) rcv_destruct(ship, do_weapon_plant(ships[sh])); sh = ships[sh]->nextship; } } add = round_rand((double)ship->popn * races[ship->owner-1]->birthrate); if (ship->popn+add > Max_crew(ship)) add = Max_crew(ship) - ship->popn; rcv_popn(ship, add, races[ship->owner-1]->mass); }
int do_weapon_plant(shiptype *ship) { int maxrate, rate; maxrate = (int)(races[ship->owner-1]->tech/2.0); rate = round_rand(MIN((double)ship->resource/(double)RES_COST_WPLANT, ship->fuel/FUEL_COST_WPLANT) * (1.-.01*(double)ship->damage) * (double)ship->popn/(double)ship->max_crew); rate = MIN(rate, maxrate); use_resource(ship, (rate*RES_COST_WPLANT)); use_fuel(ship, ((double)rate*FUEL_COST_WPLANT)); return rate; }
int main(int argc, char *argv[]) { FILE *stardata; FILE *planetdata; FILE *sectordata; FILE *outputtxt = NULL; char str[200]; int c; int i; int star; /* * int x; */ /* * double att; */ double xspeed[NUMSTARS]; double yspeed[NUMSTARS]; /* * Empty stars */ int nempty; /* * How many rows and columns are needed */ int rowcolumns; /* * Non-empty stars not placed */ int starsleft; /* * How many planetless systems is in each square */ int emptyrounds; /* * Size of square */ double displacement; /* * How many wormholes */ int whcnt; int wormholes = -1; int wormidx; struct w_holes w_holes[NUMSTARS + 1]; int x; int y; int z; int squaresleft; int total; int flag = 0; struct power power[MAXPLAYERS]; struct block block[MAXPLAYERS]; /* * Initialize */ /* * srandom(getpid()); */ Bzero(Sdata); /* * Read the arguments for values */ for (i = 1; i < argc; ++i) { if (argv[i][0] != '-') { printf("\n"); printf("Usage: makeuniv [-a] [-b] [-d] [-e E] [-l MIN] [-m MAX] "); printf("[-s N] [-v] [-w C] [-x]\n"); printf(" -a Autoload star names.\n"); printf(" -b Autoload planet names.\n"); printf(" -d Use smashup (asteroid impact routines.\n"); printf(" -e E Make E%% of stars have no planets.\n"); printf(" -l MIN Other systems will have at least MIN planets.\n"); printf(" -m MAX Other systems will have at most MAX planets.\n"); printf(" -p Create postscript map file of the univese.\n"); printf(" -s N The univers will have N stars.\n"); printf(" -v Do no print info and map of planets generated.\n"); printf(" -w C The universe will have C wormholes.\n"); printf(" -x Do not print info on stars generated.\n"); printf("\n"); return 0; } else { switch (argv[i][1]) { case 'a': autoname_star = 1; break; case 'b': autoname_plan = 1; break; case 'd': use_smashup = 1; break; case 'e': ++i; planetlesschance = atoi(argv[i]); break; case 'l': ++i; minplanets = atoi(argv[i]); break; case 'm': ++i; maxplanets = atoi(argv[i]); break; case 'p': printpostscript = 1; break; case 's': ++i; nstars = atoi(argv[i]); break; case 'v': printplaninfo = 0; break; case 'x': printstarinfo = 0; break; case 'w': ++i; wormholes = atoi(argv[i]); break; default: printf("\n"); printf("Unknown option \"%s\".\n", argv[i]); printf("\n"); printf("Usage: makeuniv [-a] [-b] [-e E] [-l MIN] [-m MAX] "); printf("[-s N] [-v] [-w C] [-x]\n"); printf(" -a Autoload star names.\n"); printf(" -b Autoload planetnames.\n"); printf(" -d Use smashup (asteroid impact) routines.\n"); printf(" -e E Make E%% of stars have no planets.\n"); printf(" -l MIN Other systems will have at least MIN planets.\n"); printf(" -m MAX Other systems will have at most MAX planets.\n"); printf(" -p Create postscript map file of the universe.\n"); printf(" -s N The universe will have N stars.\n"); printf(" -v Do not print info and map of planets generated.\n"); printf(" -w C The universe will have C wormholes.\n"); printf(" -x Do not print info on stars generated.\n"); printf("\n"); return 0; } } } /* * Get values for all the switches that still don't have good values. */ if (autoname_star == -1) { printf("\nDo you wish to use the file \"%s\" for star names? [y/n]> ", STARLIST); c = getchr(); if (c != '\n') { getchr(); } autoname_star = (c == 'y'); } if (autoname_plan == -1) { printf("\nDo you wish to use the file \"%s\" for planet names? [y/n]> ", PLANETLIST); c = getchr(); if (c != '\n') { getchr(); } autoname_plan = (c == 'y'); } if (use_smashup == -1) { printf("\nUse the smashup (asteroid impact) routines? [y/n]> "); c = getchr(); if (c != '\n') { getchr(); } use_smashup = (c == 'y'); } while ((nstars < 1) || (nstars >= NUMSTARS)) { printf("Number of stars [1-%d]:", NUMSTARS - 1); scanf("%d", &nstars); } while ((planetlesschance < 0) || (planetlesschance > 100)) { printf("Percentage of empty systems [0-100]:"); scanf("%d", &planetlesschance); } while ((minplanets <= 0) || (minplanets > absmaxplan)) { printf("Minimum number of planets per system [1-%d]:", absmaxplan); scanf("%d", &maxplanets); } while ((wormholes < 0) || (wormholes > nstars) || ((wormholes % 2) == 1)) { printf("Number of wormholes (muse be even number) [0-%d]:", nstars); scanf("%d", &wormholes); } Makeplanet_init(); Makestar_init(); Sdata.numstars = nstars; sprintf(str, "/bin/mkdir -p %s", DATADIR); system(str); planetdata = fopen(PLANETDATAFL, "w+"); if (planetdata == NULL) { printf("Unable to open planet data file \"%s\"\n", PLANETDATAFL); return -1; } sectordata = fopen(SECTORDATAFL, "w+"); if (sectordata == NULL) { printf("Unable to open sector data file \"%s\"\n", SECTORDATAFL); return -1; } if (printstarinfo || printplaninfo) { outputtxt = fopen(OUTPUTFILE, "w+"); if (outputtxt == NULL) { printf("Unable to open \"%s\" for output.\n", OUTPUTFILE); return -1; } } if (!wormholes) { whcnt = 0; } else { whcnt (int)(nstars / wormholes) - 1; } wormidx = 0; for (star = 0; star < nstars; ++star) { Stars[star] = Makestar(planetdata, sectordata, outputtxt); xspeed[star] = 0; yspeed[star] = 0; Stars[star]->wh_has_wormhole = 0; Stars[star]->wh_dest_starnum = -1; Stars[star]->wh_stability = 0; /* * See if time to put a wormhole in */ if (!whcnt) { /* * Make a wormhole here. This adds a wormhole planet to this star. */ if (Stars[star]->numplanets == MAXPLANETS) { /* * Skip until a star as < MAXPLANETS */ whcnt = 0; continue; } else { if (!wormholes) { whcnt = 0; } else { whcnt = (int)(nstars / wormholes) - 1; } make_wormhole(Stars[star], planetdata, sectordata, outputtxt); w_holes[wormidx].star = Stars[star]; w_hoels[wormidx].num = star; ++wormidx; } } --whcnt; } /* * Data data files to group * readwrite */ chmod(PLANETDATAFL, 00660); fclose(planetdata); chmod(SECTORDATAFL, 00660); fclose(sectordata); /* * New Gardan code 21.12.1996 * Changed 27.8.1997: Displacement wasn't set before * * Start here */ total = nstars; nempty = round_rand(((double)nstars * (double)planetlesschance) / 100); /* * Amount of non-empty stars */ nstars -= nempty; rowcolumns = 0; while ((rowcolumns * rowcolumns) < (nstars / 2)) { ++rowcolumns; } /* * Unhandled squares */ squaresleft = rowcolumns * rowcolumns; starsleft = nstars - squaresleft; emptyrounds = 0; while (nempty > squaresleft) { ++emptyrounds; nempty -= squaresleft; } displacement = UNIVSIZE / rowcolumns; /* * Size of square */ for (x = 0; x < rowcolumns; ++x) { for (y = 0; y < rowcolumns; ++y) { /* * planetlesschance = 0; * Stars[starindex] = Makestar(planetdata, sectordata, outputtxt); * xspeed[starindex] = 0; * yspeed[starindex] = 0; */ Stars[starindex]->xpos = displacement * (x + (1.0 * double_rand())); Stars[starindex]->ypos = displacement * (y + (1.0 * double_rand())); ++starindex; z = int_rand(1, squaresleft); /* * If there is system with planet */ if (z <= starsleft) { /* * Stars[starindex] = * Makestar(planetdata, sectordata, outputtxt); * xspeed[starindex] = 0; * yspeec[starindex] = 0; */ Stars[starindex]->xpos = displacement * (x + (1.0 * double_rand())); Stars[starindex]->ypos = displacement * (y + (1.0 * double_rand())); --starsleft; ++starindex; } /* * If there is planetless system */ if (x <= nempty) { /* * planetlesschance = 100; * Stars[starindex] = * Makestar(planetdata, sectordata, outputtxt); * xspeed[starindex] = 0; * yspeed[starindex] = 0; */ Stars[starindex]->xpos = displacement * (x + (1.0 * double_rand())); Stars[starindex]->ypos = displacement * (y + (1.0 * double_rand())); /* * sprintf(Stars[starindex]->name, "E%d_%d", x, y); */ /* * Added -mfw */ strcpy(Stars[starindex]->name, NextStarName()); --nempty; ++starindex; } /* * Planetless systems equal to all squares */ for (z = 0; z < emptyrounds; ++z) { /* * planetlesschance = 100; * Stars[starindex] = * Makestar(planetdata, sectordata, outputtxt); * xspeed[starindex] = 0; * yspeed[starindex] = 0; */ Stars[starindex]->xpos = displacement * (x + (1.0 * double_rand())); Stars[starindex]->ypos = displacement * (y + (1.0 * double_rand())); /* * sprintf(Stars[starindex]->name, "E%d_%d", x, y); */ /* * Added -mfw */ strcpy(Stars[starindex]->name, NextStarName()); ++starindex; } --squaresleft; } } /* * Checks if two stars are too close */ z = 1; while (z) { z = 0; for (x = 2; x < total; ++x) { for (y = x + 1; y < total; ++y) { dist = sqrt(Distsq(Stars[x]->xpos, Stars[x]->ypos, Stars[x]->xpos, Stars[x]->ypos)); if (dist < (4 * SYSTEMSIZE)) { z = 1; if (stars[x]->ypos > Stars[y]->ypos) { Stars[x]->ypos += (4 * SYSTEMSIZE); } else { Stars[y]->ypos += (4 * SYSTEMSIZE); } } } } } for (x = 0; x < starindex; ++x) { if (Stars[x]->xpos > UNIVSIZE) { Stars[x]->xpos -= UNIVSIZE; } if (Stars[x]->ypos > UNIVSIZE) { Stars[x]->ypos -= UNIVSIZE; } } /* * End Gardan code */ /* * Calculate worm hole destinations */ for (x = 1; x < wormidx; x += 2) { w_holes[x].star->wh_dest_starnum = w_holes[x - 1].num; w_holes[x - 1].star->wh_dest_starnum = w_holes[x].num; if (printstarinfo) { fprintf(outputtxt, "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n", x - 1, w_holes[x - 1].star->wh_test_starnum, w_holes[x - 1].num, w_holes[x - 1].star->name, w_holes[x - 1].star->wh_stability); } if (printfstarinfo) { fprintf(outputtxt, "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n", x, w_holes[x].star->wh_dest_starnum, w_holes[x].num, w_holes[x].star->name, w_holes[x].star->wh_stability); } } if (((double)wormidx / 2) != ((int)wormidx / 2)) { /* * Odd number so last w_hole points to #1 no return */ w_holes[wormidx - 1].star->wh_dest_starnum = w_holes[0].num; if (printstarinfo) { fprintf(outputtxt, "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n", wormidx - 1, w_holes[wormidx - 1].star->wh_dest_starnum, w_holes[wormidx - 1].num, w_holes[wormidx - 1].star->name, w_holes[wormidx - 1].star->wh_stability); } } if (printstarinfo) { fprintf(outputtxt, "Total Wormholes: %d\n", wormidx); } #if 0 /* * Old code starts */ /* * Try to more evenly space stars. Essentially this is an inverse-gravity * calculation: The nearer two stars are to each other, the more they * repulse each other. Several iterations of this will suffice to move all * of the stars nicely apart. */ CLUSTER_COUNTER = 6; STAR_COUNTER = 1; dist = CLUSTER_FROM_CENTER; for (its = 1; its <= 6; ++its) { /* * Circle of stars */ fprintf(outputtxt, "Grouping [%f]", dist); for (clusters = 1; clusters <= CLUSTER_COUNTER; ++clusters) { /* * Number of clusters in circle */ for (starsinclus = 1; starsinclus <= STAR_COUNTER; ++starsinclus) { /* * Number of stars in cluster */ ange = 2.0 * M_PI * ANGLE; cluster_delta_x = int_rand(CLUSTER_STAR_MIN, CLUSTER_STAR_MAX); cluster_delta_y = int_rand(CLUSTER_STAR_MIN, CLUSTER_STAR_MAX); clusterx = dist * sin(angle); clustery = dist * cos(angle); if (starindex >= Sdatanumstars) { flag = 1; break; } fprintf(outputtxt, " %s ", Stars[starindex]->name); if ((its == 1) || (its == 3) || (its == 6)) { setbit(Stars[starindex]->explored, 1); setbit(Stars[starindex]->inhabited, 1); } Stars[starindex]->xpos = clusterx + cluster_delta_x; Stars[starindex]->ypos = clustery + cluster_delta_y; ANGLE = (ANGLE + 0.15) + double_rand(); fprintf(outputtxt, "ANGLE 1 %f\n", ANGLE); ++starindex; } } if (flag) { break; } switch (its + 1) { case 2: ANGLE = 0.20 + double_rand(); CLUSTER_COUNTER = 10; dist += 25000; break; case 3: ANGLE = 0.35 + double_rand(); CLUSTER_COUNTER = 13; dist += 27000; break; case 4: ANGLE = 0.40 + double_rand(); CLUSTER_COUNTER = 15; dist += 27000; break; case 5: ANGLE = 0.25 + double_rand(); CLUSTER_COUNTER = 17; dist += 32000; break; case 6: ANGLE = 0.12 + double_rand(); CLUSTER_COUNTER = 17; dist += 32000; break; } fprintf(outputtxt, "\n\n"); fprintf(outputtxt, "ANGLE 2 %f\n", ANGLE); } Stars[0]->xpos = 0; Stars[0]->ypos = 0; strcpy(Stars[0]->name, "Bambi"); #endif stardata = fopen(STARDATAFL, "w+"); if (stardata == NULL) { printf("Unable to open star data file \"%s\"\n", STARDATAFL); return 01; } fwrite(&Sdata, sizeof(Sdata), 1, stardata); for (star = 0; star < Sdata.numstars; ++star) { fwrite(Stars[star], sizeof(startype), 1, stardata); } chmod(STARDATAFL, 00660); fclose(stardata); EmptyFile(SHIPDATAFL); EmptyFile(SHIPFREEDATAFL); EmptyFile(COMMODDATAFL); EmptyFile(COMMODFREEDATAFL); EmptyFile(PLAYERDATAFL); EmptyFile(RACEDATAFL); memset((char *)power, 0, sizeof(power)); InitFile(POWFL, power, sizeof(power)); memset((char *)block, 0, sizeof(block)); Initfile(BLOCKDATAFL, block, sizeof(block)); /* * Telegram files: directory and a file for each player. */ sprintf(str, "/bin/mkdir -p %s", MSGDIR); system(str); chmod(MSGDIR, 00770); #if 0 /* * Why is this not needed anymore? */ for (i = 1; i < MAXPLAYERS; ++i) { sprintf(str, "%s.%d", TELEGRAMFL, i); Empyfile(str); } #endif /* * News files: directory and the 4 types of news. */ sprintf(str, "/bin/mkdir -p %s", NEWSDIR); system(str); chmod(NEWSDIR, 00770); EmptyFile(DECLARATIONFL); EmptyFile(TRANSFERFL); EmptyFile(COMBATFL); EmptyFile(ANNOUNCEFL); if (printstarinfo) { PrintStatistics(outputtxt); } if (printpostscript) { produce_postscript(DEFAULT_POSTSCRIPT_MAP_FILENAME); } printf("Universe Created!\n"); if (printstarinfo || printplaninfo) { printf("Summary output written to %s\n", OUTPUTFILE); fclose(outputtxt); } return 0; }
void do_pod(shiptype *ship) { int starsys; int planetno; memset((char *)buf, 0, sizeof(buf)); if (ship->popn != 0) { if (ship->whatorbits == LEVEL_STAR) { if (ship->special.pod.temperature >= POD_THRESHOLD) { starsys = ship->storbits; planetno = int_rand(0, (int)Stars[starsys]->numplanets - 1); sprintf(telegram_buf, "%s has warmed and exploded at %\n", Ship(ship), prin_ship_orbits(ship)); /* Seed passes through wormhole */ if (Stars[starsys]->wh_has_wormhole && (planetno == (Stars[starsys]->numplanets - 1))) { planets[starsys][planetno]->info[ship->owner - 1].explored = 1; starsys = Stars[starsys]->wh_dest_starnum; planetno = int_rand(0, (int)Stars[starsys]->numplanets - 2); sprintf(buf, " The spores traversed a wormhole to %s.\n", Stars[starsys]->name); strcat(telegram_buf, buf); } if (infect_planet((int)ship->type, (int)ship->owner, starsys, planetno)) { sprintf(buf, " Meta-colony established on %s.", Stars[starsys]->pnames[planetno]); } else { sprintf(buf, " No spores have survived."); } strcat(telegram_buf, buf); push_telegram((int)ship->owner, (int)ship->governor, telegram_buf); kill_ship((int)ship->owner, ship); } else { /* pod.temp >= POD_THRESHOLD */ ship->special.pod.temperature += round_rand((double)Stars[ship->storbits]->temperature / (double)segments); } } else if (ship->whatorbits == LEVEL_PLAN) { if (ship->special.pod.decay >= POD_DECAY) { starsys = ship->storbits; planetno = ship->pnumorbits; sprintf(telegram_buf, "%s has decayed at %s\n", Ship(ship), prin_ship_orbits(ship)); /* Seed passes through wormhole */ if (Stars[starsys]->wh_has_wormhole && (planetno == (Stars[starsys]->numplanets - 1))) { starsys = Stars[starsys]->wh_dest_starnum; planetno = int_rand(0, (int)Stars[starsys]->numplanets - 2); sprintf(buf, " The spores traversed a wormhole to %s.\n", Stars[starsys]->name); strcat(telegram_buf, buf); } if (infect_planet((int)ship->type, (int)ship->owner, starsys, planetno)) { sprintf(buf, " Meta-colony established on %s.", Stars[starsys]->pnames[planetno]); } else { sprintf(buf, " No spores have survived."); } strcat(telegram_buf, buf); push_telegram((int)ship->owner, (int)ship->governor, telegram_buf); kill_ship((int)ship->owner, ship); } else { /* decay > POD_DECAY */ ship->special.pod.decay += round_rand(1.0 / (double) segments); } } } else { /* If no population on board, don't infect! --jpd-- */ /* Don't decay if military on board. */ if (!ship->troops) { sprintf(telegram_buf, "%s has no population and has decayed at %s\n", Ship(ship), prin_ship_orbits(ship)); push_telegram((int)ship->owner, (int)ship->governor, telegram_buf); kill_ship((int)ship->owner, ship); } } /* If ship->popn != 0 --jpd -- */ }
void do_mirror(shiptype *ship) { switch (ship->special.aimed_at.level) { case LEVEL_SHIP: /* ship aimed at is a legal ship now */ /* if in the same system */ if ( (ship->whatorbits==LEVEL_STAR || ship->whatorbits==LEVEL_PLAN) && (ships[ship->special.aimed_at.shipno]!=NULL) && (ships[ship->special.aimed_at.shipno]->whatorbits==LEVEL_STAR || ships[ship->special.aimed_at.shipno]->whatorbits==LEVEL_PLAN) && ship->storbits == ships[ship->special.aimed_at.shipno]->storbits && ships[ship->special.aimed_at.shipno]->alive ) { shiptype *s; reg int i; double range; s = ships[ship->special.aimed_at.shipno]; range = sqrt(Distsq(ship->xpos, ship->ypos,s->xpos,s->ypos)); i = int_rand(0,round_rand((2./((double)(Body(s)))) *(double)(ship->special.aimed_at.intensity)/(range/PLORBITSIZE+1.0))); sprintf(telegram_buf, "%s aimed at %s\n", Ship(ship), Ship(s)); s->damage += i; if(i) { sprintf(buf, "%d%% damage done.\n",i); strcat(telegram_buf, buf); } if (s->damage >= 100) { sprintf(buf, "%s DESTROYED!!!\n",Ship(s)); strcat(telegram_buf, buf); kill_ship((int)(ship->owner), s); } push_telegram((int)s->owner, (int)s->governor, telegram_buf); push_telegram((int)ship->owner, (int)ship->governor, telegram_buf); } break; case LEVEL_PLAN: { reg int i; double range; range = sqrt(Distsq(ship->xpos, ship->ypos, Stars[ship->storbits]->xpos +planets[ship->storbits][ship->pnumorbits]->xpos, Stars[ship->storbits]->ypos +planets[ship->storbits][ship->pnumorbits]->ypos)); if ( range > PLORBITSIZE ) i = PLORBITSIZE * ship->special.aimed_at.intensity/range; else i = ship->special.aimed_at.intensity; i = round_rand(.01*(100.0-(double)(ship->damage))*(double)i); Stinfo[ship->storbits][ship->special.aimed_at.pnum].temp_add += i; } break; case LEVEL_STAR: { /* have to be in the same system as the star; otherwise it's not too fair.. */ if (ship->special.aimed_at.snum>0 && ship->special.aimed_at.snum < Sdata.numstars && ship->whatorbits > LEVEL_UNIV && ship->special.aimed_at.snum == ship->storbits) Stars[ship->special.aimed_at.snum]->stability += random()&01; } break; case LEVEL_UNIV: break; } }
void doship(shiptype *ship, int update) { racetype *Race; shiptype *ship2; /*ship is active */ ship->active = 1; if(!ship->owner) ship->alive = 0; if (ship->alive) { /* repair radiation */ if (ship->rad) { ship->active = 1; /* irradiated ships are immobile.. */ /* kill off some people */ /* check to see if ship is active */ if(success(ship->rad)) ship->active = 0; if(update) { ship->popn = round_rand(ship->popn * .80); ship->troops = round_rand(ship->troops * .80); if (ship->rad >= (int)REPAIR_RATE) ship->rad -= int_rand(0,(int)REPAIR_RATE); else ship->rad -= int_rand(0,(int)ship->rad); } } else ship->active = 1; if(!ship->popn && Max_crew(ship) && !ship->docked) ship->whatdest = LEVEL_UNIV; if (ship->whatorbits != LEVEL_UNIV && Stars[ship->storbits]->nova_stage>0) { /* damage ships from supernovae */ /* Maarten: modified to take into account MOVES_PER_UPDATE */ ship->damage += 5 * Stars[ship->storbits]->nova_stage / ((Armor(ship)+1) * segments); if (ship->damage >= 100) { kill_ship((int)(ship->owner), ship); return; } } if(ship->type==OTYPE_FACTORY && !ship->on) { Race = races[ship->owner-1]; ship->tech = Race->tech; } if(ship->active) Moveship(ship, update, 1, 0); ship->size = ship_size(ship); /* for debugging */ if(ship->whatorbits==LEVEL_SHIP) { (void)getship(&ship2, (int)ship->destshipno); if(ship2->owner != ship->owner) { ship2->owner = ship->owner; ship2->governor = ship->governor; putship(ship2); } free(ship2); /* just making sure */ } else if(ship->whatorbits != LEVEL_UNIV && (ship->popn || ship->type == OTYPE_PROBE)) { /* Though I have often used TWCs for exploring, I don't think it is right */ /* to be able to map out worlds with this type of junk. Either a manned ship, */ /* or a probe, which is designed for this kind of work. Maarten */ StarsInhab[ship->storbits] = 1; setbit(Stars[ship->storbits]->inhabited, ship->owner); setbit(Stars[ship->storbits]->explored, ship->owner); if(ship->whatorbits == LEVEL_PLAN) { planets[ship->storbits][ship->pnumorbits]->info[ship->owner-1].explored = 1; } } /* add ships, popn to total count to add AP's */ if(update) { Power[ship->owner-1].ships_owned++; Power[ship->owner-1].resource += ship->resource; Power[ship->owner-1].fuel += ship->fuel; Power[ship->owner-1].destruct += ship->destruct; Power[ship->owner-1].popn += ship->popn; Power[ship->owner-1].troops += ship->troops; } if (ship->whatorbits==LEVEL_UNIV) { Sdatanumships[ship->owner-1]++; Sdatapopns[ship->owner] += ship->popn; } else { starnumships[ship->storbits][ship->owner-1]++; /* add popn of ships to popn */ starpopns[ship->storbits][ship->owner-1] += ship->popn; /* set inhabited for ship */ /* only if manned or probe. Maarten */ if (ship->popn || ship->type==OTYPE_PROBE) { StarsInhab[ship->storbits] = 1; setbit(Stars[ship->storbits]->inhabited, ship->owner); setbit(Stars[ship->storbits]->explored, ship->owner); } } if (ship->active) { /* bombard the planet */ if (can_bombard(ship) && ship->bombard && ship->whatorbits==LEVEL_PLAN && ship->whatdest==LEVEL_PLAN && ship->deststar== ship->storbits && ship->destpnum== ship->pnumorbits) { /* ship bombards planet */ Stinfo[ship->storbits][ship->pnumorbits].inhab = 1; } /* repair ship by the amount of crew it has */ /* industrial complexes can repair (robot ships and offline factories can't repair) */ if(ship->damage && Repair(ship)) do_repair(ship); if(update) switch (ship->type) { /* do this stuff during updates only*/ case OTYPE_CANIST: do_canister(ship); break; case OTYPE_GREEN: do_greenhouse(ship); break; case STYPE_MIRROR: do_mirror(ship); break; case STYPE_GOD: do_god(ship); break; case OTYPE_AP: do_ap(ship); break; case OTYPE_VN: /* Von Neumann machine */ case OTYPE_BERS: if(!ship->special.mind.progenitor) ship->special.mind.progenitor = 1; do_VN(ship); break; case STYPE_OAP: do_oap(ship); break; case STYPE_HABITAT: do_habitat(ship); break; default: break; } if(ship->type==STYPE_POD) do_pod(ship); } } }
void insurgency(int Playernum, int Governor, int APcount) { int who, amount, eligible, them=0; racetype *Race, *alien; planettype *p; double x; int changed_hands, chance; register int i; if(Dir[Playernum-1][Governor].level != LEVEL_PLAN) { notify(Playernum, Governor, "You must 'cs' to the planet you wish to try it on.\n"); return; } if(!control(Playernum, Governor, Stars[Dir[Playernum-1][Governor].snum])) { notify(Playernum, Governor, "You are not authorized to do that here.\n"); return; } /* if(argn<3) { notify(Playernum, Governor, "The correct syntax is 'insurgency <race> <money>'\n"); return; }*/ if(!enufAP(Playernum,Governor, Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) return; if(!(who=GetPlayer(args[1]))) { sprintf(buf,"No such player.\n"); notify(Playernum, Governor, buf); return; } Race = races[Playernum-1]; alien = races[who-1]; if(alien->Guest) { notify(Playernum, Governor, "Don't be such a dickweed.\n"); return; } if(who==Playernum) { notify(Playernum, Governor, "You can't revolt against yourself!\n"); return; } eligible = 0; them = 0; for(i=0; i<Stars[Dir[Playernum-1][Governor].snum]->numplanets; i++) { getplanet(&p,Dir[Playernum-1][Governor].snum,i); eligible += p->info[Playernum-1].popn; them += p->info[who-1].popn; free(p); } if(!eligible) { notify(Playernum, Governor, "You must have population in the star system to attempt insurgency\n."); return; } getplanet(&p,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum); if(!p->info[who-1].popn) { notify(Playernum, Governor, "This player does not occupy this planet.\n"); free(p); return; } sscanf(args[2], "%d", &amount); if(amount < 0) { notify(Playernum, Governor, "You have to use a positive amount of money.\n"); free(p); return; } if(Race->governor[Governor].money < amount) { notify(Playernum, Governor, "Nice try.\n"); free(p); return; } x = INSURG_FACTOR*(double)amount* (double)p->info[who-1].tax/(double)p->info[who-1].popn; x *= morale_factor((double)(Race->morale-alien->morale)); x *= morale_factor((double)(eligible-them)/50.0); x *= morale_factor(10.0*(double)(Race->fighters*p->info[Playernum-1].troops- alien->fighters*p->info[who-1].troops))/50.0; sprintf(buf, "x = %f\n", x); notify(Playernum, Governor, buf); chance = round_rand(200.0*atan((double)x)/3.14159265); sprintf(long_buf, "%s/%s: %s [%d] tries insurgency vs %s [%d]\n", Stars[Dir[Playernum-1][Governor].snum]->name, Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum], Race->name, Playernum, alien->name, who); sprintf(buf, "\t%s: %d total civs [%d] opposing %d total civs [%d]\n", Stars[Dir[Playernum-1][Governor].snum]->name, eligible, Playernum, them, who); strcat(long_buf, buf); sprintf(buf, "\t\t %ld morale [%d] vs %ld morale [%d]\n", Race->morale, Playernum, alien->morale, who); strcat(long_buf, buf); sprintf(buf, "\t\t %d money against %ld population at tax rate %d%%\n", amount, p->info[who-1].popn, p->info[who-1].tax); strcat(long_buf, buf); sprintf(buf, "Success chance is %d%%\n", chance); strcat(long_buf, buf); if(success(chance)) { changed_hands = revolt(p, who, Playernum); notify(Playernum, Governor, long_buf); sprintf(buf, "Success! You liberate %d sector%s.\n", changed_hands, (changed_hands == 1)?"":"s"); notify(Playernum, Governor, buf); sprintf(buf, "A revolt on /%s/%s instigated by %s [%d] costs you %d sector%s\n", Stars[Dir[Playernum-1][Governor].snum]->name, Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum], Race->name, Playernum, changed_hands, (changed_hands == 1)?"":"s"); strcat(long_buf, buf); warn(who, (int)Stars[Dir[Playernum-1][Governor].snum]->governor[who-1], long_buf); p->info[Playernum-1].tax = p->info[who-1].tax; /* you inherit their tax rate (insurgency wars he he ) */ sprintf(buf, "/%s/%s: Successful insurgency by %s [%d] against %s [%d]\n", Stars[Dir[Playernum-1][Governor].snum]->name, Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum], Race->name, Playernum, alien->name, who); post(buf, DECLARATION); } else { notify(Playernum, Governor, long_buf); notify(Playernum, Governor, "The insurgency failed!\n"); sprintf(buf, "A revolt on /%s/%s instigated by %s [%d] fails\n", Stars[Dir[Playernum-1][Governor].snum]->name, Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum], Race->name, Playernum); strcat(long_buf, buf); warn(who, (int)Stars[Dir[Playernum-1][Governor].snum]->governor[who-1], long_buf); sprintf(buf, "/%s/%s: Failed insurgency by %s [%d] against %s [%d]\n", Stars[Dir[Playernum-1][Governor].snum]->name, Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum], Race->name, Playernum, alien->name, who); post(buf, DECLARATION); } deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0); Race->governor[Governor].money -= amount; putrace(Race); free(p); }