[Freeciv-Dev] Auto come back for air units
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Air unit version 0.00
This patch forces all air unit to go back to a friendly town when
air_unit_has_to_return is true.
Todo:
- take the nearest town instead of the first one.
- add more test in air_unit_...
for fighter come back at the end of turn.
for bomber come back if moves left <= 12(8) * 3
for the CRUISE_MISSILE and NUCLEAR I don't know yet
- add a toggle command ignore/doesn't ignore auto come back.
- add an option in the client so that ignore/ not ignore auto come back.
Remarq:
- I added check_players_stuff. The idea is to put here end of turn check for
air planes, famines, low budget ...
Best regards,
diff -aur -Xno.freeciv freeciv/common/log.c fc/common/log.c
--- freeciv/common/log.c Tue Jun 15 15:08:12 1999
+++ fc/common/log.c Tue Jun 15 15:18:13 1999
@@ -63,10 +63,18 @@
}
if (n == 0) {
level = atoi(level_str);
- if (level >= LOG_NORMAL && level <= LOG_DEBUG) {
+ #ifdef DEBUG
+ if (level >= LOG_FATAL && level <= LOG_DEBUG) {
+ #else
+ if (level >= LOG_FATAL && level <= LOG_VERBOSE) {
+ #endif
return level;
} else {
fprintf(stderr, "Bad log level %d in \"%s\".\n", level, level_str);
+ #ifndef DEBUG
+ if (level == LOG_DEBUG)
+ fprintf(stderr, "Freeciv must be compiled with the DEBUG flag to use
LOG_DEBUG\n");
+ #endif
return -1;
}
}
diff -aur -Xno.freeciv freeciv/common/unit.c fc/common/unit.c
--- freeciv/common/unit.c Tue Jun 15 15:08:13 1999
+++ fc/common/unit.c Tue Jun 15 16:33:35 1999
@@ -426,6 +426,18 @@
/**************************************************************************
...
**************************************************************************/
+
+int air_unit_has_to_return(struct unit *punit)
+{
+return 1;
+/* if ((punit->type == U_BOMBER) ||
+ (punit->type == U_SBOMBER))
+ return(punit->moves_left <= get_unit_type(punit->type)->moves >> 1); */
+}
+
+/**************************************************************************
+...
+**************************************************************************/
int is_ground_unit(struct unit *punit)
{
return (unit_types[punit->type].move_type == LAND_MOVING);
diff -aur -Xno.freeciv freeciv/common/unit.h fc/common/unit.h
--- freeciv/common/unit.h Tue Jun 15 15:08:13 1999
+++ fc/common/unit.h Tue Jun 15 15:35:29 1999
@@ -267,6 +267,7 @@
int is_air_unit(struct unit *punit);
int is_air_unittype(enum unit_type_id id);
int is_heli_unit(struct unit *punit);
+int air_unit_has_to_return(struct unit *punit);
int is_ground_unit(struct unit *punit);
int is_ground_unittype(enum unit_type_id id);
int can_unit_build_city(struct unit *punit);
diff -aur -Xno.freeciv freeciv/server/civserver.c fc/server/civserver.c
--- freeciv/server/civserver.c Tue Jun 15 15:08:14 1999
+++ fc/server/civserver.c Tue Jun 15 16:30:26 1999
@@ -63,6 +63,7 @@
#include "stdinhand.h"
#include "unitfunc.h"
#include "unithand.h"
+#include "unittools.h"
#include "advmilitary.h"
#include "aihand.h"
@@ -71,6 +72,7 @@
void end_game(void);
void before_end_year(void); /* main() belongs at the bottom of files!! --
Syela */
+void check_players_stuff();
int end_turn(void);
void start_new_game(void);
void init_new_game(void);
@@ -459,6 +461,8 @@
ai_start_turn(); /* Misleading name for manage_units -- Syela */
freelog(LOG_DEBUG, "Auto-Attack phase");
auto_attack();
+ freelog(LOG_DEBUG, "Check_players_stuff");
+ check_players_stuff();
freelog(LOG_DEBUG, "Endturn");
end_turn();
freelog(LOG_DEBUG, "Gamenextyear");
@@ -708,6 +712,10 @@
}
}
+/**************************************************************************
+...
+**************************************************************************/
+
void ai_start_turn(void)
{
int i;
@@ -721,6 +729,10 @@
}
}
+/**************************************************************************
+...
+**************************************************************************/
+
int end_turn(void)
{
int i;
@@ -752,6 +764,17 @@
return 1;
}
+/**************************************************************************
+...
+**************************************************************************/
+
+void check_players_stuff()
+{
+int i;
+
+for(i=0;i<game.nplayers;i++)
+ check_planes_tool(&game.players[i]);
+}
/**************************************************************************
...
diff -aur -Xno.freeciv freeciv/server/unittools.c fc/server/unittools.c
--- freeciv/server/unittools.c Tue Jun 15 15:08:16 1999
+++ fc/server/unittools.c Tue Jun 15 16:25:52 1999
@@ -741,3 +741,33 @@
}
}
+/*******************************************************
+...
+*******************************************************/
+
+void check_planes_tool(struct player *pplayer)
+{
+unit_list_iterate(pplayer->units,punit)
+ freelog(LOG_DEBUG,"%s fuel %d.\n",
+ get_unit_type(punit->type)->name,
+ punit->moves_left);
+if (is_air_unit(punit) &&
+ !map_get_city(punit->x,punit->y) &&
+ air_unit_has_to_return(punit) &&
+ punit->moves_left) {
+ freelog(LOG_DEBUG,"Looking for a place to land for a %s.\n",
+ get_unit_type(punit->type)->name);
+ city_list_iterate(pplayer->cities,pcity)
+ if (3 * real_map_distance(punit->x,punit->y,pcity->x,pcity->y) <=
punit->moves_left) {
+ punit->goto_dest_x = pcity->x;
+ punit->goto_dest_y = pcity->y;
+ do_unit_goto(pplayer,punit);
+ freelog(LOG_DEBUG,"Find the city of %s for a %s fuel %d.\n",
+ pcity->name,
+ get_unit_type(punit->type)->name,
+ punit->moves_left);
+ }
+ city_list_iterate_end;
+ }
+unit_list_iterate_end;
+}
diff -aur -Xno.freeciv freeciv/server/unittools.h fc/server/unittools.h
--- freeciv/server/unittools.h Tue Jun 15 15:08:16 1999
+++ fc/server/unittools.h Tue Jun 15 15:35:29 1999
@@ -13,6 +13,7 @@
#ifndef FC__UNITTOOLS_H
#define FC__UNITTOOLS_H
+#include "gotohand.h"
#include "packets.h"
#include "unit.h"
@@ -53,5 +54,6 @@
int teleport_unit_to_city(struct unit *punit, struct city *pcity, int
mov_cost);
struct unit *is_enemy_unit_on_tile(int x, int y, int owner);
void resolve_unit_stack(int x, int y, int verbose);
+void check_planes_tool(struct player *pplayer);
#endif /* FC__UNITTOOLS_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Auto come back for air units,
Nicolas Brunel <=
|
|