Author: sveinung
Date: Tue Jul 28 15:28:34 2015
New Revision: 29255

URL: http://svn.gna.org/viewcvs/freeciv?rev=29255&view=rev
Log:
Let rulesets manipulate individual action odds

Introduce the new effect Action_Odds_Pct. Support the actions "Incite City",
"Steal Gold", "Steal Maps" and "Suitcase Nuke" for now.

See patch #5642

Modified:
    trunk/ai/default/daieffects.c
    trunk/common/effects.h
    trunk/doc/README.effects
    trunk/fc_version
    trunk/server/diplomats.c

Modified: trunk/ai/default/daieffects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/daieffects.c?rev=29255&r1=29254&r2=29255&view=diff
==============================================================================
--- trunk/ai/default/daieffects.c       (original)
+++ trunk/ai/default/daieffects.c       Tue Jul 28 15:28:34 2015
@@ -522,6 +522,7 @@
   case EFT_ILLEGAL_ACTION_MOVE_COST:
   case EFT_CASUS_BELLI_CAUGHT:
   case EFT_CASUS_BELLI_SUCCESS:
+  case EFT_ACTION_ODDS_PCT:
     break;
     /* This has no effect for AI */
   case EFT_VISIBLE_WALLS:

Modified: trunk/common/effects.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.h?rev=29255&r1=29254&r2=29255&view=diff
==============================================================================
--- trunk/common/effects.h      (original)
+++ trunk/common/effects.h      Tue Jul 28 15:28:34 2015
@@ -279,6 +279,8 @@
 #define SPECENUM_VALUE108NAME "Casus_Belli_Caught"
 #define SPECENUM_VALUE109 EFT_CASUS_BELLI_SUCCESS
 #define SPECENUM_VALUE109NAME "Casus_Belli_Success"
+#define SPECENUM_VALUE110 EFT_ACTION_ODDS_PCT
+#define SPECENUM_VALUE110NAME "Action_Odds_Pct"
 /* keep this last */
 #define SPECENUM_COUNT EFT_COUNT
 #include "specenum_gen.h"

Modified: trunk/doc/README.effects
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.effects?rev=29255&r1=29254&r2=29255&view=diff
==============================================================================
--- trunk/doc/README.effects    (original)
+++ trunk/doc/README.effects    Tue Jul 28 15:28:34 2015
@@ -246,6 +246,10 @@
     When does an action to another player it causes an incident. This gives
 the victim a casus belli against the player that was caught.
 
+Action_Odds_Pct
+    Modifies the odds of an action being successful. Currently supports the
+    actions "Incite City", "Steal Gold", "Steal Maps" and "Suitcase Nuke".
+
 Size_Adj
     Increase maximum size of a city by amount.
 

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=29255&r1=29254&r2=29255&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Tue Jul 28 15:28:34 2015
@@ -54,7 +54,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jul.24"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2015.Jul.28"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/diplomats.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/diplomats.c?rev=29255&r1=29254&r2=29255&view=diff
==============================================================================
--- trunk/server/diplomats.c    (original)
+++ trunk/server/diplomats.c    Tue Jul 28 15:28:34 2015
@@ -60,6 +60,11 @@
                                      struct unit *pdiplomat,
                                      struct unit *pvictim,
                                      struct tile *ptile);
+static bool diplomat_was_caught(struct player *act_player,
+                                struct unit *act_unit,
+                                struct city *tgt_city,
+                                struct player *tgt_player,
+                                struct action *act);
 static void diplomat_escape(struct player *pplayer, struct unit *pdiplomat,
                             const struct city *pcity);
 static void diplomat_escape_full(struct player *pplayer,
@@ -759,7 +764,8 @@
   log_debug("incite: infiltrated");
 
   /* Check if the Diplomat/Spy succeeds with his/her task. */
-  if (fc_rand (100) >= game.server.diplchance) {
+  if (diplomat_was_caught(pplayer, pdiplomat, pcity, cplayer,
+                          action_by_number(ACTION_SPY_INCITE_CITY))) {
     notify_player(pplayer, ctile, E_MY_DIPLOMAT_FAILED, ftc_server,
                   _("Your %s was caught in the attempt"
                     " of inciting a revolt!"),
@@ -1157,7 +1163,8 @@
   log_debug("steal gold: infiltrated");
 
   /* The thief may get caught while trying to steal the gold. */
-  if (fc_rand (100) >= game.server.diplchance) {
+  if (diplomat_was_caught(act_player, act_unit, tgt_city, tgt_player,
+                          action_by_number(ACTION_SPY_STEAL_GOLD))) {
     notify_player(act_player, tgt_tile, E_MY_DIPLOMAT_FAILED, ftc_server,
                   _("Your %s was caught in an attempt"
                     " of stealing gold!"),
@@ -1276,7 +1283,8 @@
   log_debug("steal some maps: infiltrated");
 
   /* Try to steal the map. */
-  if (fc_rand (100) >= game.server.diplchance) {
+  if (diplomat_was_caught(act_player, act_unit, tgt_city, tgt_player,
+                          action_by_number(ACTION_STEAL_MAPS))) {
     notify_player(act_player, tgt_tile, E_MY_DIPLOMAT_FAILED, ftc_server,
                   _("Your %s was caught in an attempt of"
                     " stealing parts of the %s world map!"),
@@ -1373,7 +1381,8 @@
   log_debug("suitcase nuke: infiltrated");
 
   /* Try to hide the nuke. */
-  if (fc_rand (100) >= game.server.diplchance) {
+  if (diplomat_was_caught(act_player, act_unit, tgt_city, tgt_player,
+                          action_by_number(ACTION_SPY_NUKE))) {
     notify_player(act_player, tgt_tile, E_MY_DIPLOMAT_FAILED, ftc_server,
                   _("Your %s was caught in an attempt of"
                     " hiding a nuke in %s!"),
@@ -1423,6 +1432,37 @@
   /* This may cause a diplomatic incident. */
   action_consequence_success(ACTION_SPY_NUKE, act_player,
                              tgt_player, tgt_tile, tgt_city_link);
+}
+
+/**************************************************************************
+  Returns TRUE iff the spy/diplomat was caught outside of a diplomatic
+  battle.
+**************************************************************************/
+static bool diplomat_was_caught(struct player *act_player,
+                                struct unit *act_unit,
+                                struct city *tgt_city,
+                                struct player *tgt_player,
+                                struct action *act)
+{
+  int odds;
+
+  /* Take the odds from the diplchance setting. */
+  odds = game.server.diplchance;
+
+  /* Let the Action_Odds_Pct effect modify the odds. The advantage of doing
+   * it this way in stead of rolling twice is that Action_Odds_Pct can
+   * increase the odds. */
+  odds += ((odds
+            * get_target_bonus_effects(NULL,
+                                       act_player, tgt_player,
+                                       tgt_city, NULL, NULL,
+                                       act_unit, unit_type(act_unit),
+                                       NULL, NULL, act,
+                                       EFT_ACTION_ODDS_PCT))
+           / 100);
+
+  /* Roll the dice. */
+  return fc_rand (100) >= odds;
 }
 
 /**************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to