[Freeciv-Dev] (PR#12889) move tile_activity_time into tile.[ch]
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12889 >
This patch moves map_xxx_time into tile.[ch]. map_activity_time is
renamed as tile_activity_time. All other map_xxx_time functions are
removed and their callers are changed to use tile_activity_time.
This simplifies the interface for these functions greatly. The callers
in unittools can probably be simplified as well, but for the moment I've
just done the a straightforward substitution.
-jason
Index: client/text.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/text.c,v
retrieving revision 1.33
diff -u -r1.33 text.c
--- client/text.c 23 Apr 2005 17:40:23 -0000 1.33
+++ client/text.c 25 Apr 2005 19:51:03 -0000
@@ -330,7 +330,7 @@
if (num_activities > 0) {
add("/");
}
- remains = map_activity_time(i, ptile) - activity_total[i];
+ remains = tile_activity_time(i, ptile) - activity_total[i];
if (remains > 0) {
turns = 1 + (remains + activity_units[i] - 1) / activity_units[i];
} else {
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.218
diff -u -r1.218 map.c
--- common/map.c 25 Apr 2005 19:11:25 -0000 1.218
+++ common/map.c 25 Apr 2005 19:51:05 -0000
@@ -756,107 +756,6 @@
/***************************************************************
...
***************************************************************/
-int map_build_road_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].road_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_build_irrigation_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].irrigation_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_build_mine_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].mining_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_transform_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].transform_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_build_rail_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].rail_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_build_airbase_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].airbase_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_build_fortress_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].fortress_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_clean_pollution_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].clean_pollution_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
-...
-***************************************************************/
-int map_clean_fallout_time(const struct tile *ptile)
-{
- return tile_types[ptile->terrain].clean_fallout_time * ACTIVITY_FACTOR;
-}
-
-/***************************************************************
- Time to complete given activity on given tile.
-***************************************************************/
-int map_activity_time(enum unit_activity activity, const struct tile *ptile)
-{
- switch (activity) {
- case ACTIVITY_POLLUTION:
- return map_clean_pollution_time(ptile);
- case ACTIVITY_ROAD:
- return map_build_road_time(ptile);
- case ACTIVITY_MINE:
- return map_build_mine_time(ptile);
- case ACTIVITY_IRRIGATE:
- return map_build_irrigation_time(ptile);
- case ACTIVITY_FORTRESS:
- return map_build_fortress_time(ptile);
- case ACTIVITY_RAILROAD:
- return map_build_rail_time(ptile);
- case ACTIVITY_TRANSFORM:
- return map_transform_time(ptile);
- case ACTIVITY_AIRBASE:
- return map_build_airbase_time(ptile);
- case ACTIVITY_FALLOUT:
- return map_clean_fallout_time(ptile);
- default:
- return 0;
- }
-}
-
-/***************************************************************
-...
-***************************************************************/
static void clear_infrastructure(struct tile *ptile)
{
tile_clear_special(ptile, S_INFRASTRUCTURE_MASK);
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.240
diff -u -r1.240 map.h
--- common/map.h 25 Apr 2005 19:11:25 -0000 1.240
+++ common/map.h 25 Apr 2005 19:51:05 -0000
@@ -290,17 +290,6 @@
void change_terrain(struct tile *ptile, Terrain_type_id type);
void map_transform_tile(struct tile *ptile);
-int map_build_road_time(const struct tile *ptile);
-int map_build_irrigation_time(const struct tile *ptile);
-int map_build_mine_time(const struct tile *ptile);
-int map_transform_time(const struct tile *ptile);
-int map_build_rail_time(const struct tile *ptile);
-int map_build_airbase_time(const struct tile *ptile);
-int map_build_fortress_time(const struct tile *ptile);
-int map_clean_pollution_time(const struct tile *ptile);
-int map_clean_fallout_time(const struct tile *ptile);
-int map_activity_time(enum unit_activity activity, const struct tile *ptile);
-
bool can_channel_land(const struct tile *ptile);
bool can_reclaim_ocean(const struct tile *ptile);
@@ -578,9 +567,4 @@
|| ptile->nat_y >= map.ysize - ydist);
}
-/* An arbitrary somewhat integer value. Activity times are multiplied by
- * this amount, and divided by them later before being used. This may
- * help to avoid rounding errors; however it should probably be removed. */
-#define ACTIVITY_FACTOR 10
-
#endif /* FC__MAP_H */
Index: common/tile.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.c,v
retrieving revision 1.1
diff -u -r1.1 tile.c
--- common/tile.c 25 Apr 2005 19:11:26 -0000 1.1
+++ common/tile.c 25 Apr 2005 19:51:05 -0000
@@ -138,3 +138,32 @@
{
ptile->continent = val;
}
+
+/****************************************************************************
+ Time to complete the given activity on the given tile.
+****************************************************************************/
+int tile_activity_time(enum unit_activity activity, const struct tile *ptile)
+{
+ switch (activity) {
+ case ACTIVITY_POLLUTION:
+ return tile_types[ptile->terrain].clean_pollution_time * ACTIVITY_FACTOR;
+ case ACTIVITY_ROAD:
+ return tile_types[ptile->terrain].road_time * ACTIVITY_FACTOR;
+ case ACTIVITY_MINE:
+ return tile_types[ptile->terrain].mining_time * ACTIVITY_FACTOR;
+ case ACTIVITY_IRRIGATE:
+ return tile_types[ptile->terrain].irrigation_time * ACTIVITY_FACTOR;
+ case ACTIVITY_FORTRESS:
+ return tile_types[ptile->terrain].fortress_time * ACTIVITY_FACTOR;
+ case ACTIVITY_RAILROAD:
+ return tile_types[ptile->terrain].rail_time * ACTIVITY_FACTOR;
+ case ACTIVITY_TRANSFORM:
+ return tile_types[ptile->terrain].transform_time * ACTIVITY_FACTOR;
+ case ACTIVITY_AIRBASE:
+ return tile_types[ptile->terrain].airbase_time * ACTIVITY_FACTOR;
+ case ACTIVITY_FALLOUT:
+ return tile_types[ptile->terrain].clean_fallout_time * ACTIVITY_FACTOR;
+ default:
+ return 0;
+ }
+}
Index: common/tile.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tile.h,v
retrieving revision 1.1
diff -u -r1.1 tile.h
--- common/tile.h 25 Apr 2005 19:11:26 -0000 1.1
+++ common/tile.h 25 Apr 2005 19:51:05 -0000
@@ -16,6 +16,7 @@
#include "fc_types.h"
#include "terrain.h"
+#include "unit.h"
/* Convenience macro for accessing tile coordinates. This should only be
* used for debugging. */
@@ -65,4 +66,11 @@
void tile_set_continent(struct tile *ptile, Continent_id val);
Continent_id tile_get_continent(const struct tile *ptile);
+/* An arbitrary somewhat integer value. Activity times are multiplied by
+ * this amount, and divided by them later before being used. This may
+ * help to avoid rounding errors; however it should probably be removed. */
+#define ACTIVITY_FACTOR 10
+int tile_activity_time(enum unit_activity activity,
+ const struct tile *ptile);
+
#endif /* FC__TILE_H */
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.234
diff -u -r1.234 unit.c
--- common/unit.c 23 Apr 2005 17:40:27 -0000 1.234
+++ common/unit.c 25 Apr 2005 19:51:07 -0000
@@ -477,7 +477,7 @@
/* FIXME: This is just an approximation since we don't account for
* get_activity_rate_this_turn. */
int speed = get_activity_rate(punit);
- int time = map_activity_time(activity, ptile);
+ int time = tile_activity_time(activity, ptile);
if (time >= 0 && speed >= 0) {
return (time - 1) / speed + 1; /* round up */
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.339
diff -u -r1.339 unittools.c
--- server/unittools.c 25 Apr 2005 19:28:22 -0000 1.339
+++ server/unittools.c 25 Apr 2005 19:51:10 -0000
@@ -723,7 +723,7 @@
if (activity==ACTIVITY_POLLUTION) {
if (total_activity (punit->tile, ACTIVITY_POLLUTION)
- >= map_clean_pollution_time(punit->tile)) {
+ >= tile_activity_time(ACTIVITY_POLLUTION, punit->tile)) {
tile_clear_special(punit->tile, S_POLLUTION);
unit_activity_done = TRUE;
}
@@ -731,7 +731,7 @@
if (activity==ACTIVITY_FALLOUT) {
if (total_activity (punit->tile, ACTIVITY_FALLOUT)
- >= map_clean_fallout_time(punit->tile)) {
+ >= tile_activity_time(ACTIVITY_FALLOUT, punit->tile)) {
tile_clear_special(punit->tile, S_FALLOUT);
unit_activity_done = TRUE;
}
@@ -739,7 +739,7 @@
if (activity==ACTIVITY_FORTRESS) {
if (total_activity (punit->tile, ACTIVITY_FORTRESS)
- >= map_build_fortress_time(punit->tile)) {
+ >= tile_activity_time(ACTIVITY_FORTRESS, punit->tile)) {
tile_set_special(punit->tile, S_FORTRESS);
unit_activity_done = TRUE;
/* watchtower becomes effective */
@@ -760,15 +760,15 @@
if (activity==ACTIVITY_AIRBASE) {
if (total_activity (punit->tile, ACTIVITY_AIRBASE)
- >= map_build_airbase_time(punit->tile)) {
+ >= tile_activity_time(ACTIVITY_AIRBASE, punit->tile)) {
tile_set_special(punit->tile, S_AIRBASE);
unit_activity_done = TRUE;
}
}
if (activity==ACTIVITY_IRRIGATE) {
- if (total_activity (punit->tile, ACTIVITY_IRRIGATE) >=
- map_build_irrigation_time(punit->tile)) {
+ if (total_activity (punit->tile, ACTIVITY_IRRIGATE)
+ >= tile_activity_time(ACTIVITY_IRRIGATE, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
map_irrigate_tile(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
@@ -778,8 +778,8 @@
if (activity==ACTIVITY_ROAD) {
if (total_activity (punit->tile, ACTIVITY_ROAD)
- + total_activity (punit->tile, ACTIVITY_RAILROAD) >=
- map_build_road_time(punit->tile)) {
+ + total_activity (punit->tile, ACTIVITY_RAILROAD)
+ >= tile_activity_time(ACTIVITY_ROAD, punit->tile)) {
tile_set_special(punit->tile, S_ROAD);
unit_activity_done = TRUE;
}
@@ -787,15 +787,15 @@
if (activity==ACTIVITY_RAILROAD) {
if (total_activity (punit->tile, ACTIVITY_RAILROAD)
- >= map_build_rail_time(punit->tile)) {
+ >= tile_activity_time(ACTIVITY_RAILROAD, punit->tile)) {
tile_set_special(punit->tile, S_RAILROAD);
unit_activity_done = TRUE;
}
}
if (activity==ACTIVITY_MINE) {
- if (total_activity (punit->tile, ACTIVITY_MINE) >=
- map_build_mine_time(punit->tile)) {
+ if (total_activity (punit->tile, ACTIVITY_MINE)
+ >= tile_activity_time(ACTIVITY_MINE, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
map_mine_tile(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
@@ -805,8 +805,8 @@
}
if (activity==ACTIVITY_TRANSFORM) {
- if (total_activity (punit->tile, ACTIVITY_TRANSFORM) >=
- map_transform_time(punit->tile)) {
+ if (total_activity (punit->tile, ACTIVITY_TRANSFORM)
+ >= tile_activity_time(ACTIVITY_TRANSFORM, punit->tile)) {
Terrain_type_id old = tile_get_terrain(punit->tile);
map_transform_tile(punit->tile);
solvency = check_terrain_ocean_land_change(punit->tile, old);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12889) move tile_activity_time into tile.[ch],
Jason Short <=
|
|