[Freeciv-Dev] Patch: more efficient unhappiness calculation.
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
The number of people who are made unhappy is a quantity which can
easily be calculated. The old code used while loops instead of simple
division.
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.43
diff -u -r1.43 cityturn.c
--- cityturn.c 1998/12/15 09:51:04 1.43
+++ cityturn.c 1998/12/20 06:24:45
@@ -195,31 +195,32 @@
**************************************************************************/
void citizen_happy_units(struct city *pcity, int unhap)
{
+ int step;
+
if (city_got_effect(pcity, B_POLICE)) {
if (get_government(pcity->owner)==G_DEMOCRACY)
unhap-=2;
else
unhap--;
}
- if (unhap>0 && (pcity->ppl_happy[3] + pcity->ppl_content[3])) {
- 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) {
+ 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--;
+ }
}
- if (unhap > 0 && pcity->ppl_happy[3]) {
- pcity->ppl_happy[3]--;
- pcity->ppl_content[3]++;
- unhap--;
- }
}
/* MAKE VERY UNHAPPY CITIZENS WITH THE REST, but that is not
* documented */
}
--
Anthony J. Stuckey stuckey@xxxxxxxxxxxxxxxxx
"When I was young, the sky was filled with stars.
I watched them burn out one by one." -Warren Zevon
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Patch: more efficient unhappiness calculation.,
Tony & <=
|
|