[Freeciv-Dev] Re: (PR#18476) [Patch] generate_warmap() and "TerrainSpeed
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#18476) [Patch] generate_warmap() and "TerrainSpeed" |
From: |
"Marko Lindqvist" <cazfi74@xxxxxxxxx> |
Date: |
Tue, 11 Jul 2006 08:41:54 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18476 >
Marko Lindqvist wrote:
>
> Make really_generate_warmap() UCF_TERRAIN_SPEED aware. I had to
> rewrite most of it. Old version did several things I don't understand
> and I left those out of this new version. This may fix some old bugs but
> more likely brings new ones.
Several bugs fixed
- ML
diff -Nurd -X.diff_ignore freeciv/server/gotohand.c freeciv/server/gotohand.c
--- freeciv/server/gotohand.c 2006-07-11 13:57:11.078125000 +0300
+++ freeciv/server/gotohand.c 2006-07-11 18:30:51.812500000 +0300
@@ -270,10 +270,11 @@
{
int move_cost;
struct tile *orig_tile;
- bool igter;
+ bool igter, terrain_speed;
int maxcost = THRESHOLD * 6 + 2; /* should be big enough without being TOO
big */
struct tile *ptile;
struct player *pplayer;
+ int unit_speed;
if (pcity) {
orig_tile = pcity->tile;
@@ -286,10 +287,25 @@
init_warmap(orig_tile, move_type);
add_to_mapqueue(0, orig_tile);
- if (punit && unit_flag(punit, F_IGTER))
- igter = TRUE;
- else
- igter = FALSE;
+ igter = FALSE;
+ if (punit) {
+ if (unit_flag(punit, F_IGTER)) {
+ igter = TRUE;
+ }
+ terrain_speed = unit_class_flag(get_unit_class(unit_type(punit)),
UCF_TERRAIN_SPEED);
+ if (!terrain_speed) {
+ /* Igter meaningless without terrain_speed */
+ igter = FALSE;
+ }
+ unit_speed = unit_move_rate(punit);
+ } else {
+ /* Guess - can result in bad city warmaps in with custom rulesets */
+ if (move_type == LAND_MOVING) {
+ terrain_speed = TRUE;
+ } else {
+ terrain_speed = FALSE;
+ }
+ }
/* FIXME: Should this apply only to F_CITIES units? -- jjm */
if (punit
@@ -305,69 +321,99 @@
? WARMAP_SEACOST(ptile) : WARMAP_COST(ptile));
adjc_dir_iterate(ptile, tile1, dir) {
- switch (move_type) {
- case LAND_MOVING:
- if (WARMAP_COST(tile1) <= cost)
- continue; /* No need for all the calculations */
+ if ((move_type == LAND_MOVING && WARMAP_COST(tile1) <= cost)
+ || (move_type == SEA_MOVING && WARMAP_SEACOST(tile1) <= cost)) {
+ continue; /* No need for calculations */
+ }
- if (is_ocean(tile_get_terrain(tile1))) {
- if (punit && ground_unit_transporter_capacity(tile1, pplayer) > 0)
- move_cost = SINGLE_MOVE;
- else
- continue;
- } else if (is_ocean(ptile->terrain)) {
- int base_cost
- = tile_get_terrain(tile1)->movement_cost * SINGLE_MOVE;
+ if (!terrain_speed) {
+ if (punit) {
+ if (!can_unit_exist_at_tile(punit, tile1)) {
+ if (move_type == SEA_MOVING) {
+ /* Bombardment allowed for sea units... */
+ if (!is_native_terrain(unit_type(punit), ptile->terrain)) {
+ /* ...but not from land city */
+ continue;
+ }
+ move_cost = SINGLE_MOVE;
+ } else {
+ /* Land or air moving */
+ if (move_type == LAND_MOVING
+ && ground_unit_transporter_capacity(tile1, pplayer) > 0) {
+ /* Enters transport */
+ move_cost = SINGLE_MOVE;
+ } else {
+ /* Can't enter tile */
+ continue;
+ }
+ }
+ } else {
+ /* Punit can_exist_at_tile() */
+ move_cost = SINGLE_MOVE;
+ }
+ } else {
+ /* No punit */
+ if ((move_type == SEA_MOVING && !is_ocean(tile1->terrain))
+ || (move_type == LAND_MOVING && is_ocean(tile1->terrain))) {
+ /* Can't enter tile */
+ continue;
+ }
+ move_cost = SINGLE_MOVE;
+ }
+ } else {
- move_cost = igter ? MOVE_COST_ROAD : MIN(base_cost,
unit_move_rate(punit));
- } else if (igter)
- /* NOT c = 1 (Syela) [why not? - Thue] */
- move_cost = (map_move_cost_ai(ptile, tile1) != 0
- ? SINGLE_MOVE : 0);
- else if (punit) {
- const int tmp1 = map_move_cost_ai(ptile, tile1);
- const int tmp2 = unit_move_rate(punit);
+ /* Speed determined by terrain */
+ if (punit) {
+ if (!can_unit_exist_at_tile(punit, tile1)) {
+ if (move_type == LAND_MOVING
+ && ground_unit_transporter_capacity(tile1, pplayer) > 0) {
+ move_cost = SINGLE_MOVE; /* Go on board */
+ } else if (move_type == SEA_MOVING) {
+ /* Bombardment allowed for sea units */
+ if (!is_native_terrain(unit_type(punit), ptile->terrain)) {
+ /* But not from land city */
+ continue;
+ }
+ int base_cost = map_move_cost(ptile, tile1);
- move_cost = MIN(tmp1, tmp2);
-#if 0
- } else {
- c = ptile->move_cost[k];
- /* This led to a bad bug where a unit in a swamp was considered
- * too far away. */
-#endif
- } else {
- /* we have a city */
- const int tmp1 = map_move_cost_ai(tile1, ptile);
- const int tmp2 = map_move_cost_ai(ptile, tile1);
+ move_cost = igter ? MIN(MOVE_COST_ROAD, base_cost) : base_cost;
+ } else {
+ continue; /* Can't enter tile */
+ }
+ } else {
+ /* punit can_exist_at_tile() */
+ int base_cost = map_move_cost(ptile, tile1);
- move_cost = (tmp2 + tmp1 + (tmp2 > tmp1 ? 1 : 0)) / 2;
+ base_cost = base_cost > unit_speed ? unit_speed : base_cost;
+ move_cost = igter ? MIN(MOVE_COST_ROAD, base_cost) : base_cost;
+ }
+ } else if ((move_type == LAND_MOVING && is_ocean(tile1->terrain))
+ || (move_type == SEA_MOVING && !is_ocean(tile1->terrain))) {
+ continue; /* City warmap ignores
possible ships */
+ } else {
+ move_cost = map_move_cost(ptile, tile1);
}
+ }
- move_cost += cost;
+ move_cost += cost;
+
+ if (move_type != SEA_MOVING) {
if (WARMAP_COST(tile1) > move_cost && move_cost < maxcost) {
WARMAP_COST(tile1) = move_cost;
add_to_mapqueue(move_cost, tile1);
}
- break;
-
-
- case SEA_MOVING:
- move_cost = SINGLE_MOVE;
- move_cost += cost;
+ } else if (move_type == SEA_MOVING) {
if (WARMAP_SEACOST(tile1) > move_cost && move_cost < maxcost) {
- /* by adding the move_cost to the warmap regardless if we
- can move between we allow for shore bombardment/transport
- to inland positions/etc. */
+ /* by adding the move_cost to the warmap regardless if we
+ * can move between we allow for shore bombardment/transport
+ * to inland positions/etc. */
WARMAP_SEACOST(tile1) = move_cost;
- if (map_move_cost_ai(ptile, tile1)
- == MOVE_COST_FOR_VALID_SEA_STEP) {
- add_to_mapqueue(move_cost, tile1);
+ if ((punit && can_unit_exist_at_tile(punit, tile1))
+ || (!punit && (is_ocean(tile1->terrain) || tile1->city))) {
+ /* Unit can actually move to tile */
+ add_to_mapqueue(move_cost, tile1);
}
- }
- break;
- default:
- move_cost = 0; /* silence compiler warning */
- die("Bad/unimplemented move_type in really_generate_warmap().");
+ }
}
} adjc_dir_iterate_end;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#18476) [Patch] generate_warmap() and "TerrainSpeed",
Marko Lindqvist <=
|
|