Exemple #1
0
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);
        }
    }
}
Exemple #2
0
void do_canister(shiptype *ship)
{
    if (ship->whatorbits == LEVEL_PLAN && !landed(ship)) {
        if (++ship->special.timer.count < DISSIPATE) {
            if ( Stinfo[ship->storbits][ship->pnumorbits].temp_add < -90 )
                Stinfo[ship->storbits][ship->pnumorbits].temp_add = -100;
            else
                Stinfo[ship->storbits][ship->pnumorbits].temp_add -= 10;
        } else {	/* timer expired; destroy canister */
            reg int j=0;
            kill_ship((int)(ship->owner), ship);
            sprintf(telegram_buf, "Canister of dust previously covering %s has dissipated.\n",
                    prin_ship_orbits(ship));
            for (j=1; j<=Num_races; j++)
                if (planets[ship->storbits][ship->pnumorbits]->info[j-1].numsectsowned)
                    push_telegram(j, (int)Stars[ship->storbits]->governor[j-1],
                                  telegram_buf);
        }
    }
}
Exemple #3
0
void scrap(int playernum, int governor, int apcount)
{
    planettype *planet;
    sectortype *sect;
    shiptype *s;
    shiptype *s2;
    int shipno;
    int nextshipno;
    int scrapval = 0;
    int destval = 0;
    int crewval = 0;
    int max_crew = 0;
    int xtalval = 0;
    int troopval = 0;
    int max_resource = 0;
    int max_mil = 0;
    int max_fuel = 0;
    int max_destruct = 0;
    int cost = 0;
    double fuelval = 0.0;
    racetype *race;

    if (argn < 2) {
        notify(playernum, governor, "Scrap what?\n");

        return;
    }

    nextshipno = start_shiplist(playernum, governor, args[1]);
    race = races[playernum - 1];

    if (race->Guest) {
        notify(playernum, governor, "Guest races cannot scrap ships\n");

        return;
    }

    shipno = do_shiplist(&s, &nextshipno);

    while (shipno) {
        if (in_list(playernum, args[1], s, &nextshipno)) {
#ifdef USE_VN
            if ((s->type == OTYPE_VN) || (s->type == OTYPE_BERS)) {
                notify(playernum, governor, "VNs will not scrap themselves.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }
#endif

            if (s->max_crew && !s->popn) {
                notify(playernum,
                       governor,
                       "Can't scrap that ship - no crew.\n");

                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                /*
                 * Used to not allow scrapping at the UNIV level for
                 * anything. However, I'm going to permit pods. This is so pod
                 * races can clean up their messes. I'm not going to charge APs
                 * at the UNIV scope either. -mfw
                 */
                if (s->type) {
                    apcount = 0;
                } else {
                    notify(playernum,
                           governor,
                           "Can't scrap at the ship's scope.\n");

                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            } else if (!enufAP(playernum, governor, Stars[s->storbits]->AP[playernum - 1], apcount)) {
                notify(playernum, governor, "Not enough APs to scrap.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* HUTm (kse) wc's can't be scrapped inside of ship anymore */
            if (inship(s) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "Can't scrap waste canisters inside of other ship.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* Ships that have other ships in the hangar can't scrap *mfw */
            if (s->ships) {
                sprintf(buf,
                        "There are other ships in the hangar; scrap those first.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if ((s->whatorbits == LEVEL_PLAN) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "WARNING: This releases %d toxin points back into the atmosphere!!!\n",
                        s->special.waste.toxic);

                notify(playernum, governor, buf);
            }

            if (!s->docked) {
                sprintf(buf,
                        "%s is not landed or docked.\nNo resources can be reclaimed.\n",
                        Ship(s));

                notify(playernum, governor, buf);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                /* wc's release poison */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s)) {
                    if (!getsector(&sect, planet, (int)s->land_x, (int)s->land_y)) {
                        notify(playernum,
                               governor,
                               "Error in sector database, notify deity.\n");

                        free(s);

                        return;
                    }
                }
            }

            if (docked(s) || inship(s)) {
                if (!getship(&s2, (int)s->destshipno)) {
                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }

                if ((!s2->docked || (s2->destshipno != s->number))
                    && (!s->whatorbits == LEVEL_SHIP)) {
                    sprintf(buf, "Warning, other ship not docked...\n");
                    notify(playernum, governor, buf);
                    free(s);
                    free(s2);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            }

            if (s->type == OTYPE_FACTORY) {
                cost = (2 * s->build_code * s->on) + Shipdata[s->type][ABIL_COST];
            } else {
                cost = s->build_cost;
            }

            scrapval = (cost / 2) + s->resource;

            if (s->docked) {
                sprintf(buf, "%s: original cost: %ld\n", Ship(s), cost);
                notify(playernum, governor, buf);

                sprintf(buf,
                        "         scrap value%s: %d rp's.\n",
                        s->resource ? "(with stockpile) " : "",
                        scrapval);

                notify(playernum, governor, buf);

                /* New code by Kharush. check for STYPE_DHUTTLE added. */
                /* I've removed it, Dhuttle was silly -mfw */

                if (s2->type == OTYPE_FACTORY) {
                    max_resource = Shipdata[s2->type][ABIL_CARGO];
                    max_fuel = Shipdata[s2->type][ABIL_FUELCAP];
                    max_destruct = Shipdata[s2->type][DESTCAP];
                } else {
                    max_resource = s2->max_resource;
                    max_fuel = s2->max_fuel;
                    max_destruct = s2->max_destruct;
                }

                if ((s->whatdest == LEVEL_SHIP)
                    && ((s2->resource + scrapval) > max_resource)
                    && (s2->type != STYPE_SHUTTLE)) {
                    scrapval = max_resource - s2->resource;
                    sprintf(buf,
                            "(There is only room for %d resources.)\n",
                            scrapval);

                    notify(playernum, governor, buf);
                }

                if (s->fuel) {
                    sprintf(buf, "Fuel recover: %.0f.\n", s->fuel);
                    notify(playernum, governor, buf);
                    fuelval = s->fuel;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->fuel + fuelval) > max_fuel)) {
                        fuelval = max_fuel - s2->fuel;
                        sprintf(buf,
                                "(There is only room for %.2f fuel.)\n",
                                fuelval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    fuelval = 0.0;
                }

                if (s->destruct) {
                    sprintf(buf, "Armament recovery: %d.\n", s->destruct);
                    notify(playernum, governor, buf);
                    destval = s->destruct;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->destruct + destval) > max_destruct)) {
                        destval = max_destruct - s2->destruct;
                        sprintf(buf,
                                "(There is only room for %d destruct.)\n",
                                destval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    destval = 0;
                }

                if (s->popn + s->troops) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crew can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        troopval = s->troops;

                        if (s2->type == OTYPE_FACTORY) {
                            max_mil = Shipdata[s2->type][ABIL_MAXCREW] - s->popn;
                        } else {
                            max_mil = s2->max_crew - s2->popn;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->troops + troopval) > max_mil)) {
                            troopval = max_mil - s2->troops;
                            sprintf(buf,
                                    "(There is only room for %d troops.)\n",
                                    troopval);

                            notify(playernum, governor, buf);
                        }

                        crewval = s->popn;

                        if (s2->type == OTYPE_FACTORY) {
                            max_crew = Shipdata[s2->type][ABIL_MAXCREW] - s2->troops;
                        } else {
                            max_crew = s2->max_crew - s2->troops;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->popn + crewval) > max_crew)) {
                            crewval = max_crew - s2->popn;
                            sprintf(buf,
                                    "(There is only room for %d crew.)\n",
                                    crewval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf,
                                "Population/Troops recover: %d/%d.\n",
                                crewval,
                                troopval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    crewval = 0;
                    troopval = 0;
                }

                if (s->crystals + s->mounted) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crystals can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        xtalval = s->crystals + s->mounted;

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->crystals + xtalval) > 127)) {
                            xtalval = 127 - s2->crystals;
                            sprintf(buf,
                                    "(There is only room for %d crystals.)\n",
                                    xtalval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf, "Crystal recover: %d.\n", xtalval);
                        notify(playernum, governor, buf);
                    }
                } else {
                    xtalval = 0;
                }
            }

            /* More adjustments needed here for hangar. Maarten */
            if (s->whatorbits == LEVEL_SHIP) {
                s2->hangar -= (unsigned short)s->size;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                deductAPs(playernum, governor, apcount, 0, 1);
            } else {
                deductAPs(playernum, governor, apcount, (int)s->storbits, 0);
            }

            if (docked(s) || inship(s)) {
                s2->crystals += xtalval;
                rcv_fuel(s2, (double)fuelval);
                rcv_destruct(s2, destval);
                rcv_resource(s2, scrapval);
                rcv_troops(s2, troopval, race->mass);
                rcv_popn(s2, crewval, race->mass);

                /*
                 * Check for docking status in case scrapped ship is
                 * landed. Maarten
                 */
                if (s->whatorbits != LEVEL_SHIP) {
                    s2->docked = 0; /* Undock the surviving ship */
                    s2->whatdest = LEVEL_UNIV;
                    s2->destshipno = 0;
                }

                putship(s2);
                free(s2);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                free(planet); /* this has already been allocated */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s) || inship(s)) {
                    /*
                     * If colonizing the sector, set sector owner and give a
                     * message it's also nice to check if there is anyone to
                     * colonize
                     */
                    if ((sect->owner == 0)
                        && ((troopval > 0) || (crewval > 0))) {
                        sect->owner = playernum;
                        ++planet->info[playernum - 1].numsectsowned;
                        sprintf(buf,
                                "Sector %d,%d Colonized.\n",
                                s->land_x,
                                s->land_y);

                        notify(playernum, governor, buf);
                    }

                    /* Increase sector's crew and troop count */
                    sect->troops += troopval;
                    sect->popn += crewval;

                    /*
                     * Increase planet's crew, troop, res, tec. count for this
                     * player
                     */
                    planet->info[playernum - 1].popn += crewval;
                    planet->info[playernum - 1].troops += troopval;

                    /*
                     * New code by Kharush. Scrapping does not anymore overflow
                     * stockpiles.
                     */
                    if ((planet->info[playernum - 1].resource + scrapval) <= USHRT_MAX) {
                        planet->info[playernum - 1].resource += scrapval;
                    } else {
                        planet->info[playernum - 1].resource = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d resources.\n",
                                USHRT_MAX - planet->info[playernum - 1].resource);

                        notify(playernum, governor, buf);
                    }

                    if ((playernum->info[playernum - 1].fuel + fuelval) <= USHRT_MAX) {
                        planet->info[playernum - 1].fuel += fuelval;
                    } else {
                        planet->info[playernum - 1].fuel = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d fuel.\n",
                                USHRT_MAX - planet->info[playernum - 1].fuel);

                        notify(playernum, governor, buf);
                    }

                    if ((planet->info[playernum - 1].destruct + destval) <= USHRT_MAX) {
                        planet->info[playernum - 1].destruct += destval;
                    } else {
                        planet->info[playernum - 1].destruct = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d destruct.\n",
                                USHRT_MAX - planet->info[playernum - 1].destruct);

                        notify(playernum, governor, buf);
                    }

                    /*
                     * Old code
                     *
                     * planet->info[playernum - 1].resource += scrapval;
                     * planet->info[playernum - 1].destruct += destval;
                     * planet->info[playernum - 1].fuel += (int)fuelval;
                     */

                    plant->popn += crewval;
                    planet->info[playernum - 1].crystals += (int)xtalval;
                    putsector(sect, planet, (int)s->land_x, (int)s->land_y);
                    free(sect);
                }

                putplanet(planet, (int)s->storbits, (int)s->pnumorbits);
            }

            kill_ship(playernum, s);
            putship(s);
            free(s);

            if (landed(s)) {
                sprintf(buf, "\nScrapped.\n");
            } else {
                sprintf(buf, "\nDestroyed.\n");
            }

            notify(playernum, governor, buf);
        } else {
            free(s);
        }

        shipno = do_shiplist(&s, &nextshipno);
    }
}
Exemple #4
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 -- */
}
Exemple #5
0
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;
    }
}
Exemple #6
0
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);
        }
    }
}
Exemple #7
0
void domine(int shipno, int detonate)
{
    int sh,sh2,i;
    shiptype *s, *ship;
    planettype *planet;
    racetype *r;

    (void)getship(&ship, shipno);

    if(ship->type!=STYPE_MINE || !ship->alive || !ship->owner) {
        free(ship);
        return;
    }
    /* check around and see if we should explode. */
    if (ship->on || detonate) {
        int rad=0;
        double xd,yd,range;

        switch(ship->whatorbits) {
        case LEVEL_STAR:
            sh = Stars[ship->storbits]->ships;
            break;
        case LEVEL_PLAN:
            getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
            sh=planet->ships;
            free(planet);
            break;
        default:
            free(ship);
            return;
        }
        sh2 = sh;
        /* traverse the list, look for ships that
        are closer than the trigger radius... */
        rad = 0;
        if(!detonate) {
            r = races[ship->owner-1];
            while (sh && !rad) {
                (void)getship(&s, sh);
                xd = s->xpos - ship->xpos;
                yd = s->ypos - ship->ypos;
                range = sqrt(xd*xd + yd*yd);
                if( !isset(r->allied, s->owner) && (s->owner != ship->owner) &&
                        ( (int)range <= ship->special.trigger.radius) )
                    rad = 1;
                else
                    sh = s->nextship;
                free(s);
            }
        } else
            rad = 1;

        if (rad) {
            sprintf(buf, "%s detonated at %s\n",
                    Ship(ship), prin_ship_orbits(ship));
            post(buf, COMBAT);
            notify_star((int)ship->owner, (int)ship->governor, 0,
                        (int)ship->storbits, buf);
            sh = sh2 ;
            while (sh) {
                (void)getship(&s, sh);
                if (sh != shipno && s->alive &&
                        (s->type != OTYPE_CANIST) && (s->type!=OTYPE_GREEN)) {
                    rad = shoot_ship_to_ship(ship, s, (int)(ship->destruct), 0, 0,
                                             long_buf, short_buf);
                    if(rad>0) {
                        post(short_buf, COMBAT);
                        warn((int)s->owner, (int)s->governor, long_buf);
                        putship(s);
                    }
                }
                sh = s->nextship;
                free(s);
            }

            /* if the mine is in orbit around a planet, nuke the planet too! */
            if(ship->whatorbits==LEVEL_PLAN) {
                /* pick a random sector to nuke */
                reg int x,y,numdest;
                getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
                if(landed(ship)) {
                    x = ship->land_x;
                    y = ship->land_y;
                } else {
                    x=int_rand(0, (int)planet->Maxx-1);
                    y=int_rand(0, (int)planet->Maxy-1);
                }
                numdest=shoot_ship_to_planet(ship, planet,
                                             (int)(ship->destruct), x, y, 1, 0, LIGHT,
                                             long_buf, short_buf);
                putplanet(planet, (int)ship->storbits, (int)ship->pnumorbits);

                sprintf(telegram_buf, "%s", buf);
                if(numdest>0) {
                    sprintf(buf, " - %d sectors destroyed.",numdest);
                    strcat(telegram_buf, buf);
                }
                strcat(telegram_buf, "\n");
                for(i=1; i<=Num_races; i++)
                    if(Nuked[i-1])
                        warn(i, (int)Stars[ship->storbits]->governor[i-1],
                             telegram_buf);
                notify((int)(ship->owner), (int)ship->governor, telegram_buf);
                free(planet);
            }
            kill_ship((int)(ship->owner), ship);
        }
        putship(ship);
    }
    free(ship);
}
Exemple #8
0
void domissile(shiptype *ship)
{
    int sh2;
    int bombx, bomby, numdest, pdn, i;
    planettype *p;
    double dist;
    placetype where;

    if(!ship->alive || !ship->owner)  return;
    if(!ship->on || ship->docked) return;

    /* check to see if it has arrived at it's destination */
    if(ship->whatdest==LEVEL_PLAN && ship->whatorbits==LEVEL_PLAN &&
            ship->destpnum==ship->pnumorbits) {
        p=planets[ship->storbits][ship->pnumorbits];
        /* check to see if PDNs are present */
        pdn = 0;
        sh2 = p->ships;
        while(sh2 && !pdn) {
            if(ships[sh2]->alive && ships[sh2]->type==OTYPE_PLANDEF) {
                /* attack the PDN instead */
                ship->whatdest=LEVEL_SHIP;	/* move missile to PDN for attack */
                ship->xpos=ships[sh2]->xpos;
                ship->ypos=ships[sh2]->ypos;
                ship->destshipno = sh2;
                pdn = sh2;
            }
            sh2 = ships[sh2]->nextship;
        }
        if(!pdn) {
            if(ship->special.impact.scatter) {
                bombx = int_rand(1,(int)p->Maxx)-1;
                bomby = int_rand(1,(int)p->Maxy)-1;
            } else {
                bombx = ship->special.impact.x % p->Maxx;
                bomby = ship->special.impact.y % p->Maxy;
            }
            sprintf(buf, "%s dropped on sector %d,%d at planet %s.\n",
                    Ship(ship), bombx, bomby, prin_ship_orbits(ship));
            where.level = LEVEL_PLAN;
            where.snum = ship->storbits;
            where.pnum = ship->pnumorbits;

            numdest = shoot_ship_to_planet(ship, p, (int)ship->destruct,
                                           bombx, bomby, 1, 0, HEAVY,
                                           long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            kill_ship((int)ship->owner, ship);
            sprintf(buf, "%s dropped on %s.\n\t%d sectors destroyed.\n",
                    Ship(ship), prin_ship_orbits(ship), numdest);
            for (i=1; i<=Num_races; i++)
                if(p->info[i-1].numsectsowned && i!=ship->owner)
                    push_telegram(i, Stars[ship->storbits]->governor[i-1], buf);
            if(numdest) {
                sprintf(buf, "%s dropped on %s.\n", Ship(ship),
                        prin_ship_orbits(ship));
                post(buf, COMBAT);
            }
        }
    } else if(ship->whatdest==LEVEL_SHIP) {
        sh2=ship->destshipno;
        dist=sqrt(Distsq(ship->xpos, ship->ypos,
                         ships[sh2]->xpos, ships[sh2]->ypos));
        if(dist<=((double)ship->speed*STRIKE_DISTANCE_FACTOR
                  *(100.0-(double)ship->damage)/100.0)) {
            /* do the attack */
            (void)shoot_ship_to_ship(ship, ships[sh2], (int)ship->destruct, 0, 0,
                                     long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            push_telegram((int)ships[sh2]->owner, (int)ships[sh2]->governor,
                          long_buf);
            kill_ship((int)ship->owner, ship);
            post(short_buf, COMBAT);
        }
    }
}