diff -Nur -Xpatches/no.freeciv freeciv/common/city.h my_freeciv/common/city.h --- freeciv/common/city.h Wed May 16 18:18:36 2001 +++ my_freeciv/common/city.h Thu May 17 22:38:22 2001 @@ -192,6 +192,7 @@ ppl_*[3] is distribution after units enfored martial order. ppl_*[4] is distribution after wonders. (final result.) */ int ppl_happy[5], ppl_content[5], ppl_unhappy[5]; + int ppl_residue[5]; /* leftover unhappiness */ /* Specialists */ int ppl_elvis, ppl_scientist, ppl_taxman; diff -Nur -Xpatches/no.freeciv freeciv/server/cityturn.c my_freeciv/server/cityturn.c --- freeciv/server/cityturn.c Wed May 16 18:19:15 2001 +++ my_freeciv/server/cityturn.c Thu May 17 22:38:22 2001 @@ -153,6 +153,7 @@ **************************************************************************/ static void happy_copy(struct city *pcity, int i) { + pcity->ppl_residue[i+1]=pcity->ppl_residue[i]; pcity->ppl_unhappy[i+1]=pcity->ppl_unhappy[i]; pcity->ppl_content[i+1]=pcity->ppl_content[i]; pcity->ppl_happy[i+1]=pcity->ppl_happy[i]; @@ -167,6 +168,10 @@ workers = pcity->size - city_specialists(pcity); tmp = content_citizens(&game.players[pcity->owner]); + /* leftover unhappiness is no longer discarded, + but saved in ppl_residue[i] instead. */ + pcity->ppl_residue[0] = MAX(0, -tmp); + /* nobody can be content or happy until ppl_residue[i]=0 */ pcity->ppl_content[0] = MAX(0, MIN(workers, tmp)); pcity->ppl_unhappy[0] = workers - pcity->ppl_content[0]; pcity->ppl_happy[0] = 0; /* no one is born happy */ @@ -177,11 +182,20 @@ **************************************************************************/ static void citizen_happy_luxury(struct city *pcity) { - int x=pcity->luxury_total; + /* luxury above 2*citysize has no effect, as in Civ2 -- Jing */ + int x=MIN(pcity->luxury_total, 2*pcity->size); + happy_copy(pcity, 0); - /* make people happy, content are made happy first, then unhappy content, - etc. each conversions costs 2 luxuries. */ - while (x>=2 && (pcity->ppl_content[1])) { + + /* make people happy: + leftover unhappiness (residue) is eliminated first, + then content are made happy, then unhappy content, etc. + each conversions costs 2 luxuries. */ + while (x>=2 && pcity->ppl_residue[1]) { + pcity->ppl_residue[1]--; + x-=2; + } + while (x>=2 && pcity->ppl_content[1]) { pcity->ppl_content[1]--; pcity->ppl_happy[1]++; x-=2; @@ -189,13 +203,11 @@ while (x>=4 && pcity->ppl_unhappy[1]) { pcity->ppl_unhappy[1]--; pcity->ppl_happy[1]++; -/* x-=2; We can't seriously mean this, right? -- Syela */ - x-=4; + x-=4; /* unhappy ->(content)-> happy costs 4 luxuries*/ } - if (x>=2 && pcity->ppl_unhappy[1]) { + if (x>=2 && pcity->ppl_unhappy[1]) { /* x=2 or 3 */ pcity->ppl_unhappy[1]--; pcity->ppl_content[1]++; - x-=2; } } @@ -205,27 +217,25 @@ **************************************************************************/ static void citizen_happy_units(struct city *pcity, int unhap) { - int step; - - if (unhap>0) { - step=MIN(unhap,pcity->ppl_content[3]); - pcity->ppl_content[3]-=step; - pcity->ppl_unhappy[3]+=step; - unhap-=step; - if (unhap>0) { - step=MIN((unhap/2),pcity->ppl_happy[3]); - pcity->ppl_happy[3]-=step; - pcity->ppl_unhappy[3]+=step; - unhap -= step * 2; - if ((unhap > 0) && pcity->ppl_happy[3]) { - pcity->ppl_happy[3]--; - pcity->ppl_content[3]++; - unhap--; - } + while (unhap>0 && pcity->ppl_content[3]) { + pcity->ppl_content[3]--; + pcity->ppl_unhappy[3]++; + unhap--; + } + while (unhap>=2 && pcity->ppl_happy[3]) { + pcity->ppl_happy[3]--; + pcity->ppl_unhappy[3]++; + unhap-=2; + } + if (unhap>0) { + if (pcity->ppl_happy[3]>0) { /* 1 unhap left */ + pcity->ppl_happy[3]--; + pcity->ppl_content[3]++; + } + else { /* everyone is unhappy now, add unhap to residue */ + pcity->ppl_residue[3]+=unhap; } } - /* MAKE VERY UNHAPPY CITIZENS WITH THE REST, but that is not documented */ - } /************************************************************************** @@ -235,35 +245,30 @@ { struct government *g = get_gov_pcity(pcity); int faces=0; + happy_copy(pcity, 1); - if (city_got_building(pcity,B_TEMPLE)) { + if (city_got_building(pcity,B_TEMPLE)) faces+=get_temple_power(pcity); - } if (city_got_building(pcity,B_COURTHOUSE) && - g->corruption_level == 0) { + g->corruption_level == 0) faces++; - } - if (city_got_building(pcity, B_COLOSSEUM)) faces+=get_colosseum_power(pcity); if (city_got_effect(pcity, B_CATHEDRAL)) faces+=get_cathedral_power(pcity); + + /* make people content (but not happy): + get rid of residue first, then make unhappy content. */ + while (faces && pcity->ppl_residue[2]) { + pcity->ppl_residue[2]--; + faces--; + } while (faces && pcity->ppl_unhappy[2]) { pcity->ppl_unhappy[2]--; pcity->ppl_content[2]++; faces--; } -/* no longer hijacking ppl_content[0]; seems no longer to be helpful -- Syela */ - /* TV doesn't make people happy just content... - - while (faces && pcity->ppl_content[2]) { - pcity->ppl_content[2]--; - pcity->ppl_happy[2]++; - faces--; - } - - */ } /************************************************************************** @@ -272,8 +277,9 @@ static void citizen_happy_wonders(struct city *pcity) { int bonus=0; + happy_copy(pcity, 3); - bonus = 0; + if (city_affected_by_wonder(pcity, B_HANGING)) { bonus += 1; if (city_got_building(pcity, B_HANGING)) @@ -290,6 +296,11 @@ bonus+=2; if (city_affected_by_wonder(pcity, B_CURE)) bonus+=1; + /* get rid of residue first, then make unhappy content */ + while (bonus && pcity->ppl_residue[4]) { + pcity->ppl_residue[4]--; + bonus--; + } while (bonus && pcity->ppl_unhappy[4]) { pcity->ppl_unhappy[4]--; pcity->ppl_content[4]++; @@ -298,6 +309,7 @@ if (city_affected_by_wonder(pcity, B_SHAKESPEARE)) { pcity->ppl_content[4]+=pcity->ppl_unhappy[4]; pcity->ppl_unhappy[4]=0; + pcity->ppl_residue[4]=0; } } @@ -472,9 +484,16 @@ } unit_list_iterate_end; city_units *= g->martial_law_per; - city_units = MIN(city_units, pcity->ppl_unhappy[3]); - pcity->ppl_unhappy[3] -= city_units; - pcity->ppl_content[3] += city_units; + /* get rid of residue first, then make unhappy content */ + while (city_units>0 && pcity->ppl_residue[3]) { + pcity->ppl_residue[3]--; + city_units--; + } + while (city_units>0 && pcity->ppl_unhappy[3]) { + pcity->ppl_unhappy[3]--; + pcity->ppl_content[3]++; + city_units--; + } } /* loop over units, subtracting appropriate amounts of food, shields,