Esempio n. 1
0
File: name.c Progetto: phreddrick/GB
void pay(int Playernum, int Governor, int APcount)
{
  int who,amount;
  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;
  }
  Race = races[Playernum-1];
  alien = races[who-1];
  
  sscanf(args[2], "%d", &amount);
  if(amount < 0) {
      notify(Playernum, Governor, "You have to give a player a positive amount of money.\n");
      return;
  }
  if(Race->Guest) {
      notify(Playernum, Governor, "Nice try. Your attempt has been duly noted.\n");
      return;
  }
  if(Race->governor[Governor].money < amount) {
      notify(Playernum, Governor, "You don't have that much money to give!\n");
      return;
  }
  
  Race->governor[Governor].money -= amount;
  alien->governor[0].money += amount;
  sprintf(buf, "%s [%d] payed you %d.\n", Race->name, Playernum, amount);
  warn(who, 0, buf);
  sprintf(buf, "%d payed to %s [%d].\n", amount, alien->name, who);
  notify(Playernum, Governor, buf);

  sprintf(buf, "%s [%d] pays %s [%d].\n", Race->name,
      Playernum, alien->name, who);
  post(buf, TRANSFER);

  putrace(alien);
  putrace(Race);
}
Esempio n. 2
0
File: name.c Progetto: phreddrick/GB
void personal(int Playernum, int Governor, char *message)
{
  racetype *Race;

  if(Governor) {
      notify(Playernum, Governor, "Only the leader can do this.\n");
      return;
  }
  Race = races[Playernum-1];
  strncpy(Race->info, message, PERSONALSIZE-1);
  putrace(Race);
}
Esempio n. 3
0
void highlight(int playernum, int governor)
{
    int n;
    racetype *race;

    n = GetPlayer(args[1]);

    if (!n) {
        sprintf(buf, "No such player.\n");
        notify(playernum, governor, buf);

        return;
    }

    race = races[playernum - 1];
    race->governor[governor].toggle.highlight = n;
    putrace(race);
}
Esempio n. 4
0
/*
 * toggle:
 *
 * arguments:
 *   playernum
 *   governor
 *
 * called by:
 *   process_commands
 *
 * description: Called from process_commands, allows you to toggle some
 *              options. Currently inverse, double_digits, gag, autoload,
 *              autopurge, color and monitor
 */
void toggle(int playernum, int governor, int apcount)
{
    racetype *race;

    race = races[playernum - 1];

    if (argn > 1) {
        if (match(args[1], "inverse")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.inverse,
                "inverse");
        } else if (match(args[1], "double_digits")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.double_digits,
                "double_digits");
        } else if (match(args[1], "geography")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.geography,
                "geography");
        } else if (match(args[1], "gag")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.gag,
                "gag");
        } else if (match(args[1], "autoload")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.autoload,
                "autoload");
        } // else if (match(args[1], "autopurge")) {
        //   tog(playernum,
        //       governor,
        //       &race->governor[governor].toggle.autopurge,
        //       "autopurge");
        // }
        else if (match(args[1], "color")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.color,
                "color");
        } else if (match(args[1], "visible")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.invisible,
                "invisible");
        } else if (race->God && match(args[1], "monitor")) {
            tog(playernum, governor, &race->monitor, "monitor");
        } else if (match(args[1], "compatibility")) {
            tog(playernum,
                governor,
                &race->governor[governor].toggle.compat,
                "compatibility");
        } else if (match(args[1], "client")) {
            CSP_client_toggle(playernum, governor, 0);
            notify(playernum, governor, "client toggled\n");
        } else {
            sprintf(buf, "No such option \'%s\'\n", args[1]);
            notify(playernum, governor, bug);

            return;
        }

        putrace(race);
    } else {
        sprintf(buf,
                "gag is %s\n",
                race->governor[governor].toggle.gag ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "inverse is %s\n",
                race->governor[governor].toggle.inverse ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "double_digits is %s\n",
                race->governor[governor].toggle.double_digits ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "geography is %s\n",
                race->governor[governor].toggle.geography ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "autoload is %s\n",
                race->governor[governor].toggle.autoload ? "ON": "OFF");

        notify(playernum, governor, buf);

        /*
         * sprintf(buf,
         *         autopurge is %s\n",
         *         race->governor[governor].toggle.autopurge ? "ON" : "OFF");
         *
         * notify(playernum, governor, buf);
         */

        sprintf(buf,
                "color is %s\n",
                race->governor[governor].toggle.color ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "compatibility is %s\n",
                race->governor[governor].toggle.compat ? "ON" : "OFF");

        notify(playernum, governor, buf);

        sprintf(buf,
                "%s\n",
                race->governor[governor].toggle.invisible ? "INVISIBLE" : "VISIBLE");

        notify(playernum, governor, buf);

        sprintf(buf,
                "highlight player %d\n",
                race->governor[governor].toggle.highlight);

        notify(playernum, governor, buf);

        sprintf(buf,
                "client mode is %s\n",
                Race->governor[governor].CSP_client_info.csp_user ? "ON" : "OFF");

        notify(playernum, governor, buf);

        if (race->God) {
            sprintf(buf, "monitor is %s\n", race->monitor ? "ON" : "OFF");
            notify(playernum, governor, buf);
        }
    }
}
Esempio n. 5
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);
    }
}
Esempio n. 6
0
File: name.c Progetto: 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);
}
Esempio n. 7
0
File: name.c Progetto: 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);
}
Esempio n. 8
0
File: name.c Progetto: 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);
}