home *** CD-ROM | disk | FTP | other *** search
/ Amiga Times / AmigaTimes.iso / spiele / FreeCiv / src / freeciv-1.7.0 / server / citytools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-06  |  20.6 KB  |  668 lines

  1. /**********************************************************************
  2.  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2, or (at your option)
  6.    any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12. ***********************************************************************/
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include <player.h>
  17. #include <unithand.h>
  18. #include <civserver.h>
  19. #include <map.h>
  20. #include <maphand.h>
  21. #include <mapgen.h>
  22. #include <cityhand.h>
  23. #include <cityturn.h>
  24. #include <citytools.h>
  25. #include <unit.h>
  26. #include <city.h>
  27. #include <player.h>
  28. #include <tech.h>
  29. #include <shared.h>
  30. #include <plrhand.h>
  31. #include <events.h>
  32. #include <unitfunc.h>
  33. #include <settlers.h>
  34.  
  35. /****************************************************************
  36. ...
  37. *****************************************************************/
  38.  
  39. int city_got_barracks(struct city *pcity)
  40. {
  41.   return (city_affected_by_wonder(pcity, B_SUNTZU) ||
  42.       city_got_building(pcity, B_BARRACKS) || 
  43.       city_got_building(pcity, B_BARRACKS2) ||
  44.       city_got_building(pcity, B_BARRACKS3));
  45. }
  46.  
  47. /**************************************************************************
  48. ...
  49. **************************************************************************/
  50.  
  51. int can_sell_building(struct city *pcity, int id)
  52. {
  53.  
  54.   return (city_got_building(pcity, id) ? (!is_wonder(id)) : 0);
  55. }
  56.  
  57. /**************************************************************************
  58. ...
  59. **************************************************************************/
  60.  
  61. enum city_tile_type get_worker_city(struct city *pcity, int x, int y)
  62. {
  63.   if ((x==0 || x==4) && (y == 0 || y == 4)) 
  64.     return C_TILE_UNAVAILABLE;
  65.   return(pcity->city_map[x][y]);
  66. }
  67.  
  68. /**************************************************************************
  69. ...
  70. **************************************************************************/
  71. int is_worker_here(struct city *pcity, int x, int y) 
  72. {
  73.   if (x < 0 || x > 4 || y < 0 || y > 4 || ((x == 0 || x == 4) && (y == 0|| y==4))) {
  74.     return 0;
  75.   }
  76.   return (get_worker_city(pcity,x,y)==C_TILE_WORKER); 
  77. }
  78.  
  79. /**************************************************************************
  80. ...
  81. **************************************************************************/
  82.  
  83. struct city *find_city_wonder(enum improvement_type_id id)
  84. {
  85.   return (find_city_by_id(game.global_wonders[id]));
  86. }
  87.  
  88. /**************************************************************************
  89. Locate the city where the players palace is located, (NULL Otherwise) 
  90. **************************************************************************/
  91.  
  92. struct city *find_palace(struct player *pplayer)
  93. {
  94.   city_list_iterate(pplayer->cities, pcity) 
  95.     if (city_got_building(pcity, B_PALACE)) 
  96.       return pcity;
  97.   city_list_iterate_end;
  98.   return NULL;
  99. }
  100.  
  101.  
  102. /**************************************************************************
  103. ...
  104. **************************************************************************/
  105.  
  106. int city_specialists(struct city *pcity)
  107. {
  108.   return (pcity->ppl_elvis+pcity->ppl_scientist+pcity->ppl_taxman);
  109. }
  110.  
  111. /**************************************************************************
  112. ... v 1.0j code was too rash, only first penalty now!
  113. **************************************************************************/
  114. int content_citizens(struct player *pplayer) 
  115. {
  116.   int cities =  city_list_size(&pplayer->cities);
  117.   int content = game.unhappysize;
  118.   int basis   = game.cityfactor - (G_DEMOCRACY - pplayer->government);
  119.  
  120.   if (cities > basis) 
  121.     content--;
  122.   return content;
  123. }
  124.  
  125. /**************************************************************************
  126. ...
  127. **************************************************************************/
  128.  
  129. int get_temple_power(struct city *pcity)
  130. {
  131.   struct player *p=&game.players[pcity->owner];
  132.   int power=1;
  133.   if (get_invention(p, A_MYSTICISM)==TECH_KNOWN)
  134.     power=2;
  135.   if (city_affected_by_wonder(pcity, B_ORACLE)) 
  136.     power*=2;
  137.   return power;
  138. }
  139.  
  140. /**************************************************************************
  141. ...
  142. **************************************************************************/
  143.  
  144. int get_cathedral_power(struct city *pcity)
  145. {
  146.   struct player *p=&game.players[pcity->owner];
  147.   int power = 3;
  148.   if (get_invention(p, A_COMMUNISM) == TECH_KNOWN)
  149.    power--;
  150.   if (get_invention(p, A_THEOLOGY) == TECH_KNOWN)
  151.    power++;
  152.   return power;
  153. }
  154.  
  155. /**************************************************************************
  156. ...
  157. **************************************************************************/
  158. int get_colosseum_power(struct city *pcity)
  159. {
  160.   int power = 3;
  161.   struct player *p=&game.players[pcity->owner];
  162.   if (get_invention(p, A_ELECTRICITY) == TECH_KNOWN)
  163.    power++;
  164.   return power;
  165. }
  166.  
  167. /**************************************************************************
  168. ...
  169. **************************************************************************/
  170. int is_worked_here(int x, int y)
  171. {
  172.   return (map_get_tile(x, y)->worked >= 0); /* saves at least 10% of runtime CPU usage! */
  173. }
  174.  
  175. int old_is_worked_here(int x, int y)
  176. {
  177.   struct player *pplayer;
  178.   int my, i;
  179.   int xx;
  180.  
  181.   x = map_adjust_x(x);
  182.   for(i=0; i<game.nplayers; i++) {
  183.     pplayer=&game.players[i];
  184.     city_list_iterate(pplayer->cities, pcity) {
  185.  
  186.       my=y+2-pcity->y;
  187.       if (0 <= my && my <5)
  188.     for ( xx = 0; xx<5; xx++) 
  189.       if (map_adjust_x(pcity->x+xx-2) == x) 
  190.         if(get_worker_city(pcity, xx, my)==C_TILE_WORKER) return 1;
  191.     }
  192.     city_list_iterate_end;
  193.   }
  194.   return 0;
  195. }
  196.  
  197. /**************************************************************************
  198. x and y are city cords in the range [0;4]
  199. **************************************************************************/
  200. int can_place_worker_here(struct city *pcity, int x, int y)
  201. {
  202.   if ((x == 0 || x == 4) && (y == 0 || y == 4))
  203.     return 0;
  204.   if (x < 0  || x > 4 || y < 0 || y > 4)
  205.     return 0;
  206.   if (get_worker_city(pcity, x, y) != C_TILE_EMPTY)
  207.     return 0;
  208.   return  (map_get_known(pcity->x+x-2, pcity->y+y-2, city_owner(pcity))
  209.     && !is_worked_here(map_adjust_x(pcity->x+x-2), pcity->y+y-2));
  210. }
  211.  
  212. int food_weighting(int n)
  213. {
  214.   static int value[56] = { -1, 57, 38, 25, 19, 15, 12, 10, 9, 8, 7,
  215.                          6, 6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3,
  216.                          2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  217.                          2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
  218.   return(value[n]);
  219. }
  220.  
  221. int city_tile_value(struct city *pcity, int x, int y, int foodneed, int prodneed)
  222. { /* by Syela, unifies best_tile, best_food_tile, worst_elvis_tile */
  223.   int i, j, k;
  224.   struct player *plr;
  225.  
  226.   plr = city_owner(pcity);
  227.  
  228.   i = get_food_tile(x, y, pcity);
  229.   if (foodneed > 0) i += 9 * (MIN(i, foodneed));
  230. /* *= 10 led to stupidity with foodneed = 1, mine, and farmland -- Syela */
  231.   i *= food_weighting(MAX(2,pcity->size));
  232.   
  233.   j = get_shields_tile(x, y, pcity);
  234.   if (prodneed > 0) j += 9 * (MIN(j, prodneed));
  235.   j *= SHIELD_WEIGHTING * city_shield_bonus(pcity);
  236.   j /= 100;
  237.   k = get_trade_tile(x, y, pcity) * pcity->ai.trade_want *
  238.       (city_tax_bonus(pcity) * (plr->economic.tax + plr->economic.luxury) +
  239.        city_science_bonus(pcity) * plr->economic.science) / 10000;
  240.   return(i + j + k);
  241. }  
  242.  
  243. int worst_worker_tile_value(struct city *pcity)
  244. {
  245.   int x, y;
  246.   int worst = 0, tmp;
  247.   city_map_iterate(x, y) {
  248.     if ((x !=2 || y != 2) && get_worker_city(pcity, x, y) == C_TILE_WORKER) {
  249.       tmp = city_tile_value(pcity, x, y, 0, 0);
  250.       if (tmp < worst || !worst) worst = tmp;
  251.     }
  252.   }
  253.   return(worst);
  254. }
  255.  
  256. int better_tile(struct city *pcity, int x, int y, int bx, int by, int foodneed, int prodneed)
  257. {
  258.   return (city_tile_value(pcity, x, y, foodneed, prodneed) >
  259.           city_tile_value(pcity, bx, by, foodneed, prodneed));
  260. }
  261. /**************************************************************************
  262. ...
  263. **************************************************************************/
  264. int best_tile(struct city *pcity, int x, int y, int bx, int by)
  265. { /* obsoleted but not deleted by Syela */
  266.   return (4*get_food_tile(x, y, pcity) +
  267.           12*get_shields_tile(x, y, pcity) +
  268.           8*get_trade_tile(x, y, pcity) >
  269.           4*get_food_tile(bx, by, pcity) +
  270.           12*get_shields_tile(bx, by, pcity) +
  271.           8*get_trade_tile(bx, by, pcity) 
  272.           );
  273. }
  274.  
  275. /**************************************************************************
  276. ...
  277. **************************************************************************/
  278. int best_food_tile(struct city *pcity, int x, int y, int bx, int by)
  279. { /* obsoleted but not deleted by Syela */
  280.   return (100*get_food_tile(x, y, pcity) +
  281.           12*get_shields_tile(x, y, pcity) +
  282.           8*get_trade_tile(x, y, pcity) >
  283.           100*get_food_tile(bx, by, pcity) +
  284.           12*get_shields_tile(bx, by, pcity) +
  285.           8*get_trade_tile(bx, by, pcity) 
  286.           );
  287. }
  288.  
  289. /**************************************************************************
  290. ...
  291. **************************************************************************/
  292. int settler_eats(struct city *pcity)
  293. {
  294.   int eat=0;
  295.   unit_list_iterate(pcity->units_supported, this_unit) {
  296.     if (unit_flag(this_unit->type, F_SETTLERS)) {
  297.       eat++;
  298.       if (get_government(pcity->owner)>=G_COMMUNISM) {
  299.         eat++;
  300.       }
  301.     }
  302.   }
  303.   unit_list_iterate_end;
  304.   return eat;
  305. }
  306.  
  307. /**************************************************************************
  308. ...
  309. **************************************************************************/
  310. int is_building_other_wonder(struct city *pc)
  311. {
  312.   struct player *pplayer = city_owner(pc);
  313.   city_list_iterate(pplayer->cities, pcity) 
  314.     if ((pc != pcity) && !(pcity->is_building_unit) && is_wonder(pcity->currently_building) && map_get_continent(pcity->x, pcity->y) == map_get_continent(pc->x, pc->y))
  315.       return pcity->currently_building; /* why return 1? -- Syela */
  316.   city_list_iterate_end;
  317.   return 0;
  318. }
  319.  
  320. /**************************************************************************
  321. ...
  322. **************************************************************************/
  323. int built_elsewhere(struct city *pc, int wonder)
  324. {
  325.   struct player *pplayer = city_owner(pc);
  326.   city_list_iterate(pplayer->cities, pcity) 
  327.     if ((pc != pcity) && !(pcity->is_building_unit) && pcity->currently_building == wonder)
  328.       return 1;
  329.   city_list_iterate_end;
  330.   return 0;
  331. }
  332.  
  333.  
  334. /**************************************************************************
  335. ...
  336. **************************************************************************/
  337. void eval_buildings(struct city *pcity,int *values)
  338. {
  339.   int i, gov, tech;
  340.   struct player *plr = city_owner(pcity);
  341.   gov = get_government(pcity->owner);
  342.   tech = (plr->research.researching != A_NONE);
  343.     
  344.   for (i=0;i<B_LAST;i++) {
  345.     if (is_wonder(i) && can_build_improvement(pcity, i) && !built_elsewhere(pcity, i)) {
  346.       if (wonder_obsolete(i))
  347.     values[i]=1;
  348.       else
  349.     values[i]=99;
  350.     } else
  351.     values[i]=0;
  352.   }
  353.   
  354.   if (gov <= G_COMMUNISM || pcity->size < 5) {
  355.     if (can_build_improvement(pcity, B_GRANARY)) 
  356.       values[B_GRANARY]=pcity->food_surplus*50;
  357.   }
  358.   if (can_build_improvement(pcity, B_SUPERMARKET))
  359.     values[B_SUPERMARKET]=pcity->size*55;
  360.  
  361.   if (can_build_improvement(pcity, B_AQUEDUCT) && pcity->size > 6)
  362.     values[B_AQUEDUCT]=pcity->size*125+pcity->food_surplus*50;
  363.   if (can_build_improvement(pcity, B_SEWER) && pcity->size > 11)
  364.     values[B_SEWER]=pcity->size*100+pcity->food_surplus*50;
  365.   
  366.   if (can_build_improvement(pcity, B_HARBOUR) && (pcity->size > 5)) 
  367.     values[B_HARBOUR]=pcity->size*60;
  368.   if (can_build_improvement(pcity, B_OFFSHORE) && 
  369.       !can_build_improvement(pcity, B_HARBOUR))
  370.     values[B_OFFSHORE]=pcity->size*60;
  371.   
  372.   if (can_build_improvement(pcity, B_MARKETPLACE)) 
  373.     values[B_MARKETPLACE]=pcity->trade_prod*200;
  374.   
  375.   if (pcity->trade_prod > 15) 
  376.     if (can_build_improvement(pcity, B_BANK)) 
  377.       values[B_BANK]=pcity->tax_total*100;
  378.  
  379.     if (can_build_improvement(pcity, B_STOCK)) 
  380.       values[B_STOCK]=pcity->tax_total*100;
  381.   
  382.   if (gov > G_COMMUNISM)
  383.     if (can_build_improvement(pcity, B_SUPERHIGHWAYS)) 
  384.       values[B_SUPERHIGHWAYS]=pcity->trade_prod*60;
  385.   if (can_build_improvement(pcity, B_COURTHOUSE)) {
  386.     if (gov != G_DEMOCRACY) 
  387.       values[B_COURTHOUSE]=pcity->corruption*100;
  388.     else 
  389.       values[B_COURTHOUSE]=pcity->ppl_unhappy[4]*200+pcity->ppl_elvis*400;
  390.   }
  391.   if (tech) {
  392.     if (can_build_improvement(pcity, B_LIBRARY)) 
  393.       values[B_LIBRARY]=pcity->science_total*200;
  394.     
  395.     if (can_build_improvement(pcity, B_UNIVERSITY)) 
  396.       values[B_UNIVERSITY]=pcity->science_total*101;
  397.     
  398.     if (can_build_improvement(pcity, B_RESEARCH)) 
  399.       values[B_RESEARCH]=pcity->science_total*100;
  400.   }
  401.   if (can_build_improvement(pcity, B_AIRPORT))
  402.     values[B_AIRPORT]=pcity->shield_prod*49;
  403.  
  404.   if (pcity->shield_prod >= 15)
  405.     if (can_build_improvement(pcity, B_PORT))
  406.       values[B_PORT]=pcity->shield_prod*48;
  407.  
  408.   if (pcity->shield_prod >= 5) {
  409.     if (can_build_improvement(pcity, B_BARRACKS))
  410.       values[B_BARRACKS]=pcity->shield_prod*50;
  411.  
  412.     if (can_build_improvement(pcity, B_BARRACKS2))
  413.       values[B_BARRACKS2]=pcity->shield_prod*50;
  414.  
  415.     if (can_build_improvement(pcity, B_BARRACKS3))
  416.       values[B_BARRACKS3]=pcity->shield_prod*50;
  417.   }
  418.   if (can_build_improvement(pcity, B_TEMPLE))
  419.      values[B_TEMPLE]=pcity->ppl_unhappy[4]*200+pcity->ppl_elvis*600;
  420.  
  421.   if (can_build_improvement(pcity, B_COLOSSEUM))
  422.     values[B_COLOSSEUM]=pcity->ppl_unhappy[4]*200+pcity->ppl_elvis*300;
  423.  
  424.   if (can_build_improvement(pcity, B_CATHEDRAL))
  425.     values[B_CATHEDRAL]=pcity->ppl_unhappy[4]*201+pcity->ppl_elvis*300;
  426.  
  427.   if (!(tech && plr->economic.tax > 50)) {
  428.     if (can_build_improvement(pcity, B_COASTAL))
  429.       values[B_COASTAL]=pcity->size*36;
  430.     if (can_build_improvement(pcity, B_CITY))
  431.       values[B_CITY]=pcity->size*35;
  432.   } 
  433.   if (!(tech && plr->economic.tax > 40)) {
  434.     if (can_build_improvement(pcity, B_SAM))
  435.       values[B_SAM]=pcity->size*24;
  436.     if (can_build_improvement(pcity, B_SDI))
  437.       values[B_SDI]=pcity->size*25;
  438.   }
  439.   if (pcity->shield_prod >= 10)
  440.     if (can_build_improvement(pcity, B_FACTORY)) 
  441.       values[B_FACTORY]=pcity->shield_prod*125;
  442.  
  443.   if (city_got_building(pcity, B_FACTORY)) {
  444.     
  445.     if (can_build_improvement(pcity, B_HYDRO))
  446.       values[B_HYDRO]=pcity->shield_prod*100+pcity->pollution*100;
  447.     
  448.     if (can_build_improvement(pcity, B_NUCLEAR))
  449.       values[B_NUCLEAR]=pcity->shield_prod*101+pcity->pollution*100;
  450.     
  451.     if (can_build_improvement(pcity, B_POWER))
  452.       values[B_POWER]=pcity->shield_prod*100;
  453.   }
  454.  
  455.   if (can_build_improvement(pcity, B_MFG)) 
  456.     values[B_MFG]=pcity->shield_prod*125;
  457.  
  458.   if (can_build_improvement(pcity, B_MASS)) 
  459.     values[B_MASS]=pcity->pollution*(100+pcity->size);
  460.  
  461.   if (can_build_improvement(pcity, B_RECYCLING)) 
  462.     values[B_RECYCLING]=pcity->pollution*(100+pcity->shield_prod);
  463.     
  464.   if (can_build_improvement(pcity, B_CAPITAL))
  465.     values[B_CAPITAL]=pcity->shield_prod;
  466. }
  467.  
  468. /**************************************************************************
  469. ...
  470. **************************************************************************/
  471. int do_make_unit_veteran(struct city *pcity, enum unit_type_id id)
  472. {
  473.   if (unit_flag(id,F_DIPLOMAT) && get_government(pcity->owner)==G_COMMUNISM)
  474.     return 1;
  475.   if (is_ground_unittype(id))
  476.     return city_got_barracks(pcity);
  477.   else if (is_water_unit(id))
  478.     return (city_affected_by_wonder(pcity, B_LIGHTHOUSE) || city_got_building(pcity, B_PORT));
  479.   else
  480.     return city_got_building(pcity, B_AIRPORT);
  481.   return 0;
  482. }
  483.  
  484. /**************************************************************************
  485. corruption, corruption is halfed during love the XXX days.
  486. **************************************************************************/
  487. int city_corruption(struct city *pcity, int trade)
  488. {
  489.   struct city *capital;
  490.   int dist;
  491.   int val;
  492.   int corruption[]= { 12,8,20,24,20,0}; /* original {12,8,16,20,24,0} */
  493.   if (get_government(pcity->owner)==G_DEMOCRACY) {
  494.     return(0);
  495.   }
  496.   if (get_government(pcity->owner)==G_COMMUNISM) {
  497.     dist=10;
  498.   } else {
  499.     capital=find_palace(city_owner(pcity));
  500.     if (!capital)
  501.       dist=36;
  502.     else
  503.       dist=min(36,map_distance(capital->x, capital->y, pcity->x, pcity->y));
  504.   }
  505.   if (get_government(pcity->owner) == G_DESPOTISM)
  506.     dist = dist*2 + 3; /* yes, DESPOTISM is even worse than ANARCHY */
  507.   
  508.   val=(trade*dist*3)/(corruption[get_government(pcity->owner)]*10);
  509.  
  510.   if (city_got_building(pcity, B_COURTHOUSE) ||   
  511.       city_got_building(pcity, B_PALACE))
  512.     val /= 2;
  513.   if (val >= trade && val)
  514.     val = trade - 1;
  515.   return(val); /* how did y'all let me forget this one? -- Syela */
  516. }
  517.   
  518.  
  519. int set_city_shield_bonus(struct city *pcity)
  520. {
  521.   int tmp = 0;
  522.   if (city_got_building(pcity, B_FACTORY)) {
  523.     if (city_got_building(pcity, B_MFG))
  524.       tmp = 100;
  525.     else
  526.       tmp = 50;
  527.   }
  528.  
  529.   if (city_affected_by_wonder(pcity, B_HOOVER) ||
  530.       city_got_building(pcity, B_POWER) ||
  531.       city_got_building(pcity, B_HYDRO) ||
  532.       city_got_building(pcity,B_NUCLEAR))
  533.     tmp *= 1.5;
  534.  
  535.   pcity->shield_bonus = tmp + 100;
  536.   return (tmp + 100);
  537. }
  538.  
  539. int city_shield_bonus(struct city *pcity)
  540. {
  541.   return pcity->shield_bonus;
  542. }
  543.  
  544. /**************************************************************************
  545. ...
  546. **************************************************************************/
  547. int set_city_tax_bonus(struct city *pcity)
  548. {
  549.   int tax_bonus = 100;
  550.   if (city_got_building(pcity, B_MARKETPLACE)) {
  551.     tax_bonus+=50;
  552.     if (city_got_building(pcity, B_BANK)) {
  553.       tax_bonus+=50;
  554.       if (city_got_building(pcity, B_STOCK)) 
  555.     tax_bonus+=50;
  556.     }
  557.   }
  558.   pcity->tax_bonus = tax_bonus;
  559.   return tax_bonus;
  560. }
  561.  
  562. int city_tax_bonus(struct city *pcity)
  563. {
  564.   return pcity->tax_bonus;
  565. }
  566.  
  567. /**************************************************************************
  568. ...
  569. **************************************************************************/
  570. int set_city_science_bonus(struct city *pcity)
  571. {
  572.   int science_bonus = 100;
  573.   if (city_got_building(pcity, B_LIBRARY)) {
  574.     science_bonus+=50;
  575.     if (city_got_building(pcity, B_UNIVERSITY)) {
  576.       science_bonus+=50;
  577.     }
  578.     if ((city_affected_by_wonder(pcity, B_SETI) || city_got_building(pcity, B_RESEARCH)))
  579.       science_bonus+=50;
  580.   }
  581.   if (city_affected_by_wonder(pcity, B_COPERNICUS)) 
  582.     science_bonus+=50;
  583.   if (city_affected_by_wonder(pcity, B_ISAAC))
  584.     science_bonus+=100;
  585.   pcity->science_bonus = science_bonus;
  586.   return science_bonus;
  587. }
  588.  
  589. int city_science_bonus(struct city *pcity)
  590. {
  591.   return pcity->science_bonus;
  592. }
  593.  
  594. int wants_to_be_bigger(struct city *pcity)
  595. {
  596.   if (pcity->size < 8) return 1;
  597.   if (city_got_building(pcity, B_SEWER)) return 1;
  598.   if (city_got_building(pcity, B_AQUEDUCT) && pcity->size < 12) return 1;
  599.   if (!pcity->is_building_unit) {
  600.     if (pcity->currently_building == B_SEWER && pcity->did_buy == 1) return 1;
  601.     if (pcity->currently_building == B_AQUEDUCT && pcity->did_buy == 1) return 1;
  602.   } /* saves a lot of stupid flipflops -- Syela */
  603.   return 0;
  604. }
  605.  
  606. /*
  607.  *  Units in a bought city are transferred to the new owner, units 
  608.  * supported by the city, but held in other cities are updated to
  609.  * reflect those cities as their new homecity.  Units supported 
  610.  * by the bought city, that are not in a city square are deleted.
  611.  * This is consistent with Civ2, but units just outside the bought
  612.  * city are deleted rather than transferred as in Civ2.
  613.  *
  614.  * - Kris Bubendorfer <Kris.Bubendorfer@MCS.VUW.AC.NZ>
  615.  */
  616.  
  617. void transfer_city_units(struct player *pplayer, struct player *pvictim, 
  618.              struct city *pcity, struct city *vcity){
  619.  
  620.   int x = vcity->x;
  621.   int y = vcity->y;
  622.  
  623.   struct genlist_iterator myiter;
  624.  
  625.   printf("Transferring City Units to new owner");
  626.  
  627.   genlist_iterator_init(&myiter, &pvictim->units.list, 0);
  628.  
  629.   for(; ITERATOR_PTR(myiter); ITERATOR_NEXT(myiter)) {
  630.     struct unit *vunit=(struct unit *)ITERATOR_PTR(myiter);
  631.  
  632.     /* Is unit in the city? */
  633.     
  634.     if(same_pos(vunit->x, vunit->y, x, y)){
  635.       create_unit(pplayer, x, y, vunit->type, vunit->veteran,
  636.           pcity->id, vunit->moves_left);
  637.       wipe_unit(0, vunit);
  638.     }else{
  639.       if(vunit->homecity == vcity->id){
  640.     /* look up victim's cities and see if this unit is
  641.        in one of them */
  642.     
  643.     struct city* new_home_city = 
  644.       city_list_find_coor(&pvictim->cities, vunit->x, vunit->y);
  645.     
  646.     if(new_home_city){
  647.       /* unit is in another city: make that the new homecity */
  648.       
  649.       create_unit(pvictim, vunit->x, vunit->y, vunit->type, 
  650.               vunit->veteran, new_home_city->id, vunit->moves_left);
  651.  
  652.     }else{
  653.  
  654.       /* 
  655.        * unit isn't in a city - Civ2 deletes it - seems like
  656.        * a good idea to prevent the city being immediately
  657.        * retaken.  We don't actually have to do anything here 
  658.        * as remove_city deletes all supported units.
  659.        */
  660.      
  661.       wipe_unit(0, vunit);
  662.       
  663.     }
  664.       }
  665.     }
  666.   }
  667. }
  668.