Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2004:
[Freeciv-Dev] Re: (PR#9664) Dangerous danger
Home

[Freeciv-Dev] Re: (PR#9664) Dangerous danger

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: chrisk@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#9664) Dangerous danger
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Wed, 11 Aug 2004 13:53:15 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9664 >

On Wed, 11 Aug 2004, Christian Knoke wrote:
> And this one even crashes:
>
> 1: Dangerous danger[0] (-46488) in Newcastle.Beware of overflow.
> Gleitkomma-Ausnahme (core dumped)

Yes, the error is obvious. You have assembled too many units in the same
location, and this concentration of virtual matter causes a collapse in
the game logic, producing a logical singularity.

The solution is the attached witch-brew, which should make the code more
singularity-proof.

Warning: The patch is a half-brained 'cure the symptom, ignore the real
problem' kludge. This bug should be fixed, it is quite annoying, but I
really really don't want to work on this part of the code right now
because that is a real big job to do properly and I don't have the time.

  - Per

Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.117
diff -u -r1.117 aitools.c
--- ai/aitools.c        6 Aug 2004 02:13:34 -0000       1.117
+++ ai/aitools.c        11 Aug 2004 20:51:53 -0000
@@ -146,7 +146,7 @@
 {
   struct player *pplayer = unit_owner(punit);
   struct ai_data *ai = ai_data_get(pplayer);
-  int danger = 0;
+  unsigned int danger = 0;
   struct city *dcity;
   struct tile *ptile;
   
@@ -722,7 +722,8 @@
 void ai_advisor_choose_building(struct city *pcity, struct ai_choice *choice)
 { /* I prefer the ai_choice as a return value; gcc prefers it as an arg -- 
Syela */
   Impr_Type_id id = B_LAST;
-  int danger = 0, downtown = 0, cities = 0;
+  unsigned int danger = 0;
+  int downtown = 0, cities = 0;
   int want=0;
   struct player *plr;
         
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.169
diff -u -r1.169 advmilitary.c
--- ai/advmilitary.c    25 Jun 2004 23:43:00 -0000      1.169
+++ ai/advmilitary.c    11 Aug 2004 20:51:53 -0000
@@ -41,7 +41,7 @@
 
 #include "advmilitary.h"
 
-static int assess_danger(struct city *pcity);
+static unsigned int assess_danger(struct city *pcity);
 
 /********************************************************************** 
 This function should assign a value to choice and want, where want is a value
@@ -244,13 +244,13 @@
 /************************************************************************** 
   Compute actual danger depending on move rate of enemy and its distance.
 **************************************************************************/
-static int dangerfunct(int danger, int move_rate, int distance)
+static unsigned int dangerfunct(int danger, int move_rate, int distance)
 {
   /* XXX: I don't have a clue about these, it probably has something in common
    * with the way how attack force is computed when attacker already spent some
    * move points..? --pasky */
-  int num = move_rate * 4;
-  int denom = move_rate * 4;
+  unsigned int num = move_rate * 4;
+  unsigned int denom = move_rate * 4;
 
   if (move_rate == 0) {
     return danger;
@@ -286,9 +286,9 @@
 /************************************************************************** 
 How dangerous a unit is for a city?
 **************************************************************************/
-static int assess_danger_unit(struct city *pcity, struct unit *punit)
+static unsigned int assess_danger_unit(struct city *pcity, struct unit *punit)
 {
-  int danger;
+  unsigned int danger;
   bool sailing;
 
   if (unit_flag(punit, F_NO_LAND_ATTACK)) return 0;
@@ -373,7 +373,7 @@
   Syela's convoluted if ... else logic, and it seems to work. -- Per
 ***********************************************************************/
 static void ai_reevaluate_building(struct city *pcity, int *value, 
-                                   int urgency, int danger, 
+                                   unsigned int urgency, unsigned int danger, 
                                    int defense)
 {
   if (*value == 0 || danger <= 0) {
@@ -410,13 +410,13 @@
   afraid of a boat laden with enemies if it stands on the coast (i.e.
   is directly reachable by this boat).
 ***********************************************************************/
-static int assess_danger(struct city *pcity)
+static unsigned int assess_danger(struct city *pcity)
 {
   int i;
-  int danger[5];
+  unsigned int danger[5];
   struct player *pplayer = city_owner(pcity);
   bool pikemen = FALSE;
-  int urgency = 0;
+  unsigned int urgency = 0;
   int igwall_threat = 0;
   struct tile *ptile = map_get_tile(pcity->x, pcity->y);
 
@@ -442,7 +442,7 @@
     unit_list_iterate(aplayer->units, punit) {
       int paramove = 0;
       int move_rate = unit_move_rate(punit);
-      int vulnerability = assess_danger_unit(pcity, punit);
+      unsigned int vulnerability = assess_danger_unit(pcity, punit);
       int dist = assess_distance(pcity, punit, move_rate);
       bool igwall = unit_really_ignores_citywalls(punit);
 
@@ -611,7 +611,7 @@
   build yet.
 **************************************************************************/
 static void process_defender_want(struct player *pplayer, struct city *pcity,
-                                  int danger, struct ai_choice *choice)
+                                  unsigned int danger, struct ai_choice 
*choice)
 {
   bool walls = city_got_citywalls(pcity);
   bool shore = is_ocean_near_tile(pcity->x, pcity->y);
@@ -1179,7 +1179,7 @@
                                   struct ai_choice *choice)
 {
   Unit_Type_id unit_type;
-  int our_def, danger, urgency;
+  unsigned int our_def, danger, urgency;
   struct tile *ptile = map_get_tile(pcity->x, pcity->y);
   struct unit *virtualunit;
 
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.156
diff -u -r1.156 city.h
--- common/city.h       5 Aug 2004 11:34:18 -0000       1.156
+++ common/city.h       11 Aug 2004 20:51:53 -0000
@@ -176,12 +176,12 @@
   /* building desirabilities - easiest to handle them here -- Syela */
   int building_want[B_LAST];    /* not sure these will always be < 256 */
 
-  int danger;                   /* danger to be compared to assess_defense */
+  unsigned int danger;          /* danger to be compared to assess_defense */
   bool diplomat_threat;         /* enemy diplomat or spy is near the city */
   bool has_diplomat;            /* this city has diplomat or spy defender */
-  int urgency;                  /* how close the danger is; if zero, 
+  unsigned int urgency;         /* how close the danger is; if zero, 
                                    bodyguards can leave */
-  int grave_danger;             /* danger, should show positive feedback */
+  unsigned int grave_danger;    /* danger, should show positive feedback */
   int wallvalue;                /* how much it helps for defenders to be 
                                    ground units */
   int trade_want;               /* saves a zillion calculations */

[Prev in Thread] Current Thread [Next in Thread]