示例#1
0
文件: mobiliz.c 项目: phreddrick/GB
void tax(int Playernum, int Governor, int APcount)
{
int sum_tax=0;
planettype *p;
racetype *Race;

if (Dir[Playernum-1][Governor].level!=LEVEL_PLAN) {
    sprintf(buf,"scope must be a planet.\n");
    notify(Playernum, Governor, buf);
    return;
}
if(!control(Playernum, Governor, Stars[Dir[Playernum-1][Governor].snum])) {
    notify(Playernum, Governor, "You are not authorized to do that here.\n");
    return;
}
Race = races[Playernum-1];
if(!Race->Gov_ship) {
    notify(Playernum, Governor, "You have no government center active.\n");
    return;
}
if(Race->Guest) {
    notify(Playernum, Governor, "Sorry, but you can't do this when you are a guest.\n");
    return;
}
if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
    return;
}

getplanet(&p,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);

if(argn < 2) {
    sprintf(buf, "Current tax rate: %d%%    Target: %d%%\n", 
	    p->info[Playernum-1].tax, p->info[Playernum-1].newtax);
    notify(Playernum, Governor, buf);
    free(p);
    return;
}

sum_tax = atoi(args[1]);

if (sum_tax > 100 || sum_tax < 0) {
    sprintf(buf,"Illegal value.\n");
    notify(Playernum, Governor, buf);
    free(p);
    return;
}
p->info[Playernum-1].newtax = sum_tax;
putplanet(p,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);

deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0);
notify(Playernum, Governor, "Set.\n");
free(p);
}
示例#2
0
文件: mobiliz.c 项目: phreddrick/GB
void mobilize(int Playernum, int Governor, int APcount)
{
int sum_mob=0;
planettype *p;

if (Dir[Playernum-1][Governor].level!=LEVEL_PLAN) {
    sprintf(buf,"scope must be a planet.\n");
    notify(Playernum, Governor, buf);
    return;
}
if(!control(Playernum, Governor, Stars[Dir[Playernum-1][Governor].snum])) {
    notify(Playernum, Governor, "You are not authorized to do this here.\n");
    return;
}
if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
    return;
}

getplanet(&p,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);

getsmap(Smap,p);

if(argn < 2) {
    sprintf(buf, "Current mobilization: %d    Quota: %d\n", 
	    p->info[Playernum-1].comread, p->info[Playernum-1].mob_set);
    notify(Playernum, Governor, buf);
    free(p);
    return;
}
sum_mob = atoi(args[1]);

if (sum_mob > 100 || sum_mob < 0) {
    sprintf(buf,"Illegal value.\n");
    notify(Playernum, Governor, buf);
    free(p);
    return;
}
p->info[Playernum-1].mob_set = sum_mob;
putplanet(p,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);
deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0);

free(p);
}
示例#3
0
文件: scrap.c 项目: tcadigan/gbII_6.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);
    }
}
示例#4
0
文件: cs.c 项目: tcadigan/gbII_6.0
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;
}
示例#5
0
static void do_analysis(int playernum,
                        int governor,
                        int thisplayer,
                        int mode,
                        int sector_type,
                        int starnum,
                        int planetnum)
{

    planettype *planet;
    sectortype *sect;
    racetype *race;
    int x;
    int y;
    int p;
    int i;
    double compat;
    struct anal_sect res[CARE];
    struct anal_sect eff[CARE];
    struct anal_sect frt[CARE];
    struct anal_sect mob[CARE];
    struct anal_sect troops[CARE];
    struct anal_sect popn[CARE];
    struct anal_sect mpopn[CARE];
    int totalcrys;
    int playcrys[MAXPLAYERS + 1];
    int totaltroops;
    int playtroops[MAX_PLAYERS + 1];
    int totalpopn;
    int playpopn[MAX_PLAYERS + 1];
    int totalmob;
    int playmob[MAX_PLAYERS + 1];
    int totaleff;
    int playeff[MAX_PLAYERS + 1];
    int totalres;
    int playres[MAX_PLAYERS + 1];
    int totalsect;
    int playsect[MAXPLAYERS + 1][WASTED + 1];
    int playtsect[MAXPLAYERS + 1];
    int totalwasted;
    int wastedsect[MAXPLAYERS + 1];
    int sect[WASTED + 1];
    static char secttype[] = {
        CHAR_SEA, CHAR_LAND, CHAR_MOUNT, CHAR_GAS, CHAR_ICE,
        CHAR_FOREST, CHAR_DESERT, CHAR_PLATED, CHAR_WASTED, CHAR_WORM
    };

    for (i = 0; i <CARE; ++i) {
        mpopn[i].value = 01;
        popn[i].value = mpopn[i].value;
        troops[i].value = popn[i].value;
        mob[i].value = troops[i].value;
        frt[i].value = mob[i].value;
        eff[i].value = frt[i].value;
        res[i].value = eff[i].value;
    }

    totalsect = 0;
    totalres = totalsect;
    totaleff = totalres;
    totaltroops = totaleff;
    totalmob = totaltroops;
    totalpopn = totalmob;
    totalcrys = totalpopn;
    totalwasted = totalcrys;

    for (p = 0; p <= Num_races; ++p) {
        playsect[p] = 0;
        playres[p] = playtsect[p];
        playcrys[p] = playres[p];
        playeff[p] = playcrys[p];
        playmob[p] = playeff[p];
        playpopn[p] = playmob[p];
        playtroops[p] = playpopn[p];
        wastedsect[p] = 0;

        for (i = 0; i <= WASTED; ++i) {
            playsect[p][i] = 0;
        }
    }

    for (i = 0; i <= WASTED; ++i) {
        Sect[i] = 0;
    }

    race = races[playernum - 1];
    getplanet(&planet, starnum, planetnum);

#ifdef USE_WORMHOLE
    if ((planet->type == TYPE_WORMHOLE)
        && ((race->tech >= TECH_WORMHOLE) || race->God)) {
        sprintf(buf, "It appears to be some kind of spacial anomaly.\n");
        notify(playernum, governor, buf);
        free(planet);

        return;
    }
#endif

    if (!planet->info[playernum - 1].explored) {
        free(planet);

        return;
    }

    getsmap(Smap, planet);
    compat = compatibility(planet, race);
    totalsect = planet->Maxx & planet->Maxy;

    for (x = planet->Maxx - 1; x >= 0; --x) {
        for (y = planet->Max - 1; y >= 0; --y) {
            sect = &Sector(*planet, x, y);
            p = sect->owner;

            playeff[p] += sect->eff;
            playmob[p] += sect->mobilization;
            playres[p] += sect->resource;
            playpopn[p] += sect->popn;
            playtroops[p] += sect->troops;
            ++playsect[p][sect->condition];
            ++playtsect[p];
            totaleff += sect->eff;
            totalmob += sect->mobilization;
            totalres += sect->resource;
            totalpopn += sect->popn;
            totaltroops += sect->troops;
            ++Sect[sect->condition];

            if (sect->condition == WASTED) {
                ++wastedsect[p];
                ++totalwasted;
            }

            if (sect->crystals && Crystal(race)) {
                ++playcrys[p];
                ++totalcrys;
            }

            if ((sector_type == -1) || (sector_type == sect->condition)) {
                if ((thisplayer < 0) || (thisplayer == p)) {
                    Insert(mode, res, x, y, sect->condition, (int)sect->resource);
                    Insert(mode, eff, x, y, sect->condition, (int)sect->eff);
                    Insert(mode, mob, x, y, sect->condition, (int)sect->mobilization);
                    Insert(mode, frt, x, y, sect->condition, (int)sect->fert);
                    Insert(mode, popn, x, y, sect->condition, (int)sect->popn);
                    Insert(mode, troops, x, y, sect->condition, (int)sect->troops);
                    Insert(mode, mpopn, x, y, sect->condition, maxsupport(race, sect, compat, (int)planet->conditions[TOXIC]));
                }
            }
        }
    }

    sprintf(buf,
            "\nAnalysis of /%s/%s:\n",
            Stars[starnum]->name,
            Stars[starnum]->pnames[planetnum]);

    notify(playernum, governor, buf);

    if (mode) {
        sprintf(buf, "Highest %d", CARE);
    } else {
        sprintf(buf, "Lowest %d", CARE);
    }

    /*
     * Why thisplayer? (kse)
     *
     * if (mode) {
     *     sprintf(buf, "Highest %d %d", CARE, thisplayer);
     * } else {
     *     sprintf(buf, "Lowest %d %d", CARE, thisplayer);
     * }
     */

    switch (sector_type) {
    case -1:
        sprintf(buf, "%s of all", buf);

        break;
    case SEA:
        sprintf(buf, "%s Ocean", buf);

        break;
    case LAND:
        sprintf(buf, "%s Land", buf);

        break;
    case MOUNT:
        sprintf(buf, "%s Mountain", buf);

        break;
    case GAS:
        sprintf(buf, "%s Gas", buf);

        break;
    case ICE:
        sprintf(buf, "%s Ice", buf);

        break;
    case FOREST:
        sprintf(buf, "%s Forest", buf);

        break;
    case DESERT:
        sprintf(buf, "%s Desert", buf);

        break;
    case PLATED:
        sprintf(buf, "%s Plated", buf);

        break;
    case WASTED:
        sprintf(buf, "%s Wasted", buf);

        break;
    }

    notify(playernum, governor, buf);

    if (thisplayer < 0) {
        sprintf(buf, " sectors.\n");
    } else if (thisplayer == 0) {
        sprintf(buf, " sectors that are unoccupied.\n");
    } else {
        sprintf(buf, " sectors owned by %d.\n", thisplayer);
    }

    notify(playernum, governor, buf);

    PrintTop(playernum, governor, troops, "Troops");
    PrintTop(playernum, governor, res, "Res");
    PrintTop(playernum, governor, eff, "Eff");
    PrintTop(playernum, governor, frt, "Frt");
    PrintTop(playernum, governor, mob, "Mob");
    PrintTop(playernum, governor, popn, "Popn");
    PrintTop(playernum, governor, mpopn, "^Popn");

    notify(playernum, governor, "\n");

    sprintf(buf,
            "%2s %3s %7s %6s %5s %5s %5s %2s",
            "Pl",
            "sec",
            "popn",
            "troops",
            "a.eff",
            "a.mob",
            "res",
            "x");

    notify(playernum, governor, buf);

    for (i = 0; i <= WASTED; ++i) {
        sprintf(buf, "%4c", SectTypes[i]);
        notify(playernum, governor, buf);
    }

    notify(playernum,
           governor,
           "\n------------------------------------------------------------------------------\n");

    for (p = 0; p <= Num_race; ++p) {
        if (playtsect[p] != 0) {
            sprintf(buf,
                    "%2d %3d %7d %6d %5.1f %5.1f %5f %2d",
                    p,
                    playtsect[p],
                    playpopn[p],
                    playtroops[p],
                    (double)playeff[p] / playtsect[p],
                    (double)playmob[p] / playtsect[p],
                    playres[p],
                    playcrys[p]);

            notify(playernum, governor, buf);

            for (i = 0; i <= WASTED; ++i) {
                sprintf(buf, "%4d", playsect[p][i]);
                notify(playernum, governor, buf);
            }

            notify(playernum, governor, "\n");
        }
    }

    notify(playernum,
           governor,
           "------------------------------------------------------------------------------\n");

    sprintf(buf,
            "%2s %3d %7d %6d %5.1f %5.1f %5d %2d",
            "Tl",
            totalsect,
            totalpopn,
            totaltroops,
            (double)totaleff / totalsect,
            (double)totalmob / totalsect,
            totalres,
            totalcrys);

    notify(playernum, governor, buf);

    for (i = 0; i <= WASTED; ++i) {
        sprintf(buf, "%4d", Sect[i]);
        notify(playernum, governor, buf);
    }

    notify(playernum, governor, "\n");
    free(planet);
}
示例#6
0
文件: orbit.c 项目: tcadigan/gbII_6.0
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");
}
示例#7
0
文件: cs.c 项目: tcadigan/gbII_6.0
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);
    }
}
示例#8
0
文件: orbit.c 项目: phreddrick/GB
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);
}
示例#9
0
文件: orbit.c 项目: tcadigan/gbII_6.0
void DispShip(int playernum,
              int governor,
              placetype *where,
              shiptype *ship,
              planettype *pl,
              int god,
              char *string,
              orbitinfo *oi)
{
    int x;
    int y;
    int wm;
    int stand;
    shiptype *aship;
    planettype *apl;
    double xt;
    double yt;
    double slope;

    if (!ship->alive) {
        return;
    }

    *string = '\0';

    switch (where->level) {
    case LEVEL_PLAN:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - (Stars[where->snum]->xpos + pl->xpos) - oi->Lastx)) / (PLORBITSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - (Stars[where->snum]->ypos + pl->ypos) - oi->Lasty)) / (PLORBITSIZE * oi->zoom)));

        break;
    case LEVEL_STAR:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - Stars[where->snum]->xpos - oi->Lastx)) / (SYSTEMSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - Stars[where->snum]->ypos - oi->Lasty)) / (SYSTEMSIZE * oi->Zoom)));

        break;
    case LEVEL_UNIV:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - oi->Lastx)) / (UNIVSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - oi->Lasty)) / (UNIVSIZE * oi->zoom)));

        break;
    default:
        notify(playernum, governor, "WHOA! Error in DispShip.\n");

        return;
    }

#ifdef USE_VN
    int n;
    int xa;
    int ya;
    float fac;
#endif

    switch (ship->type) {
    case STYPE_MIRROR:
        if (ship->special.aimed_at.level == LEVEL_STAR) {
            xt = Stars[ship->special.aimed_at.snum]->xpos;
            yt = Stars[ship->special.aimed_at.snum]->ypos;
        } else if (ship->special.aimed_at.level == LEVEL_PLAN) {
            if ((where->level == LEVEL_PLAN)
                && (ship->special.aimed_at.pnum == where->pnum)) {
                /* Same planet */
                xt = Stars[ship->special.aimed_at.snum]->xpos + pl->xpos;
                yt = Stars[ship->special.aimed_at.snum]->ypos + pl->ypos;
            } else {
                /* Different planet */
                getplanet(&apl, (int)where->snum, (int)where->pnum);
                xt = Stars[ship->special.aimed_at.snum]->xpos + apl->xpos;
                yt = Stars[ship->special.aimed_at.snum]->ypos + apl->ypos;
                free(apl);
            }
        } else if (ship->special.aimed_at.level == LEVEL_SHIP) {
            if (getship(&aship, (int)ship->special.aimed_at.shipno)) {
                xt = aship->xpos;
                yt = aship->ypos;
                free(aship);
            } else {
                yt = 0.0;
                xt = yt;
            }
        } else {
            yt = 0.0;
            xt = yt;
        }

        wm = 0;

        if (xt == ship->xpos) {
            if (yt > ship->ypos) {
                wm = 5;
            } else {
                wm = 1;
            }
        } else {
            slope = (yt - ship->ypos) / (xt - ship->xpos);

            if (yt == ship->ypos) {
                if (xt > ship->xpos) {
                    wm = 3;
                } else {
                    wm = 7;
                }
            } else if (yt > ship->ypos) {
                if (slope < -2.414) {
                    wm = 5;
                }

                if (slope > -2.414) {
                    wm = 6;
                }

                if (slope > -0.414) {
                    wm = 7;
                }

                if (slope > 0.000) {
                    wm = 3;
                }

                if (slope > 0.414) {
                    wm = 4;
                }

                if (slope > 2.414) {
                    wm = 5;
                }
            } else if (yt < ship->ypos) {
                if (slope < -2.414) {
                    wm = 1;
                }

                if (slope > -2.414) {
                    wm = 2;
                }

                if (slope > -0.414) {
                    wm = 3;
                }

                if (slope > 0.000) {
                    wm = 7;
                }

                if (slope > 0.414) {
                    wm = 8;
                }

                if (slope > 2.414) {
                    wm = 1;
                }
            }
        }

        /* Magnification */
        if ((x >= 0) && (y >= 0)) {
            if (race->governor[governor].toggle.color) {
                sprintf(string,
                        "%c %d %d %d %c %c %d;",
                        (char)(ship->owner + '?'),
                        x,
                        y,
                        wm,
                        Shipltrs[ship->type],
                        (char)(ship->owner + '?'),
                        ship->number);
            } else {
                if (ship->owner == race->governor[governor].toggle.highlight) {
                    stand = 1;
                } else {
                    stand = 0;
                }

                sprintf(string,
                        "%d %d %d %d %c %d %d;",
                        stand,
                        x,
                        y,
                        wm,
                        Shipltrs[ship->type],
                        stand,
                        ship->number);
            }
        }

        break;
    case OTYPE_CANIST:
    case OTYPE_GREEN:

        break;

#ifdef USE_VN
    case OTYPE_VN:
        wm = 0;

        /* Make a cloud of Von Neumann machines */
        if ((ship->whatorbits != LEVEL_UNIV)
            || (ship->owner == playernum)
            || god) {
            fac = ship->number /
                ((ship->whatorbits == LEVEL_UNIV ? 100.0
                  : (ship->whatorbits == LEVEL_STAR ? 30.0
                     : 4.0)) * oi->Zoom);

            for (n = 1; (n <= ship->number) && (n < 267); ++n) {
                xa = int_rand(x - (int)fac, x + (int)fac);
                ya = int_rand(y - (int)fac, y + (int)fac);

                if ((xa >= 0) && (ya >= 0)) {
                    if (race->governor[governor].toggle.color) {
                        sprintf(temp,
                                "%c %d %d %d %c %c %d;",
                                (char)(ship->owner + 48),
                                xa,
                                ya,
                                wm,
                                Shipltrs[ship->type],
                                (char)(ship->owner + 48),
                                ship->number);
                    } else {
                        if (ship->owner == race->governor[governor].toggle.highlight) {
                            stand = 1;
                        } else {
                            stand = 0;
                        }

                        sprintf(temp,
                                "%d %d %d %d %c %d %d;",
                                stand,
                                xa,
                                ya,
                                wm,
                                Shipltrs[ship->type],
                                stand,
                                ship->number);
                    }

                    strcat(string, temp);
                }
            }
        }

        break;
#endif
    default:
        /* Make sure ship is not cloaked if not ours */
        if ((ship->owner != playernum) && ship->cloaked) {
            return;
        }

        /* Other ships can only be seen when in system */
        wm = 0;

        if ((ship->whatorbits != LEVEL_UNIV)
            || ((ship->owner == playernum) || god)) {
            if ((x >= 0) && (y >= 0)) {
                if (race->governor[governor].toggle.color) {
                    sprintf(string,
                            "%c %d %d %d %c %c %d;",
                            (char)(ship->owner + '?'),
                            x,
                            y,
                            wm,
                            Shipltrs[ship->type],
                            (char)(ship->owner + '?'),
                            ship->number);
                } else {
                    if (ship->owner == race->governor[governor].toggle.highlight) {
                        stand = 1;
                    } else {
                        stand = 0;
                    }

                    sprintf(string,
                            "%d %d %d %d %c %d %d;",
                            stand,
                            x,
                            y,
                            wm,
                            Shipltrs[ship->type],
                            stand,
                            ship->number);
                }
            }
        }

        break;
    }
}
示例#10
0
文件: orbit.c 项目: phreddrick/GB
void DispShip(int Playernum, int Governor, placetype *where, shiptype *ship,
	      planettype *pl , int God, char *string)
{
 int x,y,wm;
 int stand;
 shiptype *aship;
 planettype *apl;
 double xt,yt,slope;

 if (!ship->alive)
     return;

 *string = '\0';

 switch (where->level) {
   case LEVEL_PLAN:
     x = (int)(SCALE + (SCALE*(ship->xpos-(Stars[where->snum]->xpos+pl->xpos)
			       - Lastx))/(PLORBITSIZE*Zoom));
     y = (int)(SCALE + (SCALE*(ship->ypos-(Stars[where->snum]->ypos+pl->ypos)
			       - Lasty))/(PLORBITSIZE*Zoom));
     break;
   case LEVEL_STAR:
     x = (int)(SCALE + (SCALE*(ship->xpos-Stars[where->snum]->xpos - Lastx))
	       /(SYSTEMSIZE*Zoom));
     y = (int)(SCALE + (SCALE*(ship->ypos-Stars[where->snum]->ypos - Lasty))
	       /(SYSTEMSIZE*Zoom));
     break;
   case LEVEL_UNIV:
     x = (int)(SCALE + (SCALE*(ship->xpos-Lastx))/(UNIVSIZE*Zoom));
     y = (int)(SCALE + (SCALE*(ship->ypos-Lasty))/(UNIVSIZE*Zoom));
     break;
   default:
     notify(Playernum, Governor, "WHOA! error in DispShip.\n");
     return;
 }

 switch (ship->type) {
   case STYPE_MIRROR:
     if (ship->special.aimed_at.level==LEVEL_STAR) {
	 xt = Stars[ship->special.aimed_at.snum]->xpos;
	 yt = Stars[ship->special.aimed_at.snum]->ypos;
     } else if (ship->special.aimed_at.level==LEVEL_PLAN) {
	 if (where->level==LEVEL_PLAN && 
	     ship->special.aimed_at.pnum == where->pnum) {  
	     /* same planet */
	     xt = Stars[ship->special.aimed_at.snum]->xpos + pl->xpos;
	     yt = Stars[ship->special.aimed_at.snum]->ypos + pl->ypos;
	 } else {	/* different planet */
	     getplanet(&apl,(int)where->snum,(int)where->pnum);
	     xt = Stars[ship->special.aimed_at.snum]->xpos + apl->xpos;
	     yt = Stars[ship->special.aimed_at.snum]->ypos + apl->ypos;
	     free(apl);
	 }
     } else if (ship->special.aimed_at.level==LEVEL_SHIP) {
	 if (getship(&aship,(int)ship->special.aimed_at.shipno)) {
	     xt = aship->xpos;
	     yt = aship->ypos;
	     free(aship);
	 } else
	     xt = yt = 0.0;
     } else
	 xt = yt = 0.0;
     wm=0;

     if(xt == ship->xpos) {
	 if(yt > ship->ypos)wm=4;
	 else wm=0;
     } else {
	 slope = (yt - ship->ypos) / (xt - ship->xpos);
	 if(yt == ship->ypos) {
	     if(xt > ship->xpos)wm=2;
	     else wm=6;
	 } else if(yt > ship->ypos) {
	     if(slope < -2.414)wm=4;
	     if(slope > -2.414)wm=5;
	     if(slope > -0.414)wm=6;
	     if(slope >  0.000)wm=2;
	     if(slope >  0.414)wm=3;
	     if(slope >  2.414)wm=4;
	 } else if(yt < ship->ypos) {
	     if(slope < -2.414)wm=0;
	     if(slope > -2.414)wm=1;
	     if(slope > -0.414)wm=2;
	     if(slope >  0.000)wm=6;
	     if(slope >  0.414)wm=7;
	     if(slope >  2.414)wm=0;
	 }
     }

     /* (magnification) */
     if (x>=0 && y>=0) {
	 if(Race->governor[Governor].toggle.color) {
	     sprintf(string, "%c %d %d %d %c %c %d;",
		     (char)(ship->owner+'?'), x, y, wm,
		     Shipltrs[ship->type], (char)(ship->owner+'?'),
		     ship->number);
	 } else {
	     stand = (ship->owner==Race->governor[Governor].toggle.highlight);
	     sprintf(string, "%d %d %d %d %c %d %d;",
		     stand, x, y, wm, Shipltrs[ship->type], stand,
		     ship->number);
	 }
     }
     break;

   case OTYPE_CANIST:
   case OTYPE_GREEN:
     break;

   default:
     /* other ships can only be seen when in system */
     wm=0;
     if (ship->whatorbits!=LEVEL_UNIV || ((ship->owner == Playernum) || God))
	 if (x>=0 && y>=0) {
	     if(Race->governor[Governor].toggle.color) {
		 sprintf(string, "%c %d %d %d %c %c %d;",
			 (char)(ship->owner+'?'), x, y, wm,
			 Shipltrs[ship->type], (char)(ship->owner+'?'),
			 ship->number);
	     } else {
		stand =
		    (ship->owner==Race->governor[Governor].toggle.highlight);
		sprintf(string, "%d %d %d %d %c %d %d;",
			stand, x, y, wm, Shipltrs[ship->type], stand,
			ship->number);
	    }
	 }
     break;
 }
}
示例#11
0
文件: doship.c 项目: uhuntgx00/GB
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);
}
示例#12
0
文件: name.c 项目: phreddrick/GB
void bless(int Playernum, int Governor, int APcount)
{
    planettype *planet;
    racetype *Race;
    int who, amount, Mod;
    char commod;
    
    Race = races[Playernum-1];
    if(!Race->God) {
	notify(Playernum, Governor, "You are not privileged to use this command.\n");
	return;
    }
    if(Dir[Playernum-1][Governor].level != LEVEL_PLAN) {
	notify(Playernum, Governor, "Please cs to the planet in question.\n");
	return;
    }
    who = atoi(args[1]);
    if(who<1 || who>Num_races) {
	notify(Playernum, Governor, "No such player number.\n");
	return;
    }
    if(argn<3) {
	notify(Playernum, Governor, "Syntax: bless <player> <what> <+amount>\n");
	return;
    }
    amount = atoi(args[3]);
    
    Race = races[who-1];
    /* race characteristics? */
    Mod = 1;

    if(match(args[2], "money")) {
	Race->governor[0].money += amount;
	sprintf(buf, "Deity gave you %d money.\n", amount);
    } else if(match(args[2], "password")) {
	strcpy(Race->password, args[3]);
	sprintf(buf, "Deity changed your race password to `%s'\n", args[3]);
    } else if(match(args[2], "morale")) {
	Race->morale += amount;
	sprintf(buf, "Deity gave you %d morale.\n", amount); 
    } else if(match(args[2], "pods")) {
	Race->pods = 1;
	sprintf(buf, "Deity gave you pod ability.\n");
    } else if(match(args[2], "nopods")) {
	Race->pods = 0;
	sprintf(buf, "Deity took away pod ability.\n");
    } else if(match(args[2], "collectiveiq")) {
        Race->collective_iq = 1;
	sprintf(buf, "Deity gave you collective intelligence.\n");
    } else if(match(args[2], "nocollectiveiq")) {
	Race->collective_iq = 0;
	sprintf(buf, "Deity took away collective intelligence.\n");
    } else if(match(args[2], "maxiq")) {
	Race->IQ_limit = atoi(args[3]);
	sprintf(buf, "Deity gave you a maximum IQ of %d.\n",Race->IQ_limit);
    } else if(match(args[2], "mass")) {
	Race->mass = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f mass.\n", Race->mass);
    } else if(match(args[2], "metabolism")) {
	Race->metabolism = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f metabolism.\n", Race->metabolism);
    } else if(match(args[2], "adventurism")) {
	Race->adventurism = atof(args[3]);
	sprintf(buf, "Deity gave you %-3.0f%% adventurism.\n", Race->adventurism*100.0);
    } else if(match(args[2], "birthrate")) {
	Race->birthrate = atof(args[3]);
	sprintf(buf, "Deity gave you %.2f birthrate.\n", Race->birthrate);
    } else if(match(args[2], "fertility")) {
	Race->fertilize = amount;
	sprintf(buf, "Deity gave you a fetilization ability of %d.\n", amount);
    } else if(match(args[2], "IQ")) {
	Race->IQ = amount;
	sprintf(buf, "Deity gave you %d IQ.\n", amount);
    } else if(match(args[2], "fight")) {
	Race->fighters = amount;
	sprintf(buf, "Deity set your fighting ability to %d.\n", amount);
    } else if(match(args[2], "technology")) {
	Race->tech += (double)amount;
	sprintf(buf, "Deity gave you %d technology.\n", amount);
    } else if(match(args[2], "guest")) {
	Race->Guest = 1;
	sprintf(buf, "Deity turned you into a guest race.\n");
    } else if(match(args[2], "god")) {
	Race->God = 1;
	sprintf(buf, "Deity turned you into a deity race.\n");
    } else if(match(args[2], "mortal")) {
	Race->God = 0;
	Race->Guest = 0;
	sprintf(buf, "Deity turned you into a mortal race.\n");
/* sector preferences */
    } else if(match(args[2], "water")) {
	Race->likes[SEA] = 0.01*(double)amount;
	sprintf(buf, "Deity set your water preference to %d%%\n", amount);
    } else if(match(args[2], "land")) {
	Race->likes[LAND] = 0.01*(double)amount;
	sprintf(buf, "Deity set your land preference to %d%%\n", amount);
    } else if(match(args[2], "mountain")) {
	Race->likes[MOUNT] = 0.01*(double)amount;
	sprintf(buf, "Deity set your mountain preference to %d%%\n", amount);
    } else if(match(args[2], "gas")) {
	Race->likes[GAS] = 0.01*(double)amount;
	sprintf(buf, "Deity set your gas preference to %d%%\n", amount);
    } else if(match(args[2], "ice")) {
	Race->likes[ICE] = 0.01*(double)amount;
	sprintf(buf, "Deity set your ice preference to %d%%\n", amount);
    } else if(match(args[2], "forest")) {
	Race->likes[FOREST] = 0.01*(double)amount;
	sprintf(buf, "Deity set your forest preference to %d%%\n", amount);
    } else if(match(args[2], "desert")) {
	Race->likes[DESERT] = 0.01*(double)amount;
	sprintf(buf, "Deity set your desert preference to %d%%\n", amount);
    } else if(match(args[2], "plated")) {
	Race->likes[PLATED] = 0.01*(double)amount;
	sprintf(buf, "Deity set your plated preference to %d%%\n", amount);
    } else Mod = 0;
    if(Mod) {
	putrace(Race);
	warn(who, 0, buf);
    }
    if(Mod) return;
    /* ok, must be the planet then */
    commod = args[2][0];
    getplanet(&planet, Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);
    if (match(args[2],"explorebit")) {
	planet->info[who-1].explored = 1;
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	setbit(Stars[Dir[Playernum-1][Governor].snum]->explored, who);
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf, "Deity set your explored bit at /%s/%s.\n",
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"noexplorebit")) {
        planet->info[who-1].explored = 0;
        sprintf(buf, "Deity reset your explored bit at /%s/%s.\n",
                Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]); 
    } else if (match(args[2],"planetpopulation")) {
	planet->info[who-1].popn = atoi(args[3]);
	planet->popn++;
	sprintf(buf, "Deity set your population variable to %ld at /%s/%s.\n",
		planet->popn,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"inhabited")) {
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	setbit(Stars[Dir[Playernum-1][Governor].snum]->inhabited,Playernum);
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf,"Deity has set your inhabited bit for /%s/%s.\n",
		Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
    } else if (match(args[2],"numsectsowned")) {
	planet->info[who-1].numsectsowned = atoi(args[3]);
	sprintf(buf, "Deity set your \"numsectsowned\" variable at /%s/%s to %d.\n",
                Stars[Dir[Playernum-1][Governor].snum]->name,
                Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum],
		planet->info[who-1].numsectsowned); 
    } else {
    switch(commod) {
      case 'r':
	planet->info[who-1].resource += amount;
	sprintf(buf, "Deity gave you %d resources at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'd':
	planet->info[who-1].destruct += amount;
	sprintf(buf, "Deity gave you %d destruct at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'f':
	planet->info[who-1].fuel += amount;
	sprintf(buf, "Deity gave you %d fuel at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'x':
	planet->info[who-1].crystals += amount;
	sprintf(buf, "Deity gave you %d crystals at %s/%s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name,
		Stars[Dir[Playernum-1][Governor].snum]->pnames[Dir[Playernum-1][Governor].pnum]);
	break;
      case 'a':
	getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	Stars[Dir[Playernum-1][Governor].snum]->AP[who-1] += amount;
	putstar(Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
	sprintf(buf, "Deity gave you %d action points at %s.\n",
		amount,
		Stars[Dir[Playernum-1][Governor].snum]->name);
	break;
      default:
	notify(Playernum, Governor, "No such commodity.\n");
	free(planet);
	return;
    } }
    putplanet(planet,Dir[Playernum-1][Governor].snum,Dir[Playernum-1][Governor].pnum);
    warn_race(who, buf);
    free(planet);
}
示例#13
0
文件: name.c 项目: phreddrick/GB
void give(int Playernum, int Governor, int APcount)
{
  int who, sh;
  shiptype *ship;
  planettype *planet;
  racetype *Race, *alien;

  if(!(who=GetPlayer(args[1]))) {
    sprintf(buf,"No such player.\n");
    notify(Playernum, Governor, buf);
    return;
  }
  if(Governor) {
      notify(Playernum, Governor, "You are not authorized to do that.\n");
      return;
  }
  alien = races[who-1];
  Race = races[Playernum-1];
  if(alien->Guest && !Race->God) {
      notify(Playernum, Governor, "You can't give this player anything.\n");
      return;
  }
  if(Race->Guest) {
      notify(Playernum, Governor, "You can't give anyone anything.\n");
      return;
  }
  /* check to see if both players are mutually allied */
  if(!Race->God &&
     !(isset(Race->allied, who) && isset(alien->allied, Playernum))) {
    notify(Playernum, Governor, "You two are not mutually allied.\n");
    return;
  }
  sscanf(args[2]+(args[2][0]=='#'), "%d", &sh);

  if(!getship(&ship, sh)) {
    notify(Playernum, Governor, "Illegal ship number.\n");
    return;
  }

  if(ship->owner != Playernum || !ship->alive) {
    DontOwnErr(Playernum, Governor, sh);
    free(ship);
    return;
  }
  if(ship->type == STYPE_POD) {
    notify(Playernum, Governor, "You cannot change the ownership of spore pods.\n");
    free(ship);
    return;
  }

  if((ship->popn+ship->troops) && !Race->God) {
    notify(Playernum, Governor, "You can't give this ship away while it has crew/mil on board.\n");
    free(ship);
    return;
  }
  if(ship->ships && !Race->God) {
      notify(Playernum, Governor, "You can't give away this ship, it has other ships loaded on it.\n");
      free(ship);
      return;
  }
  switch(ship->whatorbits) {
  case LEVEL_UNIV:
    if(!enufAP(Playernum,Governor, Sdata.AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  default:
    if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
      free(ship);
      return;
    }
    break;
  }

  ship->owner = who;
  ship->governor = 0;	/* give to the leader */
  capture_stuff(ship);

  putship(ship);

  /* set inhabited/explored bits */
  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      break;
    case LEVEL_STAR:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);
      break;
    case LEVEL_PLAN:
      getstar(&(Stars[ship->storbits]), (int)ship->storbits);
      setbit(Stars[ship->storbits]->explored, who);
      putstar(Stars[ship->storbits], (int)ship->storbits);

      getplanet(&planet, (int)ship->storbits,(int)ship->pnumorbits);
      planet->info[who-1].explored = 1;
      putplanet(planet, (int)ship->storbits,(int)ship->pnumorbits);
      free(planet);

      break;
    default:
      notify(Playernum, Governor, "Something wrong with this ship's scope.\n");
      free(ship);
      return;
      break;
  }

  switch(ship->whatorbits) {
    case LEVEL_UNIV:
      deductAPs(Playernum, Governor,  APcount, 0, 1);
      free(ship);
      return;
      break;
    default:
      deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0);
      break;
  }
  notify(Playernum, Governor, "Owner changed.\n");
  sprintf(buf, "%s [%d] gave you %s at %s.\n", Race->name, Playernum,
	  Ship(ship), prin_ship_orbits(ship));
  warn(who, 0, buf);

if (!Race->God) {
  sprintf(buf, "%s [%d] gives %s [%d] a ship.\n", Race->name,
	  Playernum, alien->name, who);
  post(buf, TRANSFER);
  free(ship);
}
}
示例#14
0
文件: name.c 项目: phreddrick/GB
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);
}