Freeciv-3.2
Loading...
Searching...
No Matches
diplomats.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19
20/* utility */
21#include "bitvector.h"
22#include "fcintl.h"
23#include "log.h"
24#include "rand.h"
25
26/* common */
27#include "base.h"
28#include "combat.h"
29#include "events.h"
30#include "game.h"
31#include "government.h"
32#include "map.h"
33#include "movement.h"
34#include "player.h"
35#include "research.h"
36#include "unitlist.h"
37
38/* server */
39#include "actiontools.h"
40#include "aiiface.h"
41#include "citytools.h"
42#include "cityturn.h"
43#include "diplhand.h"
44#include "diplomats.h"
45#include "maphand.h"
46#include "notify.h"
47#include "plrhand.h"
48#include "techtools.h"
49#include "unithand.h"
50#include "unittools.h"
51
52/* server/scripting */
53#include "script_server.h"
54
55/****************************************************************************/
56
57static void diplomat_charge_movement (struct unit *pdiplomat,
58 struct tile *ptile);
59static bool diplomat_success_vs_defender(struct unit *patt, struct unit *pdef,
60 struct tile *pdefender_tile,
61 int *att_vet, int *def_vet);
62static bool diplomat_may_lose_gold(struct player *dec_player,
63 struct player *inc_player,
64 int revolt_gold);
65static bool diplomat_infiltrate_tile(struct player *pplayer,
66 struct player *cplayer,
67 const struct action *paction,
68 struct unit *pdiplomat,
69 struct unit *pvictim,
70 struct tile *ptile,
71 struct player **defender_owner);
72static void diplomat_escape(struct player *pplayer, struct unit *pdiplomat,
73 const struct city *pcity,
74 const struct action *paction);
75static void diplomat_escape_full(struct player *pplayer,
76 struct unit *pdiplomat,
77 bool city_related,
78 struct tile *ptile,
79 const char *vlink,
80 const struct action *paction);
81
82/************************************************************************/
97bool spy_poison(struct player *pplayer, struct unit *pdiplomat,
98 struct city *pcity, const struct action *paction)
99{
100 const struct unit_type *act_utype;
101 struct player *cplayer;
102 struct tile *ctile;
103 const char *clink;
104
105 /* Fetch target city's player. Sanity checks. */
106 fc_assert_ret_val(pcity, FALSE);
107 cplayer = city_owner(pcity);
109
110 /* Sanity check: The actor still exists. */
111 fc_assert_ret_val(pplayer, FALSE);
113
115
116 ctile = city_tile(pcity);
117 clink = city_link(pcity);
118
119 log_debug("poison: unit: %d", pdiplomat->id);
120
121 /* Check if the Diplomat/Spy succeeds against defending Diplomats/Spies. */
123 pdiplomat, NULL, ctile, NULL)) {
124 return FALSE;
125 }
126
127 log_debug("poison: infiltrated");
128
129 /* The Spy may get caught while trying to poison the city. */
130 if (action_failed_dice_roll(pplayer, pdiplomat, pcity, cplayer,
131 paction)) {
133 /* TRANS: unit, action */
134 _("Your %s was caught attempting to do %s!"),
139 /* TRANS: nation, unit, action, city */
140 _("You caught %s %s attempting to do %s in %s!"),
144 clink);
145
146 /* This may cause a diplomatic incident */
149
150 /* Execute the caught Spy. */
152
153 return FALSE;
154 }
155
156 log_debug("poison: succeeded");
157
158 /* Poison people! */
159 if (city_reduce_size(pcity, 1, pplayer, "poison")) {
160 /* Notify everybody involved. */
162 _("Your %s poisoned the water supply of %s."),
166 _("%s is suspected of poisoning the water supply of %s."),
167 player_name(pplayer), clink);
168
170 /* The food was poisoned too. */
172 }
173
174 /* Update clients. */
175 city_refresh (pcity);
176 send_city_info(NULL, pcity);
177 } else {
178 /* Notify everybody involved. */
180 _("Your %s destroyed %s by poisoning its water supply."),
184 _("%s is suspected of destroying %s by poisoning its"
185 " water supply."),
186 player_name(pplayer), clink);
187 }
188
189 /* this may cause a diplomatic incident */
192
193 /* Now lets see if the spy survives. */
195
196 return TRUE;
197}
198
199/************************************************************************/
215 struct city *tgt_city, const struct action *paction)
216{
217 const struct unit_type *act_utype;
218 struct player *tgt_player;
219 struct tile *tgt_tile;
220
221 const char *tgt_city_link;
222
223 /* Sanity check: The actor still exists. */
227
228 /* Sanity check: The target city still exists. */
230
231 /* Who to infect. */
233
234 /* Sanity check: The target player still exists. */
236
239
240 log_debug("spread plague: unit: %d", act_unit->id);
241
242 /* Battle all units capable of diplomatic defense. */
244 paction,
246 return FALSE;
247 }
248
249 log_debug("spread plague: infiltrated");
250
251 /* The infector may get caught while trying to spread a plague in the
252 * city. */
254 paction)) {
256 /* TRANS: unit, action */
257 _("Your %s was caught attempting to do %s!"),
262 /* TRANS: nation, unit, action, city */
263 _("You caught %s %s attempting to do %s in %s!"),
268
269 /* This may cause a diplomatic incident */
272
273 /* Execute the caught infector. */
275
276 return FALSE;
277 }
278
279 log_debug("spread plague: succeeded");
280
281 /* Commit bio-terrorism. */
283 /* Update the clients. */
286 }
287
288 /* Notify everyone involved. */
291 /* TRANS: unit, action, city */
292 _("Your %s did %s to %s."),
297 /* TRANS: action, city, nation */
298 _("%s done to %s, %s suspected."),
301
302 /* This may cause a diplomatic incident. */
305
306 /* Try to escape. */
309
310 return TRUE;
311}
312
313/************************************************************************/
324bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat,
325 struct city *pcity,
326 const struct action *paction)
327{
328 struct player *cplayer;
334 struct trade_route_packet_list *routes;
335 const struct unit_type *act_utype;
337
338 /* Fetch target city's player. Sanity checks. */
339 fc_assert_ret_val(pcity, FALSE);
340 cplayer = city_owner(pcity);
342
343 /* Sanity check: The actor still exists. */
344 fc_assert_ret_val(pplayer, FALSE);
346
348
349 /* Sanity check: The target is foreign. */
350 if (cplayer == pplayer) {
351 /* Nothing to do to a domestic target. */
352 return FALSE;
353 }
354
355 log_debug("investigate: unit: %d", pdiplomat->id);
356
358
359 /* Do It... */
360 update_dumb_city(pplayer, pcity);
361 /* Special case for a diplomat/spy investigating a city:
362 The investigator needs to know the supported and present
363 units of a city, whether or not they are fogged. So, we
364 send a list of them all before sending the city info.
365 As this is a special case we bypass send_unit_info. */
369 /* We need to force to send the packet to ensure the client will receive
370 * something (e.g. investigating twice). */
373 unit_list_iterate((pcity->tile)->units, punit) {
375 UNIT_INFO_CITY_PRESENT, pcity->id);
376 /* We need to force to send the packet to ensure the client will receive
377 * something (e.g. investigating twice). */
380 /* Send city info to investigator's player.
381 As this is a special case we bypass send_city_info(). */
382
383 if (any_web_conns()) {
385 } else {
386 webp_ptr = NULL;
387 }
388
391 webp_ptr, routes, TRUE);
392 /* We need to force to send the packet to ensure the client will receive
393 * something and popup the city dialog. */
394 city_packet.original = city_original_owner(pcity, pplayer);
404
405 /* This may cause a diplomatic incident */
407 city_tile(pcity), city_link(pcity));
408
409 /* The actor unit always survive unless the action it self has determined
410 * to always consume it. */
412 /* This unit isn't about to be consumed. Send updated unit information
413 * to the clients. */
415 }
416
418
419 return TRUE;
420}
421
422/************************************************************************/
430 struct city *pcity,
431 const struct action *paction,
432 int request_kind)
433{
434 struct packet_city_sabotage_list packet;
435
436 /* Send city improvements info to player. */
437 BV_CLR_ALL(packet.improvements);
438
440 /* Can see hidden buildings. */
442 if (city_has_building(pcity, ptarget)) {
444 }
446 } else {
447 /* Can't see hidden buildings. */
448 struct vision_site *plrcity;
449
451
452 if (!plrcity) {
453 /* Must know city to remember visible buildings. */
454 return;
455 }
456
458 if (BV_ISSET(plrcity->improvements, improvement_index(ptarget))) {
460 }
462 }
463
464 packet.actor_id = pdiplomat->id;
465 packet.city_id = pcity->id;
466 packet.act_id = paction->id;
467 packet.request_kind = request_kind;
469}
470
471/************************************************************************/
483bool diplomat_embassy(struct player *pplayer, struct unit *pdiplomat,
484 struct city *pcity, const struct action *paction)
485{
486 struct player *cplayer;
487 const struct unit_type *act_utype;
488
489 /* Fetch target city's player. Sanity checks. */
490 fc_assert_ret_val(pcity, FALSE);
491 cplayer = city_owner(pcity);
493
494 /* Sanity check: The actor still exists. */
495 fc_assert_ret_val(pplayer, FALSE);
497
499
500 /* Sanity check: The target is foreign. */
501 if (cplayer == pplayer) {
502 /* Nothing to do to a domestic target. */
503 return FALSE;
504 }
505
506 log_debug("embassy: unit: %d", pdiplomat->id);
507
508 log_debug("embassy: succeeded");
509
510 establish_embassy(pplayer, cplayer);
511
512 /* Notify everybody involved. */
513 notify_player(pplayer, city_tile(pcity),
515 _("You have established an embassy in %s."),
516 city_link(pcity));
519 _("The %s have established an embassy in %s."),
521 city_link(pcity));
522
523 /* this may cause a diplomatic incident */
525 city_tile(pcity), city_link(pcity));
526
527 /* The actor unit always survive unless the action it self has determined
528 * to always consume it. */
530 /* This unit isn't about to be consumed. Send updated unit information
531 * to the clients. */
533 }
534
535 return TRUE;
536}
537
538/************************************************************************/
548bool spy_sabotage_unit(struct player *pplayer, struct unit *pdiplomat,
549 struct unit *pvictim,
550 const struct action *paction)
551{
553 struct player *uplayer;
554 const struct unit_type *act_utype;
555
556 /* Fetch target unit's player. Sanity checks. */
560
561 /* Sanity check: The actor still exists. */
562 fc_assert_ret_val(pplayer, FALSE);
564
566
567 log_debug("sabotage-unit: unit: %d", pdiplomat->id);
568
569 /* N.B: unit_link() always returns the same pointer. */
571
572 /* Diplomatic battle against any diplomatic defender except the intended
573 * victim of the sabotage. */
574 if (!diplomat_infiltrate_tile(pplayer, uplayer,
575 paction,
578 NULL)) {
579 return FALSE;
580 }
581
582 log_debug("sabotage-unit: succeeded");
583
584 if (pvictim->hp < 2) {
585 /* Not possible to halve the hit points. Kill it. */
586 wipe_unit(pvictim, ULR_KILLED, pplayer);
587
588 /* Notify everybody involved. */
591 _("Your %s's successful sabotage killed the %s %s."),
597 /* TRANS: ... the Poles! */
598 _("Your %s was killed by %s sabotage!"),
600 nation_plural_for_player(pplayer));
601 } else {
602 /* Sabotage the unit by removing half its remaining hit points. */
603 pvictim->hp /= 2;
605
606 /* Notify everybody involved. */
609 _("Your %s succeeded in sabotaging the %s %s."),
615 /* TRANS: ... the Poles! */
616 _("Your %s was sabotaged by the %s!"),
618 nation_plural_for_player(pplayer));
619 }
620
621 /* this may cause a diplomatic incident */
624
625 /* Now lets see if the spy survives. */
627
628 return TRUE;
629}
630
631/************************************************************************/
643bool diplomat_bribe(struct player *pplayer, struct unit *pdiplomat,
644 struct unit *pvictim, const struct action *paction)
645{
647 struct player *uplayer;
648 struct tile *victim_tile;
649 int bribe_cost;
650 int diplomat_id;
651 const struct unit_type *act_utype, *victim_type;
652 struct city *pcity;
653 bool bounce;
654
655 /* Fetch target unit's player. Sanity checks. */
660
661 /* Sanity check: The actor still exists. */
662 fc_assert_ret_val(pplayer, FALSE);
665
667
668 /* Sanity check: The target is foreign. */
669 if (uplayer == pplayer) {
670 /* Nothing to do to a domestic target. */
671 return FALSE;
672 }
673
674 /* Sanity check: The victim isn't a unique unit the actor player already
675 * has. */
678 FALSE,
679 "bribe-unit: already got unique unit");
680
681 log_debug("bribe-unit: unit: %d", pdiplomat->id);
682
683 /* Get bribe cost, ignoring any previously saved value. */
685
686 /* If player doesn't have enough gold, can't bribe. */
687 if (pplayer->economic.gold < bribe_cost) {
690 _("You don't have enough gold to bribe the %s %s."),
693 log_debug("bribe-unit: not enough gold");
694 return FALSE;
695 }
696
697 log_debug("bribe-unit: enough gold");
698
699 /* Diplomatic battle against any diplomatic defender except the one that
700 * will get the bribe. */
701 if (!diplomat_infiltrate_tile(pplayer, uplayer,
702 paction,
704 pvictim->tile,
705 NULL)) {
706 return FALSE;
707 }
708
709 log_debug("bribe-unit: succeeded");
710
712 pvictim = unit_change_owner(pvictim, pplayer, pdiplomat->homecity,
713 ULR_BRIBED);
714
715 if (pvictim) {
716 /* N.B.: unit_link always returns the same pointer. As unit_change_owner()
717 * currently remove the old unit and replace by a new one (with a new id),
718 * we want to make link to the new unit. */
720 } else {
722 }
723
725 /* Destroyed by a script */
726 pdiplomat = NULL;
727 }
728
729 /* Notify everybody involved. */
731 /* TRANS: <diplomat> ... <unit> */
732 _("Your %s succeeded in bribing the %s."),
737 }
739 /* TRANS: <unit> ... <Poles> */
740 _("Your %s was bribed by the %s."),
742
743 if (pvictim) {
744 /* The unit may have been on a tile shared with a city or a unit
745 * it no longer can share a tile with. */
746 pcity = tile_city(unit_tile(pvictim));
747 bounce = ((NULL != pcity
749 /* Keep the old behavior (insto check is_non_allied_unit_tile) */
750 || 1 < unit_list_size(unit_tile(pvictim)->units));
751 if (bounce) {
753 }
754 } else {
755 bounce = FALSE;
756 }
757
758 /* This costs! */
759 pplayer->economic.gold -= bribe_cost;
760 if (pplayer->economic.gold < 0) {
761 /* Scripts have deprived us of too much gold before we paid */
762 log_normal("%s has bribed %s but has not %d gold at payment time, "
763 "%d is the discount", player_name(pplayer),
765 -pplayer->economic.gold);
766 pplayer->economic.gold = 0;
767 }
768
769 /* This may cause a diplomatic incident */
772
774 return TRUE;
775 }
776
777 /* Try to move the briber onto the victim's square unless the victim has
778 * been bounced because it couldn't share tile with a unit or city. */
779 if (!bounce
780 /* Try to perform post move forced actions. */
784 pvictim, NULL))
785 /* May have died while trying to do forced actions. */
787 pdiplomat->moves_left = 0;
788 }
789 if (NULL != player_unit_by_number(pplayer, diplomat_id)) {
791 }
792
793 /* Update clients. */
794 send_player_all_c(pplayer, NULL);
795
796 return TRUE;
797}
798
799/************************************************************************/
808 struct tile *tgt_tile, const struct action *paction)
809{
810 int act_unit_id;
811 struct player *tgt_player = NULL;
812 const struct unit_type *act_utype;
813
814 /* Sanity check: The actor still exists. */
817
819 act_unit_id = act_unit->id;
820
821 /* Do the diplomatic battle against a diplomatic defender. */
823 paction,
825 &tgt_player);
826
827 /* Sanity check: the defender had an owner. */
829
831 /* action_consequence_caught() is handled in
832 * diplomat_infiltrate_tile() */
833
834 /* The action was to start a diplomatic battle. */
835 return TRUE;
836 }
837
838 /* This may cause a diplomatic incident. */
841
842 /* The action was to start a diplomatic battle. */
843 return TRUE;
844}
845
846/************************************************************************/
851 struct city *pcity)
852{
853 int times;
855
856 if (bonus < 0) {
857 /* Negative effect value means infinite bonus */
858 times = 0;
859 } else {
860 times = pcity->steal - bonus;
861 if (times < 0) {
862 times = 0;
863 }
864 }
865
866 return times;
867}
868
869/************************************************************************/
891bool diplomat_get_tech(struct player *pplayer, struct unit *pdiplomat,
892 struct city *pcity, Tech_type_id technology,
893 const struct action *paction)
894{
895 struct research *presearch, *cresearch;
896 struct player *cplayer;
897 const struct unit_type *act_utype;
898 int count;
899 int times;
901 bool expected_kills;
902
903 /* We have to check arguments. They are sent to us by a client,
904 so we cannot trust them */
905 fc_assert_ret_val(pcity, FALSE);
906 cplayer = city_owner(pcity);
908
909 /* Sanity check: The actor still exists. */
910 fc_assert_ret_val(pplayer, FALSE);
912
914
915 /* Sanity check: The target is foreign. */
916 if (cplayer == pplayer) {
917 /* Nothing to do to a domestic target. */
918 return FALSE;
919 }
920
921 /* Currently based on if unit is consumed or not. */
924
926 /* Can't choose target. Will steal a random tech. */
927 technology = A_UNSET;
928 }
929
930 /* Targeted technology should be a ruleset defined tech,
931 * "At Spy's Discretion" (A_UNSET) or a future tech (A_FUTURE). */
932 if (technology == A_NONE
933 || (technology != A_FUTURE
934 && !(technology == A_UNSET
936 && !valid_advance_by_number(technology))) {
937 return FALSE;
938 }
939
940 presearch = research_get(pplayer);
942
943 if (technology == A_FUTURE) {
944 if (presearch->future_tech >= cresearch->future_tech) {
945 return FALSE;
946 }
947 } else if (technology != A_UNSET) {
948 if (research_invention_state(presearch, technology) == TECH_KNOWN) {
949 return FALSE;
950 }
951 if (research_invention_state(cresearch, technology) != TECH_KNOWN) {
952 return FALSE;
953 }
954 if (!research_invention_gettable(presearch, technology,
956 return FALSE;
957 }
958 }
959
960 log_debug("steal-tech: unit: %d", pdiplomat->id);
961
962 /* Check if the Diplomat/Spy succeeds against defending Diplomats/Spies. */
963 if (!diplomat_infiltrate_tile(pplayer, cplayer,
964 paction,
966 pcity->tile,
967 NULL)) {
968 return FALSE;
969 }
970
971 log_debug("steal-tech: infiltrated");
972
974
975 /* Check if the Diplomat/Spy succeeds with their task. */
976 /* (Twice as difficult if target is specified.) */
977 /* (If already stolen from, impossible for Diplomats and harder for Spies.) */
978 if (times > 0 && expected_kills) {
979 /* Already stolen from: Diplomat always fails! */
980 count = 1;
981 log_debug("steal-tech: difficulty: impossible");
982 } else {
983 /* Determine difficulty. */
984 count = 1;
986 /* Targeted steal tech is more difficult. */
987 count++;
988 }
989 count += times;
990 log_debug("steal-tech: difficulty: %d", count);
991 /* Determine success or failure. */
992 while (count > 0) {
993 if (action_failed_dice_roll(pplayer, pdiplomat, pcity, cplayer,
994 paction)) {
995 break;
996 }
997 count--;
998 }
999 }
1000
1001 if (count > 0) {
1002 /* Failed to steal a tech. */
1003 if (times > 0 && expected_kills) {
1004 notify_player(pplayer, city_tile(pcity),
1006 /* TRANS: Paris was expecting ... Your Spy was caught */
1007 _("%s was expecting your attempt to steal technology "
1008 "again. Your %s was caught and executed."),
1009 city_link(pcity),
1013 /* TRANS: The Belgian Spy ... from Paris */
1014 _("The %s %s failed to steal technology again from %s. "
1015 "We were prepared for the attempt."),
1018 city_link(pcity));
1019 } else {
1020 notify_player(pplayer, city_tile(pcity),
1022 /* TRANS: Your Spy was caught ... from %s. */
1023 _("Your %s was caught in the attempt of"
1024 " stealing technology from %s."),
1026 city_link(pcity));
1029 /* TRANS: The Belgian Spy ... from Paris */
1030 _("The %s %s failed to steal technology from %s."),
1033 city_link(pcity));
1034 }
1035
1036 /* This may cause a diplomatic incident */
1038 city_tile(pcity), city_link(pcity));
1040 return FALSE;
1041 }
1042
1043 tech_stolen = steal_a_tech(pplayer, cplayer, technology);
1044
1045 if (tech_stolen == A_NONE) {
1046 notify_player(pplayer, city_tile(pcity),
1048 _("No new technology found in %s."),
1049 city_link(pcity));
1052 return FALSE;
1053 }
1054
1055 /* Update stealing player's science progress and research fields */
1056 send_player_all_c(pplayer, NULL);
1057
1058 /* Record the theft. */
1059 (pcity->steal)++;
1060
1061 /* this may cause a diplomatic incident */
1063 city_tile(pcity), city_link(pcity));
1064
1065 /* Check if a spy survives her mission. */
1066 diplomat_escape(pplayer, pdiplomat, pcity, paction);
1067
1068 return TRUE;
1069}
1070
1071/************************************************************************/
1082 int revolt_gold)
1083{
1085 return FALSE;
1086 }
1087
1088 /* Roll the dice. */
1091 PL_("Your %d gold prepared to incite the revolt was lost!",
1092 "Your %d gold prepared to incite the revolt was lost!",
1094 dec_player->economic.gold -= revolt_gold;
1095 /* Lost money was pocketed by fraudulent executioners?
1096 * Or returned to local authority?
1097 * Roll the dice twice. */
1099 inc_player->economic.gold += revolt_gold;
1101 ftc_server,
1102 PL_("Your security service captured %d gold prepared "
1103 "to incite your town!",
1104 "Your security service captured %d gold prepared "
1105 "to incite your town!", revolt_gold), revolt_gold);
1106 }
1107 /* Update clients. */
1110
1111 return TRUE;
1112 } else {
1113 return FALSE;
1114 }
1115}
1116
1117/************************************************************************/
1135bool diplomat_incite(struct player *pplayer, struct unit *pdiplomat,
1136 struct city *pcity, const struct action *paction)
1137{
1138 struct player *cplayer;
1139 struct tile *ctile;
1140 const char *clink;
1141 int revolt_cost;
1142 const struct unit_type *act_utype;
1143
1144 /* Fetch target civilization's player. Sanity checks. */
1145 fc_assert_ret_val(pcity, FALSE);
1146 cplayer = city_owner(pcity);
1148
1149 /* Sanity check: The actor still exists. */
1150 fc_assert_ret_val(pplayer, FALSE);
1152
1153 /* Sanity check: The target is foreign. */
1154 if (cplayer == pplayer) {
1155 /* Nothing to do to a domestic target. */
1156 return FALSE;
1157 }
1158
1160
1161 ctile = city_tile(pcity);
1162 clink = city_link(pcity);
1163
1164 log_debug("incite: unit: %d", pdiplomat->id);
1165
1166 /* Get incite cost, ignoring any previously saved value. */
1167 revolt_cost = city_incite_cost(pplayer, pcity);
1168
1169 /* If player doesn't have enough gold, can't incite a revolt. */
1170 if (pplayer->economic.gold < revolt_cost) {
1172 _("You don't have enough gold to subvert %s."),
1173 clink);
1174 log_debug("incite: not enough gold");
1175 return FALSE;
1176 }
1177
1178 /* Check if the Diplomat/Spy succeeds against defending Diplomats/Spies. */
1179 if (!diplomat_infiltrate_tile(pplayer, cplayer,
1180 paction,
1181 pdiplomat, NULL,
1182 pcity->tile,
1183 NULL)) {
1185 return FALSE;
1186 }
1187
1188 log_debug("incite: infiltrated");
1189
1190 /* Check if the Diplomat/Spy succeeds with their task. */
1191 if (action_failed_dice_roll(pplayer, pdiplomat, pcity, cplayer,
1192 paction)) {
1194 _("Your %s was caught in the attempt"
1195 " of inciting a revolt!"),
1198 _("You caught %s %s attempting"
1199 " to incite a revolt in %s!"),
1202 clink);
1203
1205
1206 /* This may cause a diplomatic incident */
1208 cplayer, ctile, clink);
1209
1211 return FALSE;
1212 }
1213
1214 log_debug("incite: succeeded");
1215
1216 /* Subvert the city to your cause... */
1217
1218 /* City loses some population. */
1219 if (city_size_get(pcity) > 1) {
1220 city_reduce_size(pcity, 1, pplayer, "incited");
1221 }
1222
1223 /* This costs! */
1224 pplayer->economic.gold -= revolt_cost;
1225
1226 /* Notify everybody involved. */
1228 _("Revolt incited in %s, you now rule the city!"),
1229 clink);
1231 _("%s has revolted, %s influence suspected."),
1232 clink,
1234
1235 pcity->shield_stock = 0;
1237
1238 /* You get a technology advance, too! */
1239 steal_a_tech(pplayer, cplayer, A_UNSET);
1240
1241 /* this may cause a diplomatic incident */
1243 cplayer, ctile, clink);
1244
1245 /* Transfer city and units supported by this city (that
1246 are within one square of the city) to the new owner. */
1247 if (transfer_city(pplayer, pcity, 1, TRUE, TRUE, FALSE,
1248 !is_barbarian(pplayer))) {
1249 script_server_signal_emit("city_transferred", pcity, cplayer, pplayer,
1250 "incited");
1251 }
1252
1253 /* Check if a spy survives her mission.
1254 * _After_ transferring the city, or the city area is first fogged
1255 * when the diplomat is removed, and then unfogged when the city
1256 * is transferred. */
1258
1259 /* Update the players gold in the client */
1260 send_player_info_c(pplayer, pplayer->connections);
1261
1262 return TRUE;
1263}
1264
1265/************************************************************************/
1284bool diplomat_sabotage(struct player *pplayer, struct unit *pdiplomat,
1285 struct city *pcity, Impr_type_id improvement,
1286 const struct action *paction)
1287{
1288 struct player *cplayer;
1289 struct impr_type *ptarget;
1290 int count, which;
1291 const struct unit_type *act_utype;
1292
1293 /* Fetch target city's player. Sanity checks. */
1294 fc_assert_ret_val(pcity, FALSE);
1295 cplayer = city_owner(pcity);
1297
1298 /* Sanity check: The actor still exists. */
1299 fc_assert_ret_val(pplayer, FALSE);
1301
1303
1304 log_debug("sabotage: unit: %d", pdiplomat->id);
1305
1306 /* Check if the Diplomat/Spy succeeds against defending Diplomats/Spies. */
1307 if (!diplomat_infiltrate_tile(pplayer, cplayer,
1308 paction,
1309 pdiplomat, NULL,
1310 pcity->tile,
1311 NULL)) {
1312 return FALSE;
1313 }
1314
1315 log_debug("sabotage: infiltrated");
1316
1317 /* Check if the Diplomat/Spy succeeds with their task. */
1318 if (action_failed_dice_roll(pplayer, pdiplomat, pcity, cplayer,
1319 paction)) {
1320 notify_player(pplayer, city_tile(pcity),
1322 _("Your %s was caught in the attempt"
1323 " of industrial sabotage!"),
1327 _("You caught %s %s attempting sabotage in %s!"),
1330 city_link(pcity));
1331
1332 /* This may cause a diplomatic incident */
1334 city_tile(pcity), city_link(pcity));
1335
1337 return FALSE;
1338 }
1339
1340 log_debug("sabotage: succeeded");
1341
1342 /* Examine the city for improvements to sabotage. */
1343 count = 0;
1344 city_built_iterate(pcity, pimprove) {
1345 if (pimprove->sabotage > 0) {
1346 count++;
1347 }
1349
1350 log_debug("sabotage: count of improvements: %d", count);
1351
1352 /* Determine the target (-1 is production). */
1354 /*
1355 * Pick random:
1356 * 50/50 chance to pick production or some improvement.
1357 * Won't pick something that doesn't exit.
1358 * If nothing to do, say so, deduct movement cost and return.
1359 */
1360 if (count == 0 && pcity->shield_stock == 0) {
1361 notify_player(pplayer, city_tile(pcity),
1363 _("Your %s could not find anything to sabotage in %s."),
1365 city_link(pcity));
1368 log_debug("sabotage: random: nothing to do");
1369 return FALSE;
1370 }
1371 if (count == 0 || fc_rand (2) == 1) {
1372 ptarget = NULL;
1373 log_debug("sabotage: random: targeted production");
1374 } else {
1375 ptarget = NULL;
1376 which = fc_rand (count);
1377
1378 city_built_iterate(pcity, pimprove) {
1379 if (pimprove->sabotage > 0) {
1380 if (which > 0) {
1381 which--;
1382 } else {
1383 ptarget = pimprove;
1384 break;
1385 }
1386 }
1388
1389 if (NULL != ptarget) {
1390 log_debug("sabotage: random: targeted improvement: %d (%s)",
1393 } else {
1394 log_error("sabotage: random: targeted improvement error!");
1395 }
1396 }
1397 } else if (improvement < 0) {
1398 /* If told to sabotage production, do so. */
1399 ptarget = NULL;
1400 log_debug("sabotage: specified target production");
1401 } else {
1402 struct impr_type *pimprove = improvement_by_number(improvement);
1403 if (pimprove == NULL) {
1404 log_error("sabotage: requested for invalid improvement %d", improvement);
1405 return FALSE;
1406 }
1407 /*
1408 * Told which improvement to pick:
1409 * If try for wonder or palace, complain, deduct movement cost and return.
1410 * If not available, say so, deduct movement cost and return.
1411 */
1412 if (city_has_building(pcity, pimprove)) {
1413 if (pimprove->sabotage > 0) {
1414 ptarget = pimprove;
1415 log_debug("sabotage: specified target improvement: %d (%s)",
1416 improvement, improvement_rule_name(pimprove));
1417 } else {
1418 notify_player(pplayer, city_tile(pcity),
1420 _("You cannot sabotage a %s!"),
1424 log_debug("sabotage: disallowed target improvement: %d (%s)",
1425 improvement, improvement_rule_name(pimprove));
1426 return FALSE;
1427 }
1428 } else {
1429 notify_player(pplayer, city_tile(pcity),
1431 _("Your %s could not find the %s to sabotage in %s."),
1434 city_link(pcity));
1437 log_debug("sabotage: target improvement not found: %d (%s)",
1438 improvement, improvement_rule_name(pimprove));
1439 return FALSE;
1440 }
1441 }
1442
1443 /* Now, the fun stuff! Do the sabotage! */
1444 if (NULL == ptarget) {
1445 char prod[256];
1446
1447 /* Do it. */
1448 pcity->shield_stock = 0;
1449 nullify_prechange_production(pcity); /* Make it impossible to recover */
1450
1451 /* Report it. */
1452 universal_name_translation(&pcity->production, prod, sizeof(prod));
1453
1454 notify_player(pplayer, city_tile(pcity),
1456 _("Your %s succeeded in destroying"
1457 " the production of %s in %s."),
1459 prod,
1460 city_name_get(pcity));
1463 _("The production of %s was destroyed in %s,"
1464 " %s are suspected."),
1465 prod,
1466 city_link(pcity),
1467 nation_plural_for_player(pplayer));
1468 log_debug("sabotage: sabotaged production");
1469 } else {
1470 int vulnerability = ptarget->sabotage;
1471
1472 /* Sabotage a city improvement. */
1473
1474 /*
1475 * One last chance to get caught:
1476 * If target was specified, and it is in the capital or are
1477 * City Walls, then there is a 50% chance of getting caught.
1478 */
1481 / 100);
1482
1483 if (fc_rand(100) >= vulnerability) {
1484 /* Caught! */
1485 notify_player(pplayer, city_tile(pcity),
1487 _("Your %s was caught in the attempt of sabotage!"),
1491 _("You caught %s %s attempting"
1492 " to sabotage the %s in %s!"),
1496 city_link(pcity));
1497
1498 /* This may cause a diplomatic incident */
1500 city_tile(pcity), city_link(pcity));
1501
1503 log_debug("sabotage: caught in capital or on city walls");
1504 return FALSE;
1505 }
1506
1507 /* Report it. */
1508 notify_player(pplayer, city_tile(pcity),
1510 _("Your %s destroyed the %s in %s."),
1513 city_link(pcity));
1516 _("The %s destroyed the %s in %s."),
1517 nation_plural_for_player(pplayer),
1519 city_link(pcity));
1520 log_debug("sabotage: sabotaged improvement: %d (%s)",
1523
1524 /* Do it. */
1525 building_lost(pcity, ptarget, "sabotaged", pdiplomat);
1526
1527 /* FIXME: Lua script might have destroyed the diplomat, the city, or even the player.
1528 * Avoid dangling pointers below in that case. */
1529 }
1530
1531 /* Update clients. */
1532 send_city_info(NULL, pcity);
1533
1534 /* this may cause a diplomatic incident */
1536 city_tile(pcity), city_link(pcity));
1537
1538 /* Check if a spy survives her mission. */
1539 diplomat_escape(pplayer, pdiplomat, pcity, paction);
1540
1541 return TRUE;
1542}
1543
1544/************************************************************************/
1557 struct city *tgt_city, const struct action *paction)
1558{
1559 struct player *tgt_player;
1560 struct tile *tgt_tile;
1561
1562 const char *tgt_city_link;
1563
1564 int gold_take;
1565 int gold_give;
1566 const struct unit_type *act_utype;
1567
1568 /* Sanity check: The actor still exists. */
1571
1573
1574 /* Sanity check: The target city still exists. */
1576
1577 /* Who to steal from. */
1579
1580 /* Sanity check: The target player still exists. */
1582
1583 /* Sanity check: The target is foreign. */
1584 if (tgt_player == act_player) {
1585 /* Nothing to do to a domestic target. */
1586 return FALSE;
1587 }
1588
1589 /* Sanity check: There is something to steal. */
1590 if (tgt_player->economic.gold <= 0) {
1591 return FALSE;
1592 }
1593
1596
1597 log_debug("steal gold: unit: %d", act_unit->id);
1598
1599 /* Battle all units capable of diplomatic defense. */
1601 paction,
1603 NULL)) {
1604 return FALSE;
1605 }
1606
1607 log_debug("steal gold: infiltrated");
1608
1609 /* The thief may get caught while trying to steal the gold. */
1611 paction)) {
1613 _("Your %s was caught attempting to steal gold!"),
1616 ftc_server,
1617 /* TRANS: nation, unit, city */
1618 _("You caught %s %s attempting"
1619 " to steal your gold in %s!"),
1623
1624 /* This may cause a diplomatic incident */
1627
1628 /* Execute the caught thief. */
1630
1631 return FALSE;
1632 }
1633
1634 log_debug("steal gold: succeeded");
1635
1636 /* The upper limit on how much gold the thief can steal. */
1637 gold_take = (tgt_player->economic.gold
1639 / 1000;
1640
1641 /* How much to actually take. 1 gold is the smallest amount that can be
1642 * stolen. The victim player has at least 1 gold. If they didn't, the
1643 * something to steal sanity check would have aborted the theft. */
1645
1646 log_debug("steal gold: will take %d gold", gold_take);
1647
1648 /* Steal the gold. */
1649 tgt_player->economic.gold -= gold_take;
1650
1651 /* Some gold may be lost during transfer. */
1654 / 1000;
1655
1656 log_debug("steal gold: will give %d gold", gold_give);
1657
1658 /* Pocket the stolen money. */
1659 act_player->economic.gold += gold_give;
1660
1661 /* Notify everyone involved. */
1663 /* TRANS: unit, gold, city */
1664 PL_("Your %s stole %d gold from %s.",
1665 "Your %s stole %d gold from %s.", gold_give),
1668 /* TRANS: gold, city, nation */
1669 PL_("%d gold stolen from %s, %s suspected.",
1670 "%d gold stolen from %s, %s suspected.", gold_take),
1673
1674 /* This may cause a diplomatic incident. */
1677
1678 /* Try to escape. */
1681
1682 /* Update the players' gold in the client */
1685
1686 return TRUE;
1687}
1688
1689/************************************************************************/
1699 struct city *tgt_city,
1700 const struct action *paction)
1701{
1702 struct player *tgt_player;
1703 struct tile *tgt_tile;
1704 const struct unit_type *act_utype;
1705
1706 int normal_tile_prob;
1707
1708 const char *tgt_city_link;
1709
1710 /* Sanity check: The actor still exists. */
1713
1715
1716 /* Sanity check: The target city still exists. */
1718
1719 /* Who to steal from. */
1721
1722 /* Sanity check: The target player still exists. */
1724
1725 /* Sanity check: The target is foreign. */
1726 if (tgt_player == act_player) {
1727 /* Nothing to do to a domestic target. */
1728 return FALSE;
1729 }
1730
1733
1734 log_debug("steal some maps: unit: %d", act_unit->id);
1735
1736 /* Battle all units capable of diplomatic defense. */
1738 paction,
1740 NULL)) {
1741 return FALSE;
1742 }
1743
1744 log_debug("steal some maps: infiltrated");
1745
1746 /* Try to steal the map. */
1748 paction)) {
1750 _("Your %s was caught in an attempt of"
1751 " stealing parts of the %s world map!"),
1755 ftc_server,
1756 _("You caught %s %s attempting to steal"
1757 " parts of your world map in %s!"),
1761
1762 /* This may cause a diplomatic incident. */
1765
1766 /* Execute the caught thief. */
1768
1769 return FALSE;
1770 }
1771
1772 log_debug("steal some maps: succeeded");
1773
1774 /* Steal it. */
1775 normal_tile_prob = 100
1777 &(const struct req_context) {
1778 .player = act_player,
1779 /* City: Decide once requests from ruleset
1780 * authors arrive. Could be target city or
1781 * - with a refactoring - the city at the
1782 * tile that may be transferred. */
1783 /* Tile: Decide once requests from ruleset
1784 * authors arrive. Could be actor unit
1785 * tile, target city tile or even - with a
1786 * refactoring - the tile that may be
1787 * transferred. */
1788 .unit = act_unit,
1789 .unittype = unit_type_get(act_unit),
1790 .action = paction,
1791 },
1792 tgt_player,
1796 /* Could - with a refactoring where EFT_MAPS_STOLEN_PCT
1797 * is evaulated for each tile and the city sent to it
1798 * is the tile to transfer's city - be moved into
1799 * EFT_MAPS_STOLEN_PCT. */
1801
1802 /* Notify everyone involved. */
1804 _("Your %s stole parts of the %s world map in %s."),
1809 _("The %s are suspected of stealing"
1810 " parts of your world map in %s."),
1813
1814 /* This may cause a diplomatic incident. */
1817
1818 /* Try to escape. */
1821
1822 return TRUE;
1823}
1824
1825/************************************************************************/
1835 struct city *tgt_city, const struct action *paction)
1836{
1837 struct player *tgt_player;
1838 struct tile *tgt_tile;
1839
1840 const char *tgt_city_link;
1841 const struct unit_type *act_utype;
1842
1843 /* Sanity check: The actor still exists. */
1846
1848
1849 /* Sanity check: The target city still exists. */
1851
1852 /* The victim. */
1854
1855 /* Sanity check: The target player still exists. */
1857
1860
1861 log_debug("suitcase nuke: unit: %d", act_unit->id);
1862
1863 /* Battle all units capable of diplomatic defense. */
1865 paction,
1867 NULL)) {
1868 return FALSE;
1869 }
1870
1871 log_debug("suitcase nuke: infiltrated");
1872
1873 /* Try to hide the nuke. */
1875 paction)) {
1877 _("Your %s was caught in an attempt of"
1878 " hiding a nuke in %s!"),
1882 ftc_server,
1883 _("You caught %s %s attempting to hide a nuke in %s!"),
1887
1888 /* This may cause a diplomatic incident. */
1891
1892 /* Execute the caught terrorist. */
1894
1895 return FALSE;
1896 }
1897
1898 log_debug("suitcase nuke: succeeded");
1899
1900 /* Notify everyone involved. */
1902 _("Your %s hid a nuke in %s."),
1906 _("The %s are suspected of hiding a nuke in %s."),
1909
1910 /* Try to escape before the blast. */
1913
1915 /* The unit must be wiped here so it won't be seen as a victim of the
1916 * detonation of its own nuke. */
1918 }
1919
1920 /* Detonate the nuke. */
1923
1924 /* This may cause a diplomatic incident. */
1927
1928 return TRUE;
1929}
1930
1931/************************************************************************/
1934static void diplomat_charge_movement(struct unit *pdiplomat, struct tile *ptile)
1935{
1936 pdiplomat->moves_left -=
1937 map_move_cost_unit(&(wld.map), pdiplomat, ptile);
1938 if (pdiplomat->moves_left < 0) {
1939 pdiplomat->moves_left = 0;
1940 }
1941}
1942
1943/************************************************************************/
1951 struct unit *pdefender,
1952 struct tile *pdefender_tile,
1953 int *att_vet, int *def_vet)
1954{
1955 int chance = 50; /* Base 50% chance */
1956
1957 /* There's no challenge for the SuperSpy to gain veterancy from,
1958 * i.e. no veterancy if we exit early in next couple of checks. */
1959 *att_vet = 0;
1960 *def_vet = 0;
1961
1963 /* A defending UTYF_SUPERSPY will defeat every possible attacker. */
1964 return FALSE;
1965 }
1967 /* An attacking UTYF_SUPERSPY will defeat every possible defender
1968 * except another UTYF_SUPERSPY. */
1969 return TRUE;
1970 }
1971
1972 /* Add or remove 25% if spy flag. */
1974 chance += 25;
1975 }
1977 chance -= 25;
1978 }
1979
1980 /* Use power_fact from veteran level to modify chance in a linear way.
1981 * Equal veteran levels cancel out.
1982 * It's probably not good for rulesets to allow this to have more than
1983 * 20% effect. */
1984 {
1985 const struct veteran_level
1987 const struct veteran_level
1989
1991
1992 chance += vatt->power_fact - vdef->power_fact;
1993 }
1994
1995 /* Reduce the chance of an attack by EFT_SPY_RESISTANT percent. */
1997 NULL,
1998 &(const struct req_context) {
1999 .player = tile_owner(pdefender_tile),
2000 .city = tile_city(pdefender_tile),
2002 },
2003 NULL,
2005 ) / 100;
2006
2007 chance = CLIP(0, chance, 100);
2008
2009 /* In a combat between equal strength units the values are 50% / 50%.
2010 * -> scaling that to 100% by doubling, to match scale of chances
2011 * in existing rulesets, and in !combat_odds_scaled_veterancy case. */
2012 *att_vet = (100 - chance) * 2;
2013 *def_vet = chance * 2;
2014
2015 return (int)fc_rand(100) < chance;
2016}
2017
2018/************************************************************************/
2034static bool diplomat_infiltrate_tile(struct player *pplayer,
2035 struct player *cplayer,
2036 const struct action *paction,
2037 struct unit *pdiplomat,
2038 struct unit *pvictim,
2039 struct tile *ptile,
2040 struct player **defender_owner)
2041{
2042 struct unit *punit;
2043 char link_city[MAX_LEN_LINK] = "";
2045 char link_unit[MAX_LEN_LINK];
2046 struct city *pcity = tile_city(ptile);
2047 const struct unit_type *act_utype = unit_type_get(pdiplomat);
2048 int att_vet;
2049 int def_vet;
2050
2051 if (pcity) {
2052 /* N.B.: *_link() always returns the same pointer. */
2054 }
2055
2057 paction))) {
2058 struct player *uplayer = unit_owner(punit);
2059
2060 if (defender_owner != NULL) {
2061 /* Some action performers may want to know defender player. */
2063 }
2064
2066 &att_vet, &def_vet)) {
2067 /* Defending Spy/Diplomat dies. */
2068
2069 /* N.B.: *_link() always returns the same pointer. */
2072
2074 /* TRANS: <unit> ... <diplomat> */
2075 _("An enemy %s has been eliminated by your %s."),
2077
2078 if (pcity) {
2079 if (uplayer == cplayer || cplayer == NULL) {
2081 /* TRANS: <unit> ... <city> ... <diplomat> */
2082 _("Your %s has been eliminated defending %s"
2083 " against a %s."), link_unit, link_city,
2085 } else {
2087 /* TRANS: <nation adj> <unit> ... <city>
2088 * TRANS: ... <diplomat> */
2089 _("A %s %s has been eliminated defending %s "
2090 "against a %s."),
2094 /* TRANS: ... <unit> ... <nation adj> <city>
2095 * TRANS: ... <diplomat> */
2096 _("Your %s has been eliminated defending %s %s "
2097 "against a %s."), link_unit,
2100 }
2101 } else {
2102 if (uplayer == cplayer || cplayer == NULL) {
2104 /* TRANS: <unit> ... <diplomat> */
2105 _("Your %s has been eliminated defending "
2106 "against a %s."), link_unit, link_diplomat);
2107 } else {
2109 /* TRANS: <nation adj> <unit> ... <diplomat> */
2110 _("A %s %s has been eliminated defending "
2111 "against a %s."),
2115 /* TRANS: ... <unit> ... <diplomat> */
2116 _("Your %s has been eliminated defending "
2117 "against a %s."), link_unit, link_diplomat);
2118 }
2119 }
2120
2121 pdiplomat->moves_left = MAX(0, pdiplomat->moves_left - SINGLE_MOVE);
2122
2123 /* Attacking unit became more experienced? */
2127 }
2129 wipe_unit(punit, ULR_ELIMINATED, pplayer);
2130 return FALSE;
2131 } else {
2132 /* Attacking Spy/Diplomat dies. */
2133
2134 const char *victim_link;
2135
2136 /* N.B.: *_link() always returns the same pointer. */
2139
2141 _("Your %s was eliminated by a defending %s."),
2143
2144 if (pcity) {
2145 if (uplayer == cplayer || cplayer == NULL) {
2147 _("Eliminated a %s %s while infiltrating %s."),
2150 } else {
2152 _("A %s %s eliminated a %s %s while infiltrating "
2157 _("Your %s eliminated a %s %s while infiltrating "
2158 "%s."), link_unit,
2161 }
2162 } else {
2163 if (uplayer == cplayer || cplayer == NULL) {
2165 _("Eliminated a %s %s while infiltrating our troops."),
2168 } else {
2170 _("A %s %s eliminated a %s %s while infiltrating our "
2175 /* TRANS: ... <unit> ... <diplomat> */
2176 _("Your %s eliminated a %s %s while infiltrating our "
2177 "troops."), link_unit,
2180 }
2181 }
2182
2183 /* Defending unit became more experienced? */
2187 }
2188
2189 victim_link = NULL;
2190
2192 case ATK_CITY:
2193 victim_link = city_link(pcity);
2194 break;
2195 case ATK_UNIT:
2196 case ATK_UNITS:
2198 : tile_link(ptile);
2199 break;
2200 case ATK_TILE:
2201 case ATK_EXTRAS:
2202 victim_link = tile_link(ptile);
2203 break;
2204 case ATK_SELF:
2205 /* How did a self targeted action end up here? */
2207 break;
2208 case ATK_COUNT:
2209 break;
2210 }
2211
2213
2215 ptile, victim_link);
2216
2218 return FALSE;
2219 }
2220 }
2221
2222 return TRUE;
2223}
2224
2225/************************************************************************/
2235void diplomat_escape(struct player *pplayer, struct unit *pdiplomat,
2236 const struct city *pcity,
2237 const struct action *paction)
2238{
2239 struct tile *ptile;
2240 const char *vlink;
2241
2242 if (pcity) {
2243 ptile = city_tile(pcity);
2244 vlink = city_link(pcity);
2245 } else {
2246 ptile = unit_tile(pdiplomat);
2247 vlink = NULL;
2248 }
2249
2250 return diplomat_escape_full(pplayer, pdiplomat, pcity != NULL,
2251 ptile, vlink, paction);
2252}
2253
2254/************************************************************************/
2263static void diplomat_escape_full(struct player *pplayer,
2264 struct unit *pdiplomat,
2265 bool city_related,
2266 struct tile *ptile,
2267 const char *vlink,
2268 const struct action *paction)
2269{
2270 int escapechance;
2271 struct city *spyhome;
2272 const struct unit_type *dipltype = unit_type_get(pdiplomat);
2273
2274 fc_assert(paction->actor.is_unit.moves_actor == MAK_ESCAPE);
2275
2276 /* Veteran level's power factor's effect on escape chance is relative to
2277 * unpromoted unit's power factor */
2278 {
2279 const struct veteran_level
2281 const struct veteran_level
2283
2285 + (vunit->power_fact - vbase->power_fact);
2286 }
2287
2288 /* find closest city for escape target */
2290 FALSE, FALSE, TRUE, FALSE, NULL);
2291
2292 if (spyhome
2295 || fc_rand (100) < escapechance)) {
2296 /* Attacking Spy/Diplomat survives. */
2298 _("Your %s has successfully completed"
2299 " the mission and returned unharmed to %s."),
2302 if (maybe_make_veteran(pdiplomat, 100)) {
2304 }
2305
2307 /* Handled by the ruleset. */
2308 0,
2309 FALSE)) {
2311 log_error("Bug in diplomat_escape: Spy can't teleport.");
2312 return;
2313 }
2314
2315 return;
2316 } else {
2317 if (city_related) {
2319 _("Your %s was captured after completing"
2320 " the mission in %s."),
2322 vlink);
2323 } else {
2325 _("Your %s was captured after completing"
2326 " the mission."),
2328 }
2329 }
2330
2332 /* The unit was caught, not spent. It must therefore be deleted by
2333 * hand. */
2335 }
2336}
2337
2338/************************************************************************/
2346bool spy_escape(struct player *pplayer,
2347 struct unit *actor_unit,
2348 struct city *target_city,
2349 struct tile *target_tile,
2350 const struct action *paction)
2351{
2352 const char *vlink;
2354
2355 if (target_city != NULL) {
2358 } else {
2360 }
2361
2362 /* this may cause a diplomatic incident */
2366
2367 /* Try to escape. */
2370
2371 return TRUE;
2372}
2373
2374/************************************************************************/
2378{
2379 int count = 0;
2380
2381 unit_list_iterate((ptile)->units, punit) {
2383 count++;
2384 }
2386
2387 return count;
2388}
const char * action_name_translation(const struct action *action)
Definition actions.c:1991
enum action_target_kind action_get_target_kind(const struct action *paction)
Definition actions.c:1869
#define action_has_result(_act_, _res_)
Definition actions.h:431
void action_consequence_caught(const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
const struct action * action_auto_perf_unit_do(const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
void action_consequence_success(const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
bool action_failed_dice_roll(const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct player *tgt_player, const struct action *paction)
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
bool city_has_building(const struct city *pcity, const struct impr_type *pimprove)
Definition city.c:1240
const char * city_name_get(const struct city *pcity)
Definition city.c:1137
#define city_tile(_pcity_)
Definition city.h:564
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
#define city_owner(_pcity_)
Definition city.h:563
#define city_built_iterate(_pcity, _p)
Definition city.h:834
#define city_built_iterate_end
Definition city.h:840
void package_city(struct city *pcity, struct packet_city_info *packet, struct packet_city_nationalities *nat_packet, struct packet_city_rally_point *rally_packet, struct packet_web_city_info_addition *web_packet, struct trade_route_packet_list *routes, bool dipl_invest)
Definition citytools.c:2526
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2363
bool update_dumb_city(struct player *pplayer, struct city *pcity)
Definition citytools.c:2769
struct city * find_closest_city(const struct tile *ptile, const struct city *pexclcity, const struct player *pplayer, bool only_ocean, bool only_continent, bool only_known, bool only_player, bool only_enemy, const struct unit_class *pclass)
Definition citytools.c:856
int city_original_owner(const struct city *pcity, const struct player *known_for)
Definition citytools.c:3689
bool city_illness_strike(struct city *pcity)
Definition citytools.c:2971
void building_lost(struct city *pcity, const struct impr_type *pimprove, const char *reason, struct unit *destroyer)
Definition citytools.c:3068
bool transfer_city(struct player *ptaker, struct city *pcity, int kill_outside, bool transfer_unit_verbose, bool resolve_stack, bool raze, bool build_free)
Definition citytools.c:1076
#define trade_route_packet_list_iterate_end
Definition citytools.h:28
#define trade_route_packet_list_iterate(ptrlist, ptr)
Definition citytools.h:26
void nullify_prechange_production(struct city *pcity)
Definition cityturn.c:3544
bool city_empty_food_stock(struct city *pcity)
Definition cityturn.c:4249
int city_incite_cost(struct player *pplayer, struct city *pcity)
Definition cityturn.c:3432
bool city_reduce_size(struct city *pcity, citizens pop_loss, struct player *destroyer, const char *reason)
Definition cityturn.c:763
bool city_refresh(struct city *pcity)
Definition cityturn.c:159
struct unit * get_diplomatic_defender(const struct unit *act_unit, const struct unit *pvictim, const struct tile *tgt_tile, const struct action *paction)
Definition combat.c:942
char * incite_cost
Definition comments.c:75
struct unit * actor_unit
Definition dialogs_g.h:55
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city * target_city
Definition dialogs_g.h:56
void establish_embassy(struct player *pplayer, struct player *aplayer)
Definition diplhand.c:701
static void diplomat_escape_full(struct player *pplayer, struct unit *pdiplomat, bool city_related, struct tile *ptile, const char *vlink, const struct action *paction)
Definition diplomats.c:2263
bool spy_escape(struct player *pplayer, struct unit *actor_unit, struct city *target_city, struct tile *target_tile, const struct action *paction)
Definition diplomats.c:2346
bool spy_steal_some_maps(struct player *act_player, struct unit *act_unit, struct city *tgt_city, const struct action *paction)
Definition diplomats.c:1698
int diplomats_unignored_tech_stealings(struct unit *pdiplomat, struct city *pcity)
Definition diplomats.c:850
bool spy_sabotage_unit(struct player *pplayer, struct unit *pdiplomat, struct unit *pvictim, const struct action *paction)
Definition diplomats.c:548
static bool diplomat_may_lose_gold(struct player *dec_player, struct player *inc_player, int revolt_gold)
Definition diplomats.c:1081
bool diplomat_embassy(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, const struct action *paction)
Definition diplomats.c:483
static void diplomat_escape(struct player *pplayer, struct unit *pdiplomat, const struct city *pcity, const struct action *paction)
Definition diplomats.c:2235
void spy_send_sabotage_list(struct connection *pc, struct unit *pdiplomat, struct city *pcity, const struct action *paction, int request_kind)
Definition diplomats.c:429
static bool diplomat_infiltrate_tile(struct player *pplayer, struct player *cplayer, const struct action *paction, struct unit *pdiplomat, struct unit *pvictim, struct tile *ptile, struct player **defender_owner)
Definition diplomats.c:2034
bool diplomat_get_tech(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, Tech_type_id technology, const struct action *paction)
Definition diplomats.c:891
bool diplomat_sabotage(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, Impr_type_id improvement, const struct action *paction)
Definition diplomats.c:1284
bool diplomat_incite(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, const struct action *paction)
Definition diplomats.c:1135
bool spy_steal_gold(struct player *act_player, struct unit *act_unit, struct city *tgt_city, const struct action *paction)
Definition diplomats.c:1556
bool spy_spread_plague(struct player *act_player, struct unit *act_unit, struct city *tgt_city, const struct action *paction)
Definition diplomats.c:214
bool spy_nuke_city(struct player *act_player, struct unit *act_unit, struct city *tgt_city, const struct action *paction)
Definition diplomats.c:1834
static bool diplomat_success_vs_defender(struct unit *patt, struct unit *pdef, struct tile *pdefender_tile, int *att_vet, int *def_vet)
Definition diplomats.c:1950
bool diplomat_investigate(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, const struct action *paction)
Definition diplomats.c:324
static void diplomat_charge_movement(struct unit *pdiplomat, struct tile *ptile)
Definition diplomats.c:1934
bool diplomat_bribe(struct player *pplayer, struct unit *pdiplomat, struct unit *pvictim, const struct action *paction)
Definition diplomats.c:643
bool spy_attack(struct player *act_player, struct unit *act_unit, struct tile *tgt_tile, const struct action *paction)
Definition diplomats.c:807
bool spy_poison(struct player *pplayer, struct unit *pdiplomat, struct city *pcity, const struct action *paction)
Definition diplomats.c:97
int count_diplomats_on_tile(struct tile *ptile)
Definition diplomats.c:2377
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:1070
int Tech_type_id
Definition fc_types.h:377
int Impr_type_id
Definition fc_types.h:376
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
const char * tile_link(const struct tile *ptile)
const struct ft_color ftc_server
const char * city_link(const struct city *pcity)
const char * unit_link(const struct unit *punit)
const char * unit_tile_link(const struct unit *punit)
#define MAX_LEN_LINK
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
#define any_web_conns()
Definition game.h:319
struct impr_type * improvement_by_number(const Impr_type_id id)
Impr_type_id improvement_number(const struct impr_type *pimprove)
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
static int map_move_cost_unit(const struct civ_map *nmap, struct unit *punit, const struct tile *ptile)
Definition map.h:293
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1367
bool give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Definition maphand.c:2696
#define FC_FREE(ptr)
Definition mem.h:41
#define SINGLE_MOVE
Definition movement.h:26
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
#define web_lsend_packet(packetname,...)
Definition packets.h:57
@ UNIT_INFO_CITY_PRESENT
Definition packets.h:69
@ UNIT_INFO_CITY_SUPPORTED
Definition packets.h:68
void lsend_packet_city_nationalities(struct conn_list *dest, const struct packet_city_nationalities *packet, bool force_to_send)
void lsend_packet_trade_route_info(struct conn_list *dest, const struct packet_trade_route_info *packet)
void dlsend_packet_investigate_finished(struct conn_list *dest, int city_id)
void lsend_packet_city_info(struct conn_list *dest, const struct packet_city_info *packet, bool force_to_send)
int send_packet_city_sabotage_list(struct connection *pc, const struct packet_city_sabotage_list *packet)
void lsend_packet_unit_short_info(struct conn_list *dest, const struct packet_unit_short_info *packet, bool force_to_send)
void dlsend_packet_nuke_tile_info(struct conn_list *dest, int tile)
void dlsend_packet_investigate_started(struct conn_list *dest, int city_id)
void lsend_packet_city_rally_point(struct conn_list *dest, const struct packet_city_rally_point *packet, bool force_to_send)
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
Definition player.c:1229
const char * player_name(const struct player *pplayer)
Definition player.c:895
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1405
static bool is_barbarian(const struct player *pplayer)
Definition player.h:489
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1129
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
#define fc_rand(_size)
Definition rand.h:56
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
struct research * research_get(const struct player *pplayer)
Definition research.c:128
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
bool research_invention_gettable(const struct research *presearch, const Tech_type_id tech, bool allow_holes)
Definition research.c:693
void script_server_signal_emit(const char *signal_name,...)
#define CLIP(lower, current, upper)
Definition shared.h:57
#define MAX(x, y)
Definition shared.h:54
Definition city.h:320
int id
Definition city.h:326
struct universal production
Definition city.h:396
int steal
Definition city.h:414
struct tile * tile
Definition city.h:322
int shield_stock
Definition city.h:368
struct unit_list * units_supported
Definition city.h:406
int incite_gold_capt_chance
Definition game.h:146
int diplchance
Definition game.h:142
int incite_gold_loss_chance
Definition game.h:145
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
struct civ_game::@31::@35 server
bool tech_steal_allow_holes
bool steal_maps_reveals_all_cities
bool poison_empties_food_stock
bool combat_odds_scaled_veterancy
struct conn_list * connections
Definition player.h:296
struct player_economic economic
Definition player.h:282
Definition tile.h:50
struct veteran_system * veteran
Definition unittype.h:544
Definition unit.h:138
struct civ_map map
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * valid_advance_by_number(const Tech_type_id id)
Definition tech.c:176
#define A_FUTURE
Definition tech.h:46
#define A_NONE
Definition tech.h:43
#define A_UNSET
Definition tech.h:48
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1234
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_index(_pt_)
Definition tile.h:88
#define tile_owner(_tile)
Definition tile.h:96
bool unit_is_alive(int id)
Definition unit.c:2253
int unit_bribe_cost(struct unit *punit, struct player *briber)
Definition unit.c:2304
#define unit_tile(_pu)
Definition unit.h:397
#define unit_owner(_pu)
Definition unit.h:396
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
void do_nuclear_explosion(const struct action *paction, const struct unit_type *act_utype, struct player *pplayer, struct tile *ptile)
Definition unittools.c:2879
void send_unit_info(struct conn_list *dest, struct unit *punit)
Definition unittools.c:2722
void notify_unit_experience(struct unit *punit)
Definition unittools.c:743
void package_short_unit(struct unit *punit, struct packet_unit_short_info *packet, enum unit_info_use packet_use, int info_city_id)
Definition unittools.c:2665
bool maybe_make_veteran(struct unit *punit, int base_chance)
Definition unittools.c:219
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2131
struct unit * unit_change_owner(struct unit *punit, struct player *pplayer, int homecity, enum unit_loss_reason reason)
Definition unittools.c:2191
bool teleport_unit_to_city(struct unit *punit, struct city *pcity, int move_cost, bool verbose)
Definition unittools.c:1183
void bounce_unit(struct unit *punit, bool verbose)
Definition unittools.c:1221
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * unit_name_translation(const struct unit *punit)
Definition unittype.c:1569
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
Definition unittype.c:1927
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
const struct veteran_level * utype_veteran_level(const struct unit_type *punittype, int level)
Definition unittype.c:2597
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
bool utype_is_consumed_by_action(const struct action *paction, const struct unit_type *utype)
Definition unittype.c:1219
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1560