コード例 #1
0
ファイル: name.c プロジェクト: phreddrick/GB
void page(int Playernum, int Governor, int APcount0)
{
  int i, who, gov, to_block, dummy[2], APcount;
  racetype *Race, *alien;

  APcount = APcount0;
  if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount))
      return;

  to_block = 0;
  if(match(args[1], "block")) {
    to_block = 1;
    notify(Playernum, Governor, "Paging alliance block.\n");
  } else {
    if(!(who=GetPlayer(args[1]))) {
      sprintf(buf,"No such player.\n");
      notify(Playernum, Governor, buf);
      return;
    }
    alien = races[who-1];
    APcount *= !alien->God;
    if(argn>1) gov=atoi(args[2]);
  }

  switch(Dir[Playernum-1][Governor].level) {
  case LEVEL_UNIV:
    sprintf(buf, "You can't make pages at universal scope.\n");
    notify(Playernum, Governor, buf);
    break;
  default:
    getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
    if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) {
      return;
    }

    Race = races[Playernum-1];

    sprintf(buf, "%s \"%s\" page(s) you from the %s star system.\n",
	    Race->name, Race->governor[Governor].name,
	    Stars[Dir[Playernum-1][Governor].snum]->name);

    if(to_block) {
      dummy[0] = Blocks[Playernum-1].invite[0] & Blocks[Playernum-1].pledge[0];
      dummy[1] = Blocks[Playernum-1].invite[1] & Blocks[Playernum-1].pledge[1];
      for(i=1; i<=Num_races; i++)
        if(isset(dummy, i) && i!=Playernum)
          notify_race(i, buf);
    } else {
	if(argn>1)
	    notify(who, gov, buf);
	else
	    notify_race(who, buf);
    }

    notify(Playernum, Governor, "Request sent.\n");
    break;
  }
  deductAPs(Playernum, Governor,  APcount, Dir[Playernum-1][Governor].snum, 0);
}
コード例 #2
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);
}
コード例 #3
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);
}
コード例 #4
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);
    }
}
コード例 #5
0
ファイル: name.c プロジェクト: phreddrick/GB
void send_message(int Playernum, int Governor, int APcount0, int postit)
{
  int who, i, j, to_block, dummy[2], APcount;
  int to_star, star, start;
  placetype where;
  racetype *Race, *alien;

  APcount = APcount0;

  to_star = to_block = 0;

  if(argn<2) {
      notify(Playernum, Governor, "Send what?\n");
      return;
  }
  if(postit) {
      Race = races[Playernum-1];
      sprintf(msg, "%s \"%s\" [%d,%d]: ",
	      Race->name, Race->governor[Governor].name,
	      Playernum, Governor);
  /* put the message together */
      for(j=1; j < argn; j++) {
	  sprintf(buf, "%s ", args[j]);
	  strcat(msg, buf);
      }
    strcat(msg, "\n");
    post(msg, ANNOUNCE);
    return;
  }
  if(match(args[1], "block")) {
    to_block = 1;
    notify(Playernum, Governor, "Sending message to alliance block.\n");
    if(!(who=GetPlayer(args[2]))) {
      sprintf(buf,"No such alliance block.\n");
      notify(Playernum, Governor, buf);
      return;
    }
    alien = races[who-1];
    APcount *= !alien->God;
  } else if (match(args[1], "star")) {
    to_star = 1;
    notify(Playernum, Governor, "Sending message to star system.\n");
    where = Getplace(Playernum, Governor, args[2], 1);
    if (where.err || where.level != LEVEL_STAR) {
      sprintf(buf, "No such star.\n");
      notify(Playernum, Governor, buf);
      return;
    }
    star = where.snum;
    getstar(&(Stars[star]), star);
  } else {
    if(!(who=GetPlayer(args[1]))) {
      sprintf(buf,"No such player.\n");
      notify(Playernum, Governor, buf);
      return;
    }
    alien = races[who-1];
    APcount *= !alien->God;
  }

  switch(Dir[Playernum-1][Governor].level) {
  case LEVEL_UNIV:
    sprintf(buf, "You can't send messages from universal scope.\n");
    notify(Playernum, Governor, buf);
    return;
    break;

  case LEVEL_SHIP:
    sprintf(buf, "You can't send messages from ship scope.\n");
    notify(Playernum, Governor, buf);
    return;
    break;

  default:
    getstar(&Stars[Dir[Playernum-1][Governor].snum], Dir[Playernum-1][Governor].snum);
    if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount))
      return;
    break;
  }

  Race = races[Playernum-1];

  /* send the message */
  if(to_block)
      sprintf(msg, "%s \"%s\" [%d,%d] to %s [%d]: ", Race->name,
	      Race->governor[Governor].name, Playernum, Governor,
	      Blocks[who-1].name, who);
  else if (to_star)
      sprintf(msg, "%s \"%s\" [%d,%d] to inhabitants of %s: ", Race->name,
	      Race->governor[Governor].name, Playernum,
	      Governor, Stars[star]->name);
  else
    sprintf(msg, "%s \"%s\" [%d,%d]: ", Race->name,
	    Race->governor[Governor].name, Playernum, Governor);

  if(to_star || to_block || isdigit(*args[2])) start = 3;
  else if(postit) start = 1;
  else start = 2;
  /* put the message together */
  for(j=start; j < argn; j++)
  {
    sprintf(buf, "%s ", args[j]);
    strcat(msg, buf);
  }
  /* post it */
  sprintf(buf, "%s \"%s\" [%d,%d] has sent you a telegram. Use `read' to read it.\n",
	  Race->name, Race->governor[Governor].name,
	  Playernum, Governor);
  if(to_block) {
      dummy[0] = (Blocks[who-1].invite[0] & Blocks[who-1].pledge[0]);
      dummy[1] = (Blocks[who-1].invite[1] & Blocks[who-1].pledge[1]);
      sprintf(buf, "%s \"%s\" [%d,%d] sends a message to %s [%d] alliance block.\n",
        Race->name, Race->governor[Governor].name, Playernum, Governor,
	      Blocks[who-1].name, who);
    for(i=1; i<=Num_races; i++) {
      if(isset(dummy, i)) {
        notify_race(i, buf);
        push_telegram_race(i, msg);
      }
    }
  } else if (to_star) {
    sprintf(buf, "%s \"%s\" [%d,%d] sends a stargram to %s.\n", Race->name,
	    Race->governor[Governor].name, Playernum,
	    Governor, Stars[star]->name);
    notify_star(Playernum, Governor, 0, star, buf);
    warn_star(Playernum, 0, star, msg);
  } else {
    int gov;
    if(who==Playernum) APcount = 0;
    if(isdigit(*args[2]) && (gov=atoi(args[2])) >= 0 && gov <=MAXGOVERNORS) {
	push_telegram(who, gov, msg);
	notify(who, gov, buf);
    } else {
	push_telegram_race(who, msg);
	notify_race(who, buf);
    }

    alien = races[who-1];
    /* translation modifier increases */
    alien->translate[Playernum-1] = MIN(alien->translate[Playernum-1]+2, 100);
    putrace(alien);
  }
  notify(Playernum, Governor, "Message sent.\n");
  deductAPs(Playernum, Governor,  APcount, Dir[Playernum-1][Governor].snum, 0);
}
コード例 #6
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);
}
}
コード例 #7
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);
}