[Freeciv-Dev] Re: (PR#9154) turn_last_built: turn or year?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#9154) turn_last_built: turn or year? |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Thu, 1 Jul 2004 10:22:42 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9154 >
Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9154 >
>
> turn_last_built (which I just noticed in packets.def) is labeled there
> as a YEAR. But it's a turn, right? If not it should be!
It looks like it is stored as a year. This is bad since the turn is now
declared to be the principle measure of time. That, and the variable's
name obviously indicates it's a turn.
This patch changes turn_last_built to be a turn. Old savegames just
have their turn_last_built reset; this should be no problem. I also add
a query function city_built_last_turn(), which is used in several places.
jason
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.156
diff -u -r1.156 aicity.c
--- ai/aicity.c 25 Jun 2004 23:43:00 -0000 1.156
+++ ai/aicity.c 1 Jul 2004 17:16:19 -0000
@@ -270,7 +270,7 @@
init_choice(&newchoice);
if (ai_handicap(pplayer, H_AWAY)
- && game_next_year(pcity->turn_last_built) != game.year
+ && city_built_last_turn(pcity)
&& pcity->ai.urgency == 0) {
/* Don't change existing productions unless we have to. */
return;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.221
diff -u -r1.221 city.c
--- common/city.c 25 Jun 2004 23:29:59 -0000 1.221
+++ common/city.c 1 Jul 2004 17:16:20 -0000
@@ -1494,7 +1494,7 @@
if (orig_class == new_class) {
/* There's never a penalty for building something of the same class. */
unpenalized_shields = pcity->before_change_shields;
- } else if (game_next_year(pcity->turn_last_built) >= game.year) {
+ } else if (city_built_last_turn(pcity)) {
/* Surplus shields from the previous production won't be penalized if
* you change production on the very next turn. But you can only use
* up to the city's surplus amount of shields in this way. */
@@ -1805,6 +1805,15 @@
}
/**************************************************************************
+ Return TRUE if the city built something last turn (meaning production
+ was completed between last turn and this).
+**************************************************************************/
+bool city_built_last_turn(const struct city *pcity)
+{
+ return pcity->turn_last_built + 1 >= game.turn;
+}
+
+/**************************************************************************
Modify the incomes according to the taxrates and # of specialists.
**************************************************************************/
static void set_tax_income(struct city *pcity)
@@ -2698,7 +2707,7 @@
pcity->did_sell = FALSE;
pcity->airlift = FALSE;
- pcity->turn_last_built = game.year;
+ pcity->turn_last_built = game.turn;
pcity->changed_from_id = 0;
pcity->changed_from_is_unit = FALSE;
pcity->before_change_shields = 0;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.149
diff -u -r1.149 city.h
--- common/city.h 14 Jun 2004 23:43:08 -0000 1.149
+++ common/city.h 1 Jul 2004 17:16:20 -0000
@@ -485,6 +485,7 @@
int get_city_tax_bonus(const struct city *pcity);
int get_city_shield_bonus(const struct city *pcity);
int get_city_science_bonus(const struct city *pcity);
+bool city_built_last_turn(const struct city *pcity);
/* city creation / destruction */
struct city *create_city_virtual(struct player *pplayer, const int x,
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.29
diff -u -r1.29 packets.def
--- common/packets.def 12 Jun 2004 17:42:27 -0000 1.29
+++ common/packets.def 1 Jul 2004 17:16:20 -0000
@@ -402,7 +402,7 @@
UINT8 currently_building;
BOOL is_building_unit;
- YEAR turn_last_built;
+ TURN turn_last_built;
UINT8 changed_from_id;
BOOL changed_from_is_unit;
UINT16 before_change_shields;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.249
diff -u -r1.249 cityturn.c
--- server/cityturn.c 29 May 2004 20:34:31 -0000 1.249
+++ server/cityturn.c 1 Jul 2004 17:16:22 -0000
@@ -950,7 +950,7 @@
pcity->before_change_shields -=
impr_build_shield_cost(pcity->currently_building);
pcity->shield_stock -= impr_build_shield_cost(pcity->currently_building);
- pcity->turn_last_built = game.year;
+ pcity->turn_last_built = game.turn;
/* to eliminate micromanagement */
if (is_wonder(pcity->currently_building)) {
game.global_wonders[pcity->currently_building] = pcity->id;
@@ -1068,7 +1068,7 @@
assert(pop_cost == 0 || pcity->size >= pop_cost);
/* don't update turn_last_built if we returned above */
- pcity->turn_last_built = game.year;
+ pcity->turn_last_built = game.turn;
(void) create_unit(pplayer, pcity->x, pcity->y, pcity->currently_building,
do_make_unit_veteran(pcity, pcity->currently_building),
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.161
diff -u -r1.161 savegame.c
--- server/savegame.c 24 Jun 2004 13:18:54 -0000 1.161
+++ server/savegame.c 1 Jul 2004 17:16:22 -0000
@@ -176,7 +176,7 @@
and rulesets */
#define SAVEFILE_OPTIONS "startoptions spacerace2 rulesets" \
" diplchance_percent worklists2 map_editor known32fix turn " \
-"attributes watchtower rulesetdir client_worklists orders"
+"attributes watchtower rulesetdir client_worklists orders turn_last_built"
static const char hex_chars[] = "0123456789abcdef";
static const char terrain_chars[] = "adfghjm prstu";
@@ -970,9 +970,14 @@
pcity->currently_building=
secfile_lookup_int(file,
"player%d.c%d.currently_building", plrno, i);
- pcity->turn_last_built=
- secfile_lookup_int_default(file, GAME_START_YEAR,
- "player%d.c%d.turn_last_built", plrno, i);
+ if (has_capability("turn_last_built", savefile_options)) {
+ pcity->turn_last_built = secfile_lookup_int(file,
+ "player%d.c%d.turn_last_built", plrno, i);
+ } else {
+ /* Before, turn_last_built was stored as a year. There is no easy
+ * way to convert this into a turn value. */
+ pcity->turn_last_built = 0;
+ }
pcity->changed_from_id=
secfile_lookup_int_default(file, pcity->currently_building,
"player%d.c%d.changed_from_id", plrno, i);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#9154) turn_last_built: turn or year?,
Jason Short <=
|
|