<URL: http://bugs.freeciv.org/Ticket/Display.html?id=34431 >

On 1/24/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  This adds new requirement type: minimum AI level. This allows
> creating cheating effects for hard level AI in effects.ruleset.
>  This is just first version. More work is needed before this can go
> in. There probably should be two requirement types instead of one:
> 'Minimum AI level' (as in this patch) for creating bonus effects for
> hard level AI and 'Maximum AI level' for creating penalties for novice
> level AI.
>
>  Making this required more changes to ai level name handling than I
> anticipated. I'll probably split those changes to separate patch to be
> committed first.

 - Level name handling is now in #34566 and this patch applies on top of it.
 - Requirement is no longer minimum AI level, but exact level.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/helpdata.c freeciv/client/helpdata.c
--- freeciv/client/helpdata.c	2007-01-23 16:05:15.000000000 +0200
+++ freeciv/client/helpdata.c	2007-01-26 19:55:45.000000000 +0200
@@ -210,6 +210,10 @@
     cat_snprintf(buf, bufsz, _("Requires a minimum size of %d.\n\n"),
 		 req->source.value.minsize);
     return;
+  case REQ_AI:
+    cat_snprintf(buf, bufsz, _("Requires AI player of level %s.\n\n"),
+                 ai_level_name(req->source.value.level));
+    return;
   }
   assert(0);
 }
diff -Nurd -X.diff_ignore freeciv/common/requirements.c freeciv/common/requirements.c
--- freeciv/common/requirements.c	2006-07-17 23:56:46.000000000 +0300
+++ freeciv/common/requirements.c	2007-01-26 19:58:49.000000000 +0200
@@ -41,7 +41,8 @@
   "UnitClass",
   "OutputType",
   "Specialist",
-  "MinSize"
+  "MinSize",
+  "AI"
 };
 
 /* Names of requirement ranges. These must correspond to enum req_range in
@@ -174,6 +175,12 @@
       return source;
     }
     break;
+  case REQ_AI:
+    source.value.level = find_ai_level_by_name(value);
+    if (source.value.level != AI_LEVEL_LAST) {
+      return source;
+    }
+    break;
   case REQ_LAST:
     break;
   }
@@ -232,6 +239,9 @@
   case REQ_MINSIZE:
     source.value.minsize = value;
     return source;
+  case REQ_AI:
+    source.value.level = value;
+    return source;
   case REQ_LAST:
     return source;
   }
@@ -291,6 +301,9 @@
   case REQ_MINSIZE:
     *value = source->value.minsize;
     return;
+  case REQ_AI:
+    *value = source->value.level;
+    return;
   case REQ_LAST:
     break;
   }
@@ -339,6 +352,7 @@
     case REQ_GOV:
     case REQ_TECH:
     case REQ_NATION:
+    case REQ_AI:
       req.range = REQ_RANGE_PLAYER;
       break;
     }
@@ -359,6 +373,7 @@
     invalid = (req.range < REQ_RANGE_PLAYER);
     break;
   case REQ_GOV:
+  case REQ_AI:
     invalid = (req.range != REQ_RANGE_PLAYER);
     break;
   case REQ_BUILDING:
@@ -860,6 +875,11 @@
   case REQ_MINSIZE:
     eval = target_city && target_city->size >= req->source.value.minsize;
     break;
+  case REQ_AI:
+    eval = target_player
+      && target_player->ai.control
+      && target_player->ai.skill_level == req->source.value.level;
+    break;
   case REQ_LAST:
     assert(0);
     return FALSE;
@@ -922,6 +942,7 @@
   case REQ_NONE:
   case REQ_OUTPUTTYPE:
   case REQ_SPECIALIST: /* Only so long as it's at local range only */
+  case REQ_AI:
     return TRUE;
   case REQ_TECH:
   case REQ_GOV:
@@ -982,6 +1003,8 @@
     return psource1->value.specialist == psource2->value.specialist;
   case REQ_MINSIZE:
     return psource1->value.minsize == psource2->value.minsize;
+  case REQ_AI:
+    return psource1->value.level == psource2->value.level;
   case REQ_LAST:
     break;
   }
@@ -1040,6 +1063,11 @@
     cat_snprintf(buf, bufsz, _("Size %d"),
 		 psource->value.minsize);
     break;
+  case REQ_AI:
+    /* TRANS: "Hard AI" */
+    cat_snprintf(buf, bufsz, _("%s AI"),
+                 ai_level_name(psource->value.level));
+    break;
   case REQ_LAST:
     assert(0);
     break;
diff -Nurd -X.diff_ignore freeciv/common/requirements.h freeciv/common/requirements.h
--- freeciv/common/requirements.h	2006-07-17 23:56:46.000000000 +0300
+++ freeciv/common/requirements.h	2007-01-26 19:48:41.000000000 +0200
@@ -35,6 +35,7 @@
   REQ_OUTPUTTYPE,
   REQ_SPECIALIST,
   REQ_MINSIZE, /* Minimum size: at city range means city size */
+  REQ_AI,      /* AI level of the player */
   REQ_LAST
 };
 
@@ -67,6 +68,7 @@
     Output_type_id outputtype;          /* source output type */
     Specialist_type_id specialist;      /* specialist type */
     int minsize;                        /* source minsize type */
+    enum ai_level level;                /* source AI level */
   } value;                              /* source value */
 };
 
diff -Nurd -X.diff_ignore freeciv/server/cityturn.c freeciv/server/cityturn.c
--- freeciv/server/cityturn.c	2006-07-17 23:56:22.000000000 +0300
+++ freeciv/server/cityturn.c	2007-01-26 19:53:00.000000000 +0200
@@ -835,6 +835,21 @@
 				 API_TYPE_CITY, pcity,
 				 API_TYPE_STRING, "need_minsize");
 	      break;
+            case REQ_AI:
+              /* FIXME: we should skip rather than postpone, since we'll
+               * never be able to meet this req... */
+              notify_player(pplayer, pcity->tile, E_CITY_CANTBUILD,
+                            _("%s can't build %s from the worklist; "
+                              "only AI of level %s may build this.  "
+                              "Postponing..."),
+                            pcity->name,
+                            get_impr_name_ex(pcity, building->index),
+                            ai_level_name(preq->source.value.level));
+              script_signal_emit("building_cant_be_built", 3,
+                                 API_TYPE_BUILDING_TYPE, building,
+                                 API_TYPE_CITY, pcity,
+                                 API_TYPE_STRING, "need_ai_level");
+	      break;
 	    case REQ_NONE:
 	    case REQ_LAST:
 	      assert(0);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to