Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2001:
[Freeciv-Dev] Re: [Patch][RFC] Accessing unsafe data
Home

[Freeciv-Dev] Re: [Patch][RFC] Accessing unsafe data

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Cc: Thue Janus Kristensen <thue@xxxxxxx>
Subject: [Freeciv-Dev] Re: [Patch][RFC] Accessing unsafe data
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Oct 2001 11:40:05 +0200
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

On Thu, Oct 11, 2001 at 09:13:31PM +0200, Raimar Falke wrote:
> 
> All from common/city: generic_city_refresh calls
> set_food_trade_shields calls city_get_food_tile calls city_celebrating
> calls city_happy which accesses pcity->ppl_happy[4] which is undefined
> IMHO.
> 
> Correct? Wrong? This may lead to different initial production data
> depending on the happiness of the last calculation of this city. This
> last calculation does have to be done at the last turn (which would
> set was_happy).

I have a patch which has the same effect as the old one but is a bit
more general. The function city_get_shields_tile (and also *_food_*
and *_trade_*) now take the is_celebrating argument and are been
renamed to base_*. The test for celebrating has been split like this:

+static int base_city_celebrating(struct city *pcity)
+{
+  return (pcity->size >= get_gov_pcity(pcity)->rapture_size
+         && pcity->was_happy);
+}

 int city_celebrating(struct city *pcity)
 {
-  struct government *g = get_gov_pcity(pcity);
-  return (pcity->size>=g->rapture_size && pcity->was_happy && 
city_happy(pcity));
+  return base_city_celebrating(pcity) && city_happy(pcity);
 }

base_city_celebrating is used for the calculation of the production in
set_food_trade_shields.

The more general interface is necessary because the CMA has to get the
prodution for the unhappy or happy city.

Comments? 

If there are no objections I will apply this patch.

Old patch:

> diff -u -r1.126 city.c
> --- city.c    2001/10/04 20:23:35     1.126
> +++ city.c    2001/10/11 19:06:38
> @@ -1898,6 +1902,18 @@
>  **************************************************************************/
>  void generic_city_refresh(struct city *pcity)
>  {
> +  if (pcity->was_happy) {
> +    pcity->ppl_happy[4] = pcity->size;
> +    pcity->ppl_content[4] = 0;
> +    pcity->ppl_unhappy[4] = 0;
> +    pcity->ppl_angry[4] = 0;
> +  } else {
> +    pcity->ppl_happy[4] = 0;
> +    pcity->ppl_content[4] = 0;
> +    pcity->ppl_unhappy[4] = pcity->size;
> +    pcity->ppl_angry[4] = 0;
> +  }
> +
>    set_food_trade_shields(pcity);
>    citizen_happy_size(pcity);
>    set_tax_income(pcity);     /* calc base luxury, tax & bulbs */

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Programming today is a race between software engineers striving to
  build bigger and better idiot-proof programs, and the Universe trying
  to produce bigger and better idiots. So far, the Universe is winning."
    -- Rich Cook

Attachment: base_city1.diff
Description: Text document


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