Galactic Bloodshed
name.cc
Go to the documentation of this file.
1 // Copyright 2014 The Galactic Bloodshed Authors. All rights reserved.
2 // Use of this source code is governed by a license that can be
3 // found in the COPYING file.
4 
5 /* name.c -- rename something to something else */
6 
7 #include "gb/name.h"
8 
9 #include <cctype>
10 #include <cmath>
11 #include <cstdio>
12 #include <cstdlib>
13 #include <cstring>
14 #include <iterator>
15 #include <sstream>
16 
17 #include "gb/GB_server.h"
18 #include "gb/buffers.h"
19 #include "gb/dissolve.h"
20 #include "gb/files.h"
21 #include "gb/files_shl.h"
22 #include "gb/getplace.h"
23 #include "gb/max.h"
24 #include "gb/mobiliz.h"
25 #include "gb/races.h"
26 #include "gb/ships.h"
27 #include "gb/shlmisc.h"
28 #include "gb/tele.h"
29 #include "gb/tweakables.h"
30 #include "gb/utils/rand.h"
31 #include "gb/vars.h"
32 
33 void personal(const command_t &argv, GameObj &g) {
34  player_t Playernum = g.player;
35 
36  std::stringstream ss_message;
37  std::copy(++argv.begin(), argv.end(),
38  std::ostream_iterator<std::string>(ss_message, " "));
39  std::string message = ss_message.str();
40 
41  if (g.governor != 0) {
42  g.out << "Only the leader can do this.\n";
43  return;
44  }
45  auto Race = races[Playernum - 1];
46  strncpy(Race->info, message.c_str(), PERSONALSIZE - 1);
47  putrace(Race);
48 }
49 
50 void bless(const command_t &argv, GameObj &g) {
51  player_t Playernum = g.player;
52  // TODO(jeffbailey): int APcount = 0;
53  int amount;
54  int Mod;
55  char commod;
56 
57  if (!g.god) {
58  g.out << "You are not privileged to use this command.\n";
59  return;
60  }
61  if (g.level != ScopeLevel::LEVEL_PLAN) {
62  g.out << "Please cs to the planet in question.\n";
63  return;
64  }
65  player_t who = std::stoi(argv[1]);
66  if (who < 1 || who > Num_races) {
67  g.out << "No such player number.\n";
68  return;
69  }
70  if (argv.size() < 3) {
71  g.out << "Syntax: bless <player> <what> <+amount>\n";
72  return;
73  }
74  amount = std::stoi(argv[3]);
75 
76  racetype *Race = races[who - 1];
77  /* race characteristics? */
78  Mod = 1;
79 
80  if (argv[2] == "money") {
81  Race->governor[0].money += amount;
82  sprintf(buf, "Deity gave you %d money.\n", amount);
83  } else if (argv[2] == "password") {
84  strcpy(Race->password, argv[3].c_str());
85  sprintf(buf, "Deity changed your race password to `%s'\n", argv[3].c_str());
86  } else if (argv[2] == "morale") {
87  Race->morale += amount;
88  sprintf(buf, "Deity gave you %d morale.\n", amount);
89  } else if (argv[2] == "pods") {
90  Race->pods = 1;
91  sprintf(buf, "Deity gave you pod ability.\n");
92  } else if (argv[2] == "nopods") {
93  Race->pods = 0;
94  sprintf(buf, "Deity took away pod ability.\n");
95  } else if (argv[2] == "collectiveiq") {
96  Race->collective_iq = 1;
97  sprintf(buf, "Deity gave you collective intelligence.\n");
98  } else if (argv[2] == "nocollectiveiq") {
99  Race->collective_iq = 0;
100  sprintf(buf, "Deity took away collective intelligence.\n");
101  } else if (argv[2] == "maxiq") {
102  Race->IQ_limit = std::stoi(argv[3]);
103  sprintf(buf, "Deity gave you a maximum IQ of %d.\n", Race->IQ_limit);
104  } else if (argv[2] == "mass") {
105  Race->mass = atof(argv[3].c_str());
106  sprintf(buf, "Deity gave you %.2f mass.\n", Race->mass);
107  } else if (argv[2] == "metabolism") {
108  Race->metabolism = atof(argv[3].c_str());
109  sprintf(buf, "Deity gave you %.2f metabolism.\n", Race->metabolism);
110  } else if (argv[2] == "adventurism") {
111  Race->adventurism = atof(argv[3].c_str());
112  sprintf(buf, "Deity gave you %-3.0f%% adventurism.\n",
113  Race->adventurism * 100.0);
114  } else if (argv[2] == "birthrate") {
115  Race->birthrate = atof(argv[3].c_str());
116  sprintf(buf, "Deity gave you %.2f birthrate.\n", Race->birthrate);
117  } else if (argv[2] == "fertility") {
118  Race->fertilize = amount;
119  sprintf(buf, "Deity gave you a fetilization ability of %d.\n", amount);
120  } else if (argv[2] == "IQ") {
121  Race->IQ = amount;
122  sprintf(buf, "Deity gave you %d IQ.\n", amount);
123  } else if (argv[2] == "fight") {
124  Race->fighters = amount;
125  sprintf(buf, "Deity set your fighting ability to %d.\n", amount);
126  } else if (argv[2] == "technology") {
127  Race->tech += (double)amount;
128  sprintf(buf, "Deity gave you %d technology.\n", amount);
129  } else if (argv[2] == "guest") {
130  Race->Guest = 1;
131  sprintf(buf, "Deity turned you into a guest race.\n");
132  } else if (argv[2] == "god") {
133  Race->God = 1;
134  sprintf(buf, "Deity turned you into a deity race.\n");
135  } else if (argv[2] == "mortal") {
136  Race->God = 0;
137  Race->Guest = 0;
138  sprintf(buf, "Deity turned you into a mortal race.\n");
139  /* sector preferences */
140  } else if (argv[2] == "water") {
141  Race->likes[SectorType::SEC_SEA] = 0.01 * (double)amount;
142  sprintf(buf, "Deity set your water preference to %d%%\n", amount);
143  } else if (argv[2] == "land") {
144  Race->likes[SectorType::SEC_LAND] = 0.01 * (double)amount;
145  sprintf(buf, "Deity set your land preference to %d%%\n", amount);
146  } else if (argv[2] == "mountain") {
147  Race->likes[SectorType::SEC_MOUNT] = 0.01 * (double)amount;
148  sprintf(buf, "Deity set your mountain preference to %d%%\n", amount);
149  } else if (argv[2] == "gas") {
150  Race->likes[SectorType::SEC_GAS] = 0.01 * (double)amount;
151  sprintf(buf, "Deity set your gas preference to %d%%\n", amount);
152  } else if (argv[2] == "ice") {
153  Race->likes[SectorType::SEC_ICE] = 0.01 * (double)amount;
154  sprintf(buf, "Deity set your ice preference to %d%%\n", amount);
155  } else if (argv[2] == "forest") {
156  Race->likes[SectorType::SEC_FOREST] = 0.01 * (double)amount;
157  sprintf(buf, "Deity set your forest preference to %d%%\n", amount);
158  } else if (argv[2] == "desert") {
159  Race->likes[SectorType::SEC_DESERT] = 0.01 * (double)amount;
160  sprintf(buf, "Deity set your desert preference to %d%%\n", amount);
161  } else if (argv[2] == "plated") {
162  Race->likes[SectorType::SEC_PLATED] = 0.01 * (double)amount;
163  sprintf(buf, "Deity set your plated preference to %d%%\n", amount);
164  } else
165  Mod = 0;
166  if (Mod) {
167  putrace(Race);
168  warn(who, 0, buf);
169  }
170  if (Mod) return;
171  /* ok, must be the planet then */
172  commod = argv[2][0];
173  auto planet = getplanet(g.snum, g.pnum);
174  if (argv[2] == "explorebit") {
175  planet.info[who - 1].explored = 1;
176  getstar(&Stars[g.snum], g.snum);
177  setbit(Stars[g.snum]->explored, who);
178  putstar(Stars[g.snum], g.snum);
179  sprintf(buf, "Deity set your explored bit at /%s/%s.\n",
180  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
181  } else if (argv[2] == "noexplorebit") {
182  planet.info[who - 1].explored = 0;
183  sprintf(buf, "Deity reset your explored bit at /%s/%s.\n",
184  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
185  } else if (argv[2] == "planetpopulation") {
186  planet.info[who - 1].popn = std::stoi(argv[3]);
187  planet.popn++;
188  sprintf(buf, "Deity set your population variable to %ld at /%s/%s.\n",
189  planet.info[who - 1].popn, Stars[g.snum]->name,
190  Stars[g.snum]->pnames[g.pnum]);
191  } else if (argv[2] == "inhabited") {
192  getstar(&Stars[g.snum], g.snum);
193  setbit(Stars[g.snum]->inhabited, Playernum);
194  putstar(Stars[g.snum], g.snum);
195  sprintf(buf, "Deity has set your inhabited bit for /%s/%s.\n",
196  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
197  } else if (argv[2] == "numsectsowned") {
198  planet.info[who - 1].numsectsowned = std::stoi(argv[3]);
199  sprintf(buf, "Deity set your \"numsectsowned\" variable at /%s/%s to %d.\n",
200  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum],
201  planet.info[who - 1].numsectsowned);
202  } else {
203  switch (commod) {
204  case 'r':
205  planet.info[who - 1].resource += amount;
206  sprintf(buf, "Deity gave you %d resources at %s/%s.\n", amount,
207  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
208  break;
209  case 'd':
210  planet.info[who - 1].destruct += amount;
211  sprintf(buf, "Deity gave you %d destruct at %s/%s.\n", amount,
212  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
213  break;
214  case 'f':
215  planet.info[who - 1].fuel += amount;
216  sprintf(buf, "Deity gave you %d fuel at %s/%s.\n", amount,
217  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
218  break;
219  case 'x':
220  planet.info[who - 1].crystals += amount;
221  sprintf(buf, "Deity gave you %d crystals at %s/%s.\n", amount,
222  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum]);
223  break;
224  case 'a':
225  getstar(&Stars[g.snum], g.snum);
226  Stars[g.snum]->AP[who - 1] += amount;
227  putstar(Stars[g.snum], g.snum);
228  sprintf(buf, "Deity gave you %d action points at %s.\n", amount,
229  Stars[g.snum]->name);
230  break;
231  default:
232  g.out << "No such commodity.\n";
233  return;
234  }
235  }
236  putplanet(planet, Stars[g.snum], g.pnum);
237  warn_race(who, buf);
238 }
239 
240 void insurgency(const command_t &argv, GameObj &g) {
241  player_t Playernum = g.player;
242  governor_t Governor = g.governor;
243  int APcount = 10;
244  int who;
245  int eligible;
246  int them = 0;
247  racetype *Race;
248  racetype *alien;
249  double x;
250  int changed_hands;
251  int chance;
252  int i;
253 
254  if (g.level != ScopeLevel::LEVEL_PLAN) {
255  g.out << "You must 'cs' to the planet you wish to try it on.\n";
256  return;
257  }
258  if (!control(Playernum, Governor, Stars[g.snum])) {
259  g.out << "You are not authorized to do that here.\n";
260  return;
261  }
262  /* if(argv.size()<3) {
263  notify(Playernum, Governor, "The correct syntax is 'insurgency <race>
264  <money>'\n");
265  return;
266  }*/
267  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1], APcount))
268  return;
269  if (!(who = get_player(argv[1]))) {
270  g.out << "No such player.\n";
271  return;
272  }
273  Race = races[Playernum - 1];
274  alien = races[who - 1];
275  if (alien->Guest) {
276  g.out << "Don't be such a dickweed.\n";
277  return;
278  }
279  if (who == Playernum) {
280  g.out << "You can't revolt against yourself!\n";
281  return;
282  }
283  eligible = 0;
284  them = 0;
285  for (i = 0; i < Stars[g.snum]->numplanets; i++) {
286  auto p = getplanet(g.snum, i);
287  eligible += p.info[Playernum - 1].popn;
288  them += p.info[who - 1].popn;
289  }
290  if (!eligible) {
291  g.out << "You must have population in the star system to attempt "
292  "insurgency\n.";
293  return;
294  }
295  auto p = getplanet(g.snum, g.pnum);
296 
297  if (!p.info[who - 1].popn) {
298  g.out << "This player does not occupy this planet.\n";
299  return;
300  }
301 
302  int amount = std::stoi(argv[2]);
303  if (amount < 0) {
304  g.out << "You have to use a positive amount of money.\n";
305  return;
306  }
307  if (Race->governor[Governor].money < amount) {
308  g.out << "Nice try.\n";
309  return;
310  }
311 
312  x = INSURG_FACTOR * (double)amount * (double)p.info[who - 1].tax /
313  (double)p.info[who - 1].popn;
314  x *= morale_factor((double)(Race->morale - alien->morale));
315  x *= morale_factor((double)(eligible - them) / 50.0);
316  x *= morale_factor(10.0 *
317  (double)(Race->fighters * p.info[Playernum - 1].troops -
318  alien->fighters * p.info[who - 1].troops)) /
319  50.0;
320  sprintf(buf, "x = %f\n", x);
321  notify(Playernum, Governor, buf);
322  chance = round_rand(200.0 * atan((double)x) / 3.14159265);
323  sprintf(long_buf, "%s/%s: %s [%d] tries insurgency vs %s [%d]\n",
324  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum], Race->name,
325  Playernum, alien->name, who);
326  sprintf(buf, "\t%s: %d total civs [%d] opposing %d total civs [%d]\n",
327  Stars[g.snum]->name, eligible, Playernum, them, who);
328  strcat(long_buf, buf);
329  sprintf(buf, "\t\t %ld morale [%d] vs %ld morale [%d]\n", Race->morale,
330  Playernum, alien->morale, who);
331  strcat(long_buf, buf);
332  sprintf(buf, "\t\t %d money against %ld population at tax rate %d%%\n",
333  amount, p.info[who - 1].popn, p.info[who - 1].tax);
334  strcat(long_buf, buf);
335  sprintf(buf, "Success chance is %d%%\n", chance);
336  strcat(long_buf, buf);
337  if (success(chance)) {
338  changed_hands = revolt(&p, who, Playernum);
339  notify(Playernum, Governor, long_buf);
340  sprintf(buf, "Success! You liberate %d sector%s.\n", changed_hands,
341  (changed_hands == 1) ? "" : "s");
342  notify(Playernum, Governor, buf);
343  sprintf(buf,
344  "A revolt on /%s/%s instigated by %s [%d] costs you %d sector%s\n",
345  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum], Race->name,
346  Playernum, changed_hands, (changed_hands == 1) ? "" : "s");
347  strcat(long_buf, buf);
348  warn(who, Stars[g.snum]->governor[who - 1], long_buf);
349  p.info[Playernum - 1].tax = p.info[who - 1].tax;
350  /* you inherit their tax rate (insurgency wars he he ) */
351  sprintf(buf, "/%s/%s: Successful insurgency by %s [%d] against %s [%d]\n",
352  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum], Race->name,
353  Playernum, alien->name, who);
354  post(buf, DECLARATION);
355  } else {
356  notify(Playernum, Governor, long_buf);
357  g.out << "The insurgency failed!\n";
358  sprintf(buf, "A revolt on /%s/%s instigated by %s [%d] fails\n",
359  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum], Race->name,
360  Playernum);
361  strcat(long_buf, buf);
362  warn(who, Stars[g.snum]->governor[who - 1], long_buf);
363  sprintf(buf, "/%s/%s: Failed insurgency by %s [%d] against %s [%d]\n",
364  Stars[g.snum]->name, Stars[g.snum]->pnames[g.pnum], Race->name,
365  Playernum, alien->name, who);
366  post(buf, DECLARATION);
367  }
368  deductAPs(Playernum, Governor, APcount, g.snum, 0);
369  Race->governor[Governor].money -= amount;
370  putrace(Race);
371 }
372 
373 void pay(const command_t &argv, GameObj &g) {
374  player_t Playernum = g.player;
375  governor_t Governor = g.governor;
376  // TODO(jeffbailey): int APcount = 0;
377  int who;
378  int amount;
379  racetype *Race;
380  racetype *alien;
381 
382  if (!(who = get_player(argv[1]))) {
383  g.out << "No such player.\n";
384  return;
385  }
386  if (Governor) {
387  g.out << "You are not authorized to do that.\n";
388  return;
389  }
390  Race = races[Playernum - 1];
391  alien = races[who - 1];
392 
393  amount = std::stoi(argv[2]);
394  if (amount < 0) {
395  g.out << "You have to give a player a positive amount of money.\n";
396  return;
397  }
398  if (Race->Guest) {
399  g.out << "Nice try. Your attempt has been duly noted.\n";
400  return;
401  }
402  if (Race->governor[Governor].money < amount) {
403  g.out << "You don't have that much money to give!\n";
404  return;
405  }
406 
407  Race->governor[Governor].money -= amount;
408  alien->governor[0].money += amount;
409  sprintf(buf, "%s [%d] payed you %d.\n", Race->name, Playernum, amount);
410  warn(who, 0, buf);
411  sprintf(buf, "%d payed to %s [%d].\n", amount, alien->name, who);
412  notify(Playernum, Governor, buf);
413 
414  sprintf(buf, "%s [%d] pays %s [%d].\n", Race->name, Playernum, alien->name,
415  who);
416  post(buf, TRANSFER);
417 
418  putrace(alien);
419  putrace(Race);
420 }
421 
422 void give(const command_t &argv, GameObj &g) {
423  player_t Playernum = g.player;
424  governor_t Governor = g.governor;
425  int APcount = 5;
426  int who;
427  racetype *Race;
428  racetype *alien;
429 
430  if (!(who = get_player(argv[1]))) {
431  g.out << "No such player.\n";
432  return;
433  }
434  if (Governor) {
435  g.out << "You are not authorized to do that.\n";
436  return;
437  }
438  alien = races[who - 1];
439  Race = races[Playernum - 1];
440  if (alien->Guest && !Race->God) {
441  g.out << "You can't give this player anything.\n";
442  return;
443  }
444  if (Race->Guest) {
445  g.out << "You can't give anyone anything.\n";
446  return;
447  }
448  /* check to see if both players are mutually allied */
449  if (!Race->God &&
450  !(isset(Race->allied, who) && isset(alien->allied, Playernum))) {
451  g.out << "You two are not mutually allied.\n";
452  return;
453  }
454  auto shipno = string_to_shipnum(argv[2]);
455  if (!shipno) {
456  g.out << "Illegal ship number.\n";
457  return;
458  }
459 
460  auto ship = getship(*shipno);
461  if (!ship) {
462  g.out << "No such ship.\n";
463  return;
464  }
465 
466  if (ship->owner != Playernum || !ship->alive) {
467  DontOwnErr(Playernum, Governor, *shipno);
468  return;
469  }
470  if (ship->type == ShipType::STYPE_POD) {
471  g.out << "You cannot change the ownership of spore pods.\n";
472  return;
473  }
474 
475  if ((ship->popn + ship->troops) && !Race->God) {
476  g.out << "You can't give this ship away while it has crew/mil on board.\n";
477  return;
478  }
479  if (ship->ships && !Race->God) {
480  g.out
481  << "You can't give away this ship, it has other ships loaded on it.\n";
482  return;
483  }
484  switch (ship->whatorbits) {
485  case ScopeLevel::LEVEL_UNIV:
486  if (!enufAP(Playernum, Governor, Sdata.AP[Playernum - 1], APcount)) {
487  return;
488  }
489  break;
490  default:
491  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1],
492  APcount)) {
493  return;
494  }
495  break;
496  }
497 
498  ship->owner = who;
499  ship->governor = 0; /* give to the leader */
500  capture_stuff(*ship, g);
501 
502  putship(&*ship);
503 
504  /* set inhabited/explored bits */
505  switch (ship->whatorbits) {
506  case ScopeLevel::LEVEL_UNIV:
507  break;
508  case ScopeLevel::LEVEL_STAR:
509  getstar(&(Stars[ship->storbits]), (int)ship->storbits);
510  setbit(Stars[ship->storbits]->explored, who);
511  putstar(Stars[ship->storbits], (int)ship->storbits);
512  break;
513  case ScopeLevel::LEVEL_PLAN: {
514  getstar(&(Stars[ship->storbits]), (int)ship->storbits);
515  setbit(Stars[ship->storbits]->explored, who);
516  putstar(Stars[ship->storbits], (int)ship->storbits);
517 
518  auto planet = getplanet((int)ship->storbits, (int)ship->pnumorbits);
519  planet.info[who - 1].explored = 1;
520  putplanet(planet, Stars[ship->storbits], (int)ship->pnumorbits);
521 
522  } break;
523  default:
524  g.out << "Something wrong with this ship's scope.\n";
525  return;
526  }
527 
528  switch (ship->whatorbits) {
529  case ScopeLevel::LEVEL_UNIV:
530  deductAPs(Playernum, Governor, APcount, 0, 1);
531  return;
532  default:
533  deductAPs(Playernum, Governor, APcount, g.snum, 0);
534  break;
535  }
536  g.out << "Owner changed.\n";
537  sprintf(buf, "%s [%d] gave you %s at %s.\n", Race->name, Playernum,
538  ship_to_string(*ship).c_str(), prin_ship_orbits(&*ship));
539  warn(who, 0, buf);
540 
541  if (!Race->God) {
542  sprintf(buf, "%s [%d] gives %s [%d] a ship.\n", Race->name, Playernum,
543  alien->name, who);
544  post(buf, TRANSFER);
545  }
546 }
547 
548 void page(const command_t &argv, GameObj &g) {
549  player_t Playernum = g.player;
550  governor_t Governor = g.governor;
551  int APcount = g.god ? 0 : 1;
552  int i;
553  int who;
554  int gov;
555  int to_block;
556  int dummy[2];
557  racetype *Race;
558  racetype *alien;
559 
560  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1], APcount))
561  return;
562 
563  gov = 0; // TODO(jeffbailey): Init to zero.
564  to_block = 0;
565  if (argv[1] == "block") {
566  to_block = 1;
567  g.out << "Paging alliance block.\n";
568  who = 0; // TODO(jeffbailey): Init to zero to be sure it's initialized.
569  gov = 0; // TODO(jeffbailey): Init to zero to be sure it's initialized.
570  } else {
571  if (!(who = get_player(argv[1]))) {
572  g.out << "No such player.\n";
573  return;
574  }
575  alien = races[who - 1];
576  APcount *= !alien->God;
577  if (argv.size() > 1) gov = std::stoi(argv[2]);
578  }
579 
580  switch (g.level) {
581  case ScopeLevel::LEVEL_UNIV:
582  g.out << "You can't make pages at universal scope.\n";
583  break;
584  default:
585  getstar(&Stars[g.snum], g.snum);
586  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1],
587  APcount)) {
588  return;
589  }
590 
591  Race = races[Playernum - 1];
592 
593  sprintf(buf, "%s \"%s\" page(s) you from the %s star system.\n",
594  Race->name, Race->governor[Governor].name, Stars[g.snum]->name);
595 
596  if (to_block) {
597  dummy[0] =
598  Blocks[Playernum - 1].invite[0] & Blocks[Playernum - 1].pledge[0];
599  dummy[1] =
600  Blocks[Playernum - 1].invite[1] & Blocks[Playernum - 1].pledge[1];
601  for (i = 1; i <= Num_races; i++)
602  if (isset(dummy, i) && i != Playernum) notify_race(i, buf);
603  } else {
604  if (argv.size() > 1)
605  notify(who, gov, buf);
606  else
607  notify_race(who, buf);
608  }
609 
610  g.out << "Request sent.\n";
611  break;
612  }
613  deductAPs(Playernum, Governor, APcount, g.snum, 0);
614 }
615 
616 void send_message(const command_t &argv, GameObj &g) {
617  player_t Playernum = g.player;
618  governor_t Governor = g.governor;
619  bool postit = argv[0] == "post";
620  int APcount;
621  if (postit) {
622  APcount = 0;
623  } else {
624  APcount = g.god ? 0 : 1;
625  }
626  int who;
627  int i;
628  int j;
629  int to_block;
630  int dummy[2];
631  int to_star;
632  int star;
633  int start;
634  char msg[1000];
635  placetype where;
636  racetype *Race;
637  racetype *alien;
638 
639  star = 0; // TODO(jeffbailey): Init to zero.
640  who = 0; // TODO(jeffbailey): Init to zero.
641 
642  to_star = to_block = 0;
643 
644  if (argv.size() < 2) {
645  g.out << "Send what?\n";
646  return;
647  }
648  if (postit) {
649  Race = races[Playernum - 1];
650  sprintf(msg, "%s \"%s\" [%d,%d]: ", Race->name,
651  Race->governor[Governor].name, Playernum, Governor);
652  /* put the message together */
653  for (j = 1; j < argv.size(); j++) {
654  sprintf(buf, "%s ", argv[j].c_str());
655  strcat(msg, buf);
656  }
657  strcat(msg, "\n");
658  post(msg, ANNOUNCE);
659  return;
660  }
661  if (argv[1] == "block") {
662  to_block = 1;
663  g.out << "Sending message to alliance block.\n";
664  if (!(who = get_player(argv[2]))) {
665  g.out << "No such alliance block.\n";
666  return;
667  }
668  alien = races[who - 1];
669  APcount *= !alien->God;
670  } else if (argv[1] == "star") {
671  to_star = 1;
672  g.out << "Sending message to star system.\n";
673  where = getplace(g, argv[2], 1);
674  if (where.err || where.level != ScopeLevel::LEVEL_STAR) {
675  g.out << "No such star.\n";
676  return;
677  }
678  star = where.snum;
679  getstar(&(Stars[star]), star);
680  } else {
681  if (!(who = get_player(argv[1]))) {
682  g.out << "No such player.\n";
683  return;
684  }
685  alien = races[who - 1];
686  APcount *= !alien->God;
687  }
688 
689  switch (g.level) {
690  case ScopeLevel::LEVEL_UNIV:
691  g.out << "You can't send messages from universal scope.\n";
692  return;
693 
694  case ScopeLevel::LEVEL_SHIP:
695  g.out << "You can't send messages from ship scope.\n";
696  return;
697 
698  default:
699  getstar(&Stars[g.snum], g.snum);
700  if (!enufAP(Playernum, Governor, Stars[g.snum]->AP[Playernum - 1],
701  APcount))
702  return;
703  break;
704  }
705 
706  Race = races[Playernum - 1];
707 
708  /* send the message */
709  if (to_block)
710  sprintf(msg, "%s \"%s\" [%d,%d] to %s [%d]: ", Race->name,
711  Race->governor[Governor].name, Playernum, Governor,
712  Blocks[who - 1].name, who);
713  else if (to_star)
714  sprintf(msg, "%s \"%s\" [%d,%d] to inhabitants of %s: ", Race->name,
715  Race->governor[Governor].name, Playernum, Governor,
716  Stars[star]->name);
717  else
718  sprintf(msg, "%s \"%s\" [%d,%d]: ", Race->name,
719  Race->governor[Governor].name, Playernum, Governor);
720 
721  if (to_star || to_block || isdigit(*argv[2].c_str()))
722  start = 3;
723  else if (postit)
724  start = 1;
725  else
726  start = 2;
727  /* put the message together */
728  for (j = start; j < argv.size(); j++) {
729  sprintf(buf, "%s ", argv[j].c_str());
730  strcat(msg, buf);
731  }
732  /* post it */
733  sprintf(buf,
734  "%s \"%s\" [%d,%d] has sent you a telegram. Use `read' to read it.\n",
735  Race->name, Race->governor[Governor].name, Playernum, Governor);
736  if (to_block) {
737  dummy[0] = (Blocks[who - 1].invite[0] & Blocks[who - 1].pledge[0]);
738  dummy[1] = (Blocks[who - 1].invite[1] & Blocks[who - 1].pledge[1]);
739  sprintf(buf,
740  "%s \"%s\" [%d,%d] sends a message to %s [%d] alliance block.\n",
741  Race->name, Race->governor[Governor].name, Playernum, Governor,
742  Blocks[who - 1].name, who);
743  for (i = 1; i <= Num_races; i++) {
744  if (isset(dummy, i)) {
745  notify_race(i, buf);
746  push_telegram_race(i, msg);
747  }
748  }
749  } else if (to_star) {
750  sprintf(buf, "%s \"%s\" [%d,%d] sends a stargram to %s.\n", Race->name,
751  Race->governor[Governor].name, Playernum, Governor,
752  Stars[star]->name);
753  notify_star(Playernum, Governor, star, buf);
754  warn_star(Playernum, star, msg);
755  } else {
756  int gov;
757  if (who == Playernum) APcount = 0;
758  if (isdigit(*argv[2].c_str()) && (gov = std::stoi(argv[2])) >= 0 &&
759  gov <= MAXGOVERNORS) {
760  push_telegram(who, gov, msg);
761  notify(who, gov, buf);
762  } else {
763  push_telegram_race(who, msg);
764  notify_race(who, buf);
765  }
766 
767  alien = races[who - 1];
768  /* translation modifier increases */
769  alien->translate[Playernum - 1] =
770  MIN(alien->translate[Playernum - 1] + 2, 100);
771  putrace(alien);
772  }
773  g.out << "Message sent.\n";
774  deductAPs(Playernum, Governor, APcount, g.snum, 0);
775 }
776 
777 void read_messages(const command_t &argv, GameObj &g) {
778  // TODO(jeffbailey): int APcount = 0;
779  player_t Playernum = g.player;
780  governor_t Governor = g.governor;
781  if (argv.size() == 1 || argv[1] == "telegram")
782  teleg_read(g);
783  else if (argv[1] == "news") {
784  notify(Playernum, Governor, CUTE_MESSAGE);
785  notify(Playernum, Governor,
786  "\n---------- Declarations ----------\n");
787  news_read(Playernum, Governor, DECLARATION);
788  notify(Playernum, Governor,
789  "\n---------- Combat ----------\n");
790  news_read(Playernum, Governor, COMBAT);
791  notify(Playernum, Governor,
792  "\n---------- Business ----------\n");
793  news_read(Playernum, Governor, TRANSFER);
794  notify(Playernum, Governor,
795  "\n---------- Bulletins ----------\n");
796  news_read(Playernum, Governor, ANNOUNCE);
797  } else
798  g.out << "Read what?\n";
799 }
800 
801 void motto(const command_t &argv, GameObj &g) {
802  // TODO(jeffbailey): int APcount = 0;
803  player_t Playernum = g.player;
804  governor_t Governor = g.governor;
805 
806  std::stringstream ss_message;
807  std::copy(++argv.begin(), argv.end(),
808  std::ostream_iterator<std::string>(ss_message, " "));
809  std::string message = ss_message.str();
810 
811  if (Governor) {
812  g.out << "You are not authorized to do this.\n";
813  return;
814  }
815  strncpy(Blocks[Playernum - 1].motto, message.c_str(), MOTTOSIZE - 1);
816  Putblock(Blocks);
817  g.out << "Done.\n";
818 }
819 
820 void name(const command_t &argv, GameObj &g) {
821  int APcount = 0;
822  player_t Playernum = g.player;
823  governor_t Governor = g.governor;
824  char *ch;
825  int spaces;
826  unsigned char check = 0;
827  char string[1024];
828  char tmp[128];
829  racetype *Race;
830 
831  if (argv.size() < 3 || !isalnum(argv[2][0])) {
832  g.out << "Illegal name format.\n";
833  return;
834  }
835 
836  sprintf(buf, "%s", argv[2].c_str());
837  for (int i = 3; i < argv.size(); i++) {
838  sprintf(tmp, " %s", argv[i].c_str());
839  strcat(buf, tmp);
840  }
841 
842  sprintf(string, "%s", buf);
843 
844  /* make sure there are no ^'s or '/' in name,
845  also make sure the name has at least 1 character in it */
846  ch = string;
847  spaces = 0;
848  while (*ch != '\0') {
849  check |=
850  ((!isalnum(*ch) && !(*ch == ' ') && !(*ch == '.')) || (*ch == '/'));
851  ch++;
852  if (*ch == ' ') spaces++;
853  }
854 
855  if (spaces == strlen(buf)) {
856  g.out << "Illegal name.\n";
857  return;
858  }
859 
860  if (strlen(buf) < 1 || check) {
861  sprintf(buf, "Illegal name %s.\n", check ? "form" : "length");
862  notify(Playernum, Governor, buf);
863  return;
864  }
865 
866  if (argv[1] == "ship") {
867  if (g.level == ScopeLevel::LEVEL_SHIP) {
868  auto ship = getship(g.shipno);
869  strncpy(ship->name, buf, SHIP_NAMESIZE);
870  putship(&*ship);
871  g.out << "Name set.\n";
872  return;
873  }
874  g.out << "You have to 'cs' to a ship to name it.\n";
875  return;
876  }
877  if (argv[1] == "class") {
878  if (g.level == ScopeLevel::LEVEL_SHIP) {
879  auto ship = getship(g.shipno);
880  if (ship->type != ShipType::OTYPE_FACTORY) {
881  g.out << "You are not at a factory!\n";
882  return;
883  }
884  if (ship->on) {
885  g.out << "This factory is already on line.\n";
886  return;
887  }
888  strncpy(ship->shipclass, buf, SHIP_NAMESIZE - 1);
889  putship(&*ship);
890  g.out << "Class set.\n";
891  return;
892  }
893  g.out << "You have to 'cs' to a factory to name the ship class.\n";
894  return;
895  }
896  if (argv[1] == "block") {
897  /* name your alliance block */
898  if (Governor) {
899  g.out << "You are not authorized to do this.\n";
900  return;
901  }
902  strncpy(Blocks[Playernum - 1].name, buf, RNAMESIZE - 1);
903  Putblock(Blocks);
904  g.out << "Done.\n";
905  } else if (argv[1] == "star") {
906  if (g.level == ScopeLevel::LEVEL_STAR) {
907  Race = races[Playernum - 1];
908  if (!Race->God) {
909  g.out << "Only dieties may name a star.\n";
910  return;
911  }
912  strncpy(Stars[g.snum]->name, buf, NAMESIZE - 1);
913  putstar(Stars[g.snum], g.snum);
914  } else {
915  g.out << "You have to 'cs' to a star to name it.\n";
916  return;
917  }
918  } else if (argv[1] == "planet") {
919  if (g.level == ScopeLevel::LEVEL_PLAN) {
920  getstar(&Stars[g.snum], g.snum);
921  Race = races[Playernum - 1];
922  if (!Race->God) {
923  g.out << "Only deity can rename planets.\n";
924  return;
925  }
926  strncpy(Stars[g.snum]->pnames[g.pnum], buf, NAMESIZE - 1);
927  putstar(Stars[g.snum], g.snum);
928  deductAPs(Playernum, Governor, APcount, g.snum, 0);
929  } else {
930  g.out << "You have to 'cs' to a planet to name it.\n";
931  return;
932  }
933  } else if (argv[1] == "race") {
934  Race = races[Playernum - 1];
935  if (Governor) {
936  g.out << "You are not authorized to do this.\n";
937  return;
938  }
939  strncpy(Race->name, buf, RNAMESIZE - 1);
940  sprintf(buf, "Name changed to `%s'.\n", Race->name);
941  notify(Playernum, Governor, buf);
942  putrace(Race);
943  } else if (argv[1] == "governor") {
944  Race = races[Playernum - 1];
945  strncpy(Race->governor[Governor].name, buf, RNAMESIZE - 1);
946  sprintf(buf, "Name changed to `%s'.\n", Race->governor[Governor].name);
947  notify(Playernum, Governor, buf);
948  putrace(Race);
949  } else {
950  g.out << "I don't know what you mean.\n";
951  return;
952  }
953 }
954 
955 void announce(const command_t &argv, GameObj &g) {
956  player_t Playernum = g.player;
957  governor_t Governor = g.governor;
958 
959  enum class Communicate {
960  ANN,
961  BROADCAST,
962  SHOUT,
963  THINK,
964  };
965 
966  Communicate mode;
967  if (argv[0] == "announce")
968  mode = Communicate::ANN;
969  else if (argv[0] == "broadcast")
970  mode = Communicate::BROADCAST;
971  else if (argv[0] == "'")
972  mode = Communicate::BROADCAST;
973  else if (argv[0] == "shout")
974  mode = Communicate::SHOUT;
975  else if (argv[0] == "think")
976  mode = Communicate::THINK;
977  else {
978  g.out << "Not sure how you got here.\n";
979  return;
980  }
981 
982  racetype *Race;
983  char symbol;
984 
985  Race = races[Playernum - 1];
986  if (mode == Communicate::SHOUT && !Race->God) {
987  g.out << "You are not privileged to use this command.\n";
988  return;
989  }
990 
991  std::stringstream ss_message;
992  std::copy(++argv.begin(), argv.end(),
993  std::ostream_iterator<std::string>(ss_message, " "));
994  std::string message = ss_message.str();
995 
996  switch (g.level) {
997  case ScopeLevel::LEVEL_UNIV:
998  if (mode == Communicate::ANN) mode = Communicate::BROADCAST;
999  break;
1000  default:
1001  if ((mode == Communicate::ANN) &&
1002  !(!!isset(Stars[g.snum]->inhabited, Playernum) || Race->God)) {
1003  g.out << "You do not inhabit this system or have diety privileges.\n";
1004  return;
1005  }
1006  }
1007 
1008  switch (mode) {
1009  case Communicate::ANN:
1010  symbol = ':';
1011  break;
1012  case Communicate::BROADCAST:
1013  symbol = '>';
1014  break;
1015  case Communicate::SHOUT:
1016  symbol = '!';
1017  break;
1018  case Communicate::THINK:
1019  symbol = '=';
1020  break;
1021  }
1022  char msg[1000];
1023  sprintf(msg, "%s \"%s\" [%d,%d] %c %s\n", Race->name,
1024  Race->governor[Governor].name, Playernum, Governor, symbol,
1025  message.c_str());
1026 
1027  switch (mode) {
1028  case Communicate::ANN:
1029  d_announce(Playernum, Governor, g.snum, msg);
1030  break;
1031  case Communicate::BROADCAST:
1032  d_broadcast(Playernum, Governor, msg);
1033  break;
1034  case Communicate::SHOUT:
1035  d_shout(Playernum, Governor, msg);
1036  break;
1037  case Communicate::THINK:
1038  d_think(Playernum, Governor, msg);
1039  break;
1040  }
1041 }
void teleg_read(GameObj &g)
Definition: tele.cc:176
void post(const char *origmsg, int type)
Definition: tele.cc:63
#define MAXGOVERNORS
Definition: tweakables.h:312
double morale_factor(double x)
Definition: shlmisc.cc:239
#define MOTTOSIZE
Definition: tweakables.h:68
#define CUTE_MESSAGE
Definition: files.h:16
Planet getplanet(const starnum_t star, const planetnum_t pnum)
Definition: files_shl.cc:335
#define SHIP_NAMESIZE
Definition: ships.h:102
void personal(const command_t &argv, GameObj &g)
Definition: name.cc:33
#define TRANSFER
Definition: files.h:18
#define isset(a, i)
Definition: vars.h:312
#define setbit(a, i)
Definition: vars.h:310
void page(const command_t &argv, GameObj &g)
Definition: name.cc:548
void announce(const command_t &argv, GameObj &g)
Definition: name.cc:955
#define RNAMESIZE
Definition: tweakables.h:67
#define MIN(x, y)
Definition: tweakables.h:213
void pay(const command_t &argv, GameObj &g)
Definition: name.cc:373
#define PERSONALSIZE
Definition: tweakables.h:69
#define ANNOUNCE
Definition: files.h:20
void news_read(int Playernum, int Governor, int type)
Definition: tele.cc:219
void insurgency(const command_t &argv, GameObj &g)
Definition: name.cc:240
void deductAPs(const player_t Playernum, const governor_t Governor, unsigned int n, starnum_t snum, int sdata)
Definition: shlmisc.cc:214
void read_messages(const command_t &argv, GameObj &g)
Definition: name.cc:777
int enufAP(int Playernum, int Governor, unsigned short AP, int x)
Definition: shlmisc.cc:131
void motto(const command_t &argv, GameObj &g)
Definition: name.cc:801
#define DECLARATION
Definition: files.h:17
void Putblock(struct block b[MAXPLAYERS])
Definition: files_shl.cc:1649
void putstar(startype *s, starnum_t snum)
Definition: files_shl.cc:813
void send_message(const command_t &argv, GameObj &g)
Definition: name.cc:616
void putplanet(const Planet &p, startype *star, const int pnum)
Definition: files_shl.cc:934
void getstar(startype **s, int star)
Definition: files_shl.cc:281
void give(const command_t &argv, GameObj &g)
Definition: name.cc:422
#define COMBAT
Definition: files.h:19
#define NAMESIZE
Definition: tweakables.h:66
int revolt(Planet *pl, int victim, int agent)
Definition: dissolve.cc:134
#define INSURG_FACTOR
Definition: tweakables.h:275
void name(const command_t &argv, GameObj &g)
Definition: name.cc:820
void bless(const command_t &argv, GameObj &g)
Definition: name.cc:50
int control(int Playernum, int Governor, startype *star)
Definition: mobiliz.cc:110
void putrace(Race *r)
Definition: files_shl.cc:808