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

2007/7/14, Ulrik Sverdrup <[EMAIL PROTECTED]>:
>
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=17187 >
>
> Here are the three patches for this ticket and its two children:
> #39450: Make unit_type etc names available in the scripting api
>   api_class_names_v3.diff
> #39451: Add signal emit to scripting api
>   techsig_v1.diff
> #17187: Move hut code into lua script
>   hut_v3.diff
>

> Hut changes:
> Ported hut_get_barbarian as noted in previous emails. unleash_barbarians
> is available as an api action, as noted before.
>
> Introduced hut_get_limited for ai players with handicap H_LIMITEDHUTS;
> we cannot put this in the script file without passing irrelevant
> parameters to the hut_entered signal callback, or opening ai handicaps
> etc to the script api.
>
> hut_get_limited is a simplified version of the previous behavior; 25
> gold is given as before, but with 1/12 chance the unit is simply wiped
> (normally unleash_barbarians) would be called; but as the wipe is the
> most common outcome this was simplified.

I have here a patch to simplify: unit_enter_hut and move_unit should
return void, not bool. Currently move_unit returns bool, but the
returned value has no point; as stated in the function documentation
checks should be done by the caller, which they also are. The change
to return void has no side effects to current users, previously it did
semantically wrong things, for example;
if a paratrooper landed on a tile, wakes its neighbors and is killed
by auto-attack, the paradrop is reported internally as FALSE, not
successful. However this is ignored in the code and does not show
ofcourse.

The attached patch applies on top of the three previous.

> One hut issue remains: Only Legions are given as mercenaries. This can
> be solved by porting a method to find a unittype for role, or simplified
> now that different rulesets can customize by script.

We should probably port find_a_unit_type to find units by role to the
scripting api.

diff --git a/server/maphand.c b/server/maphand.c
index d065ab7..4979edd 100644
--- a/server/maphand.c
+++ b/server/maphand.c
@@ -1526,7 +1526,7 @@ static void bounce_units_on_terrain_change(struct tile *ptile)
 			   punit->tile, E_UNIT_RELOCATED,
 			   _("Moved your %s due to changing terrain."),
 			   unit_name_translation(punit));
-	  (void) move_unit(punit, ptile2, 0);
+	  move_unit(punit, ptile2, 0);
 	  if (punit->activity == ACTIVITY_SENTRY) {
 	    handle_unit_activity_request(punit, ACTIVITY_IDLE);
 	  }
diff --git a/server/unithand.c b/server/unithand.c
index 32ba567..f46fcf6 100644
--- a/server/unithand.c
+++ b/server/unithand.c
@@ -1180,7 +1180,7 @@ bool handle_unit_move_request(struct unit *punit, struct tile *pdesttile,
   if (can_unit_move_to_tile_with_notify(punit, pdesttile, igzoc)) {
     int move_cost = map_move_cost_unit(punit, pdesttile);
 
-    (void) move_unit(punit, pdesttile, move_cost);
+    move_unit(punit, pdesttile, move_cost);
 
     return TRUE;
   } else {
diff --git a/server/unittools.c b/server/unittools.c
index 48965eb..6f54a10 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -1095,7 +1095,8 @@ bool teleport_unit_to_city(struct unit *punit, struct city *pcity,
 
     if (move_cost == -1)
       move_cost = punit->moves_left;
-    return move_unit(punit, dst_tile, move_cost);
+    move_unit(punit, dst_tile, move_cost);
+    return TRUE;
   }
   return FALSE;
 }
@@ -2138,7 +2139,7 @@ bool do_airline(struct unit *punit, struct city *city2)
 		   _("%s transported succesfully."),
 		   unit_name_translation(punit));
 
-  (void) move_unit(punit, city2->tile, punit->moves_left);
+  move_unit(punit, city2->tile, punit->moves_left);
 
   /* airlift fields have changed. */
   send_city_info(city_owner(city1), city1);
@@ -2237,7 +2238,8 @@ bool do_paradrop(struct unit *punit, struct tile *ptile)
   {
     int move_cost = unit_type(punit)->paratroopers_mr_sub;
     punit->paradropped = TRUE;
-    return move_unit(punit, ptile, move_cost);
+    move_unit(punit, ptile, move_cost);
+    return TRUE;
   }
 }
 
@@ -2273,18 +2275,16 @@ static bool hut_get_limited(struct unit *punit)
 }
 
 /**************************************************************************
-  Return FALSE if unit is known killed, TRUE means no information.
-  This is due to the effects in the script signal callback can not
-  be predicted.
+  Due to the effects in the scripted hut behavior can not be predicted,
+  unit_enter_hut returns nothing.
 **************************************************************************/
-static bool unit_enter_hut(struct unit *punit)
+static void unit_enter_hut(struct unit *punit)
 {
   struct player *pplayer = unit_owner(punit);
-  bool ok = TRUE;
   enum hut_behavior behavior = unit_class(punit)->hut_behavior;
   
   if (behavior == HUT_NOTHING) {
-    return ok;
+    return;
   }
 
   tile_clear_special(punit->tile, S_HUT);
@@ -2294,18 +2294,19 @@ static bool unit_enter_hut(struct unit *punit)
     notify_player(pplayer, punit->tile, E_HUT_BARB,
 		     _("Your overflight frightens the tribe;"
 		       " they scatter in terror."));
-    return ok;
+    return;
   }
   
   /* AI with H_LIMITEDHUTS only gets 25 gold (or barbs if unlucky) */
   if (pplayer->ai.control && ai_handicap(pplayer, H_LIMITEDHUTS)) {
-    return hut_get_limited(punit);
+    (void) hut_get_limited(punit);
+    return;
   }
 
   script_signal_emit("hut_enter", 1, API_TYPE_UNIT, punit);
 
   send_player_info(pplayer, pplayer);       /* eg, gold */
-  return ok;
+  return;
 }
 
 /****************************************************************************
@@ -2654,7 +2655,7 @@ static void check_unit_activity(struct unit *punit)
   if you have set transport_units. Note that the src and dest need not be 
   adjacent.
 **************************************************************************/
-bool move_unit(struct unit *punit, struct tile *pdesttile, int move_cost)
+void move_unit(struct unit *punit, struct tile *pdesttile, int move_cost)
 {
   struct player *pplayer = unit_owner(punit);
   struct tile *psrctile = punit->tile;
@@ -2824,7 +2825,7 @@ bool move_unit(struct unit *punit, struct tile *pdesttile, int move_cost)
 		     API_TYPE_TILE, pdesttile);
   wakeup_neighbor_sentries(punit);
   if (!unit_survive_autoattack(punit)) {
-    return FALSE;
+    return;
   }
   maybe_make_contact(pdesttile, unit_owner(punit));
 
@@ -2856,9 +2857,7 @@ bool move_unit(struct unit *punit, struct tile *pdesttile, int move_cost)
    * right order.  This is probably not a bug. */
 
   if (tile_has_special(pdesttile, S_HUT)) {
-    return unit_enter_hut(punit);
-  } else {
-    return TRUE;
+    unit_enter_hut(punit);
   }
 }
 
diff --git a/server/unittools.h b/server/unittools.h
index 579f657..24778f0 100644
--- a/server/unittools.h
+++ b/server/unittools.h
@@ -85,7 +85,7 @@ bool do_airline(struct unit *punit, struct city *city2);
 bool do_paradrop(struct unit *punit, struct tile *ptile);
 void load_unit_onto_transporter(struct unit *punit, struct unit *ptrans);
 void unload_unit_from_transporter(struct unit *punit);
-bool move_unit(struct unit *punit, struct tile *ptile, int move_cost);
+void move_unit(struct unit *punit, struct tile *ptile, int move_cost);
 bool execute_orders(struct unit *punit);
 
 #endif  /* FC__UNITTOOLS_H */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to