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

 This patch turns ai handicaps into bitvector so new bits can be added
in the future.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/player.c freeciv/common/player.c
--- freeciv/common/player.c     2008-04-17 10:49:41.000000000 +0300
+++ freeciv/common/player.c     2008-07-23 01:46:54.000000000 +0300
@@ -209,7 +209,7 @@
     plr->diplstates[i].contact_turns_left = 0;
   }
   plr->ai.control=FALSE;
-  plr->ai.handicap = 0;
+  BV_CLR_ALL(plr->ai.handicaps);
   plr->ai.skill_level = 0;
   plr->ai.fuzzy = 0;
   plr->ai.expand = 100;
@@ -721,7 +721,7 @@
   if (!pplayer->ai.control) {
     return TRUE;
   }
-  return BOOL_VAL(pplayer->ai.handicap & htype);
+  return BV_ISSET(pplayer->ai.handicaps, htype);
 }
 
 /**************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/player.h freeciv/common/player.h
--- freeciv/common/player.h     2008-06-24 01:37:50.000000000 +0300
+++ freeciv/common/player.h     2008-07-23 02:03:03.000000000 +0300
@@ -32,26 +32,28 @@
 #define ANON_USER_NAME "Unassigned"
 
 enum handicap_type {
-  H_NONE = 0,         /* No handicaps */
-  H_DIPLOMAT = 1,     /* Can't build offensive diplomats */
-  H_AWAY = 2,         /* Away mode */
-  H_LIMITEDHUTS = 4,  /* Can get only 25 gold and barbs from huts */
-  H_DEFENSIVE = 8,    /* Build defensive buildings without calculating need */
-  H_EXPERIMENTAL = 16,/* Enable experimental AI features (for testing) */
-  H_RATES = 32,       /* Can't set its rates beyond government limits */
-  H_TARGETS = 64,     /* Can't target anything it doesn't know exists */
-  H_HUTS = 128,       /* Doesn't know which unseen tiles have huts on them */
-  H_FOG = 256,        /* Can't see through fog of war */
-  H_NOPLANES = 512,   /* Doesn't build air units */
-  H_MAP = 1024,       /* Only knows map_is_known tiles */
-  H_DIPLOMACY = 2048, /* Not very good at diplomacy */
-  H_REVOLUTION = 4096, /* Cannot skip anarchy */
-  H_EXPANSION = 8192, /* Don't like being much larger than human */
-  H_DANGER = 16384    /* Always thinks its city is in danger */
+  H_DIPLOMAT = 0,     /* Can't build offensive diplomats */
+  H_AWAY,             /* Away mode */
+  H_LIMITEDHUTS,      /* Can get only 25 gold and barbs from huts */
+  H_DEFENSIVE,        /* Build defensive buildings without calculating need */
+  H_EXPERIMENTAL,     /* Enable experimental AI features (for testing) */
+  H_RATES,            /* Can't set its rates beyond government limits */
+  H_TARGETS,          /* Can't target anything it doesn't know exists */
+  H_HUTS,             /* Doesn't know which unseen tiles have huts on them */
+  H_FOG,              /* Can't see through fog of war */
+  H_NOPLANES,         /* Doesn't build air units */
+  H_MAP,              /* Only knows map_is_known tiles */
+  H_DIPLOMACY,        /* Not very good at diplomacy */
+  H_REVOLUTION,       /* Cannot skip anarchy */
+  H_EXPANSION,        /* Don't like being much larger than human */
+  H_DANGER,           /* Always thinks its city is in danger */
+  H_LAST
 };
 
 BV_DEFINE(bv_player, MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS);
 
+BV_DEFINE(bv_handicap, H_LAST);
+
 struct player_economic {
   int gold;
   int tax;
@@ -94,7 +96,7 @@
   int est_upkeep; /* estimated upkeep of buildings in cities */
   /* The units of tech_want seem to be shields */
   int tech_want[A_LAST+1];
-  int handicap;                        /* sum of enum handicap_type */
+  bv_handicap handicaps;        /* sum of enum handicap_type */
   enum ai_level skill_level;           /* 0-10 value for save/load/display */
   int fuzzy;                   /* chance in 1000 to mis-decide */
   int expand;                  /* percentage factor to value new cities */
diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c    2008-07-03 21:58:06.000000000 +0300
+++ freeciv/server/plrhand.c    2008-07-23 01:55:46.000000000 +0300
@@ -1549,7 +1549,7 @@
   cplayer->ai.control = TRUE;
   cplayer->ai.prev_gold = pplayer->ai.prev_gold;
   cplayer->ai.maxbuycost = pplayer->ai.maxbuycost;
-  cplayer->ai.handicap = pplayer->ai.handicap;
+  cplayer->ai.handicaps = pplayer->ai.handicaps;
   cplayer->ai.warmth = pplayer->ai.warmth;
   cplayer->ai.frost = pplayer->ai.frost;
   set_ai_level_direct(cplayer, game.info.skill_level);
diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c
--- freeciv/server/savegame.c   2008-07-18 22:08:35.000000000 +0300
+++ freeciv/server/savegame.c   2008-07-23 01:56:37.000000000 +0300
@@ -1963,10 +1963,10 @@
     research->tech_goal = A_UNSET;
   }
   /* Some sane defaults */
-  plr->ai.handicap = 0;                /* set later */
-  plr->ai.fuzzy = 0;           /* set later */
-  plr->ai.expand = 100;                /* set later */
-  plr->ai.science_cost = 100;  /* set later */
+  BV_CLR_ALL(plr->ai.handicaps); /* set later */
+  plr->ai.fuzzy = 0;            /* set later */
+  plr->ai.expand = 100;                 /* set later */
+  plr->ai.science_cost = 100;   /* set later */
   plr->ai.skill_level =
     secfile_lookup_int_default(file, game.info.skill_level,
                               "player%d.ai.skill_level", plrno);
diff -Nurd -X.diff_ignore freeciv/server/stdinhand.c freeciv/server/stdinhand.c
--- freeciv/server/stdinhand.c  2008-07-21 12:41:51.000000000 +0300
+++ freeciv/server/stdinhand.c  2008-07-23 02:13:20.000000000 +0300
@@ -661,31 +661,62 @@
 }
 
 /***************************************************************
-...
+ Returns handicap bitvector for given AI skill level
 ***************************************************************/
-static int handicap_of_skill_level(int level)
+static bv_handicap handicap_of_skill_level(int level)
 {
-  int h[11] = { -1,
- /* away   */  H_AWAY  | H_RATES | H_TARGETS | H_HUTS | H_FOG | H_MAP
-                        | H_REVOLUTION,
- /* novice */   H_RATES | H_TARGETS | H_HUTS | H_NOPLANES 
-                        | H_DIPLOMAT | H_LIMITEDHUTS | H_DEFENSIVE
-                       | H_DIPLOMACY | H_REVOLUTION | H_EXPANSION
-                        | H_DANGER,
- /* easy */    H_RATES | H_TARGETS | H_HUTS | H_NOPLANES 
-                        | H_DIPLOMAT | H_LIMITEDHUTS | H_DEFENSIVE
-                        | H_REVOLUTION | H_EXPANSION,
-               H_NONE,
- /* medium */  H_RATES | H_TARGETS | H_HUTS | H_DIPLOMAT,
-               H_NONE,
- /* hard */    H_NONE,
- /* cheating */ H_NONE,
-               H_NONE,
- /* testing */ H_EXPERIMENTAL,
-               };
-  
+  bv_handicap handicap;
+
   assert(level>0 && level<=10);
-  return h[level];
+
+  BV_CLR_ALL(handicap);
+
+  switch (level) {
+   case AI_LEVEL_AWAY:
+     BV_SET(handicap, H_AWAY);
+     BV_SET(handicap, H_FOG);
+     BV_SET(handicap, H_MAP);
+     BV_SET(handicap, H_RATES);
+     BV_SET(handicap, H_TARGETS);
+     BV_SET(handicap, H_HUTS);
+     BV_SET(handicap, H_REVOLUTION);
+     break;
+   case AI_LEVEL_NOVICE:
+     BV_SET(handicap, H_RATES);
+     BV_SET(handicap, H_TARGETS);
+     BV_SET(handicap, H_HUTS);
+     BV_SET(handicap, H_NOPLANES);
+     BV_SET(handicap, H_DIPLOMAT);
+     BV_SET(handicap, H_LIMITEDHUTS);
+     BV_SET(handicap, H_DEFENSIVE);
+     BV_SET(handicap, H_REVOLUTION);
+     BV_SET(handicap, H_EXPANSION);
+     BV_SET(handicap, H_DANGER);
+     break;
+   case AI_LEVEL_EASY:
+     BV_SET(handicap, H_RATES);
+     BV_SET(handicap, H_TARGETS);
+     BV_SET(handicap, H_HUTS);
+     BV_SET(handicap, H_NOPLANES);
+     BV_SET(handicap, H_DIPLOMAT);
+     BV_SET(handicap, H_LIMITEDHUTS);
+     BV_SET(handicap, H_DEFENSIVE);
+     BV_SET(handicap, H_DIPLOMACY);
+     BV_SET(handicap, H_REVOLUTION);
+     BV_SET(handicap, H_EXPANSION);
+     break;
+   case AI_LEVEL_NORMAL:
+     BV_SET(handicap, H_RATES);
+     BV_SET(handicap, H_TARGETS);
+     BV_SET(handicap, H_HUTS);
+     BV_SET(handicap, H_DIPLOMAT);
+     break;
+   case AI_LEVEL_EXPERIMENTAL:
+     BV_SET(handicap, H_EXPERIMENTAL);
+     break;
+  }
+
+  return handicap;
 }
 
 /**************************************************************************
@@ -1724,7 +1755,7 @@
 ******************************************************************/
 void set_ai_level_directer(struct player *pplayer, enum ai_level level)
 {
-  pplayer->ai.handicap = handicap_of_skill_level(level);
+  pplayer->ai.handicaps = handicap_of_skill_level(level);
   pplayer->ai.fuzzy = fuzzy_of_skill_level(level);
   pplayer->ai.expand = expansionism_of_skill_level(level);
   pplayer->ai.science_cost = science_cost_of_skill_level(level);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to