[Freeciv-Dev] (PR#2930) building requirements for units v2
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2930) building requirements for units v2 |
From: |
"Per I. Mathisen via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Thu, 30 Jan 2003 12:18:55 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
This patch adds a new field to units.ruleset called "impr_req", which
makes the building of a unit conditional upon the presence of the given
building.
I have committed the AI and bugfix parts of the patch separately. It is
now very small and should be easy to review & commit.
- Per
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.134
diff -u -r1.134 advmilitary.c
--- ai/advmilitary.c 30 Jan 2003 19:53:50 -0000 1.134
+++ ai/advmilitary.c 30 Jan 2003 20:14:20 -0000
@@ -954,7 +954,17 @@
best_choice->choice = unit_type;
best_choice->want = want;
best_choice->type = CT_ATTACKER;
- } /* FIXME: else find out why we can't build it and do something */
+ } else if (can_build_improvement(pcity,
+ get_unit_type(unit_type)->impr_requirement)) {
+ Impr_Type_id id = get_unit_type(unit_type)->impr_requirement;
+
+ CITY_LOG(LOG_DEBUG, pcity, "building %s to build %s",
+ get_improvement_type(id)->name,
+ get_unit_type(unit_type)->name);
+ best_choice->choice = id;
+ best_choice->want = want;
+ best_choice->type = CT_BUILDING;
+ }
}
}
}
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.278
diff -u -r1.278 packhand.c
--- client/packhand.c 30 Jan 2003 19:26:07 -0000 1.278
+++ client/packhand.c 30 Jan 2003 20:14:21 -0000
@@ -1761,6 +1761,7 @@
u->defense_strength = p->defense_strength;
u->move_rate = p->move_rate;
u->tech_requirement = p->tech_requirement;
+ u->impr_requirement = p->impr_requirement;
u->vision_range = p->vision_range;
u->transport_capacity = p->transport_capacity;
u->hp = p->hp;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.118
diff -u -r1.118 capstr.c
--- common/capstr.c 30 Jan 2003 19:26:08 -0000 1.118
+++ common/capstr.c 30 Jan 2003 20:14:21 -0000
@@ -75,7 +75,7 @@
*/
#define CAPABILITY "+1.14.0 conn_info +occupied team tech_impr_gfx " \
- "city_struct_minor_cleanup obsolete_last"
+ "city_struct_minor_cleanup obsolete_last +impr_req"
/* "+1.14.0" is protocol for 1.14.0 release.
*
@@ -95,6 +95,8 @@
*
* "obsolete_last" means A_LAST is used to mark improvements that are never
* obsoleted. Previously A_NONE was used.
+ *
+ * "impr_req" is city improvements as a prerequisite for building units
*/
void init_our_capability(void)
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.177
diff -u -r1.177 city.c
--- common/city.c 16 Jan 2003 18:23:35 -0000 1.177
+++ common/city.c 30 Jan 2003 20:14:21 -0000
@@ -398,15 +398,22 @@
return(could_build_improvement(pcity, id));
}
-
/**************************************************************************
Whether given city can build given unit,
ignoring whether unit is obsolete.
**************************************************************************/
bool can_build_unit_direct(struct city *pcity, Unit_Type_id id)
{
- if (!can_player_build_unit_direct(city_owner(pcity), id))
+ Impr_Type_id impr_req;
+
+ if (!can_player_build_unit_direct(city_owner(pcity), id)) {
+ return FALSE;
+ }
+ impr_req = get_unit_type(id)->impr_requirement;
+ assert(impr_req <= B_LAST && impr_req >= 0);
+ if (impr_req != B_LAST && !city_got_building(pcity, impr_req)) {
return FALSE;
+ }
if (!is_ocean_near_tile(pcity->x, pcity->y) && is_water_unit(id)) {
return FALSE;
}
Index: common/packets.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v
retrieving revision 1.230
diff -u -r1.230 packets.c
--- common/packets.c 30 Jan 2003 19:26:08 -0000 1.230
+++ common/packets.c 30 Jan 2003 20:14:22 -0000
@@ -1937,6 +1937,7 @@
dio_put_uint8(&dout, packet->defense_strength);
dio_put_uint8(&dout, packet->move_rate);
dio_put_uint8(&dout, packet->tech_requirement);
+ dio_put_uint8(&dout, packet->impr_requirement);
dio_put_uint8(&dout, packet->vision_range);
dio_put_uint8(&dout, packet->transport_capacity);
dio_put_uint8(&dout, packet->hp);
@@ -1988,6 +1989,7 @@
dio_get_uint8(&din, &packet->defense_strength);
dio_get_uint8(&din, &packet->move_rate);
dio_get_uint8(&din, &packet->tech_requirement);
+ dio_get_uint8(&din, &packet->impr_requirement);
dio_get_uint8(&din, &packet->vision_range);
dio_get_uint8(&din, &packet->transport_capacity);
dio_get_uint8(&din, &packet->hp);
Index: common/packets.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v
retrieving revision 1.131
diff -u -r1.131 packets.h
--- common/packets.h 16 Jan 2003 18:23:36 -0000 1.131
+++ common/packets.h 30 Jan 2003 20:14:22 -0000
@@ -606,6 +606,7 @@
int defense_strength;
int move_rate;
int tech_requirement;
+ int impr_requirement;
int vision_range;
int transport_capacity;
int hp;
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.25
diff -u -r1.25 unittype.c
--- common/unittype.c 14 Jan 2003 22:24:07 -0000 1.25
+++ common/unittype.c 30 Jan 2003 20:14:22 -0000
@@ -419,6 +419,9 @@
**************************************************************************/
bool can_player_build_unit_direct(struct player *p, Unit_Type_id id)
{
+ Impr_Type_id impr_req;
+ Tech_Type_id tech_req;
+
if (!unit_type_exists(id))
return FALSE;
if (unit_type_flag(id, F_NUCLEAR) && game.global_wonders[B_MANHATTEN] == 0)
@@ -428,6 +431,11 @@
return FALSE;
if (get_invention(p,unit_types[id].tech_requirement)!=TECH_KNOWN)
return FALSE;
+ impr_req = unit_types[id].impr_requirement;
+ tech_req = get_improvement_type(impr_req)->tech_req;
+ if (impr_req != B_LAST && get_invention(p, tech_req) != TECH_KNOWN) {
+ return FALSE;
+ }
return TRUE;
}
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.18
diff -u -r1.18 unittype.h
--- common/unittype.h 14 Jan 2003 22:24:07 -0000 1.18
+++ common/unittype.h 30 Jan 2003 20:14:22 -0000
@@ -167,6 +167,7 @@
int defense_strength;
int move_rate;
int tech_requirement;
+ int impr_requirement;
int vision_range;
int transport_capacity;
int hp;
Index: data/default/units.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/units.ruleset,v
retrieving revision 1.43
diff -u -r1.43 units.ruleset
--- data/default/units.ruleset 28 Jan 2003 01:50:14 -0000 1.43
+++ data/default/units.ruleset 30 Jan 2003 20:14:23 -0000
@@ -44,6 +44,7 @@
; for no alternate graphic.
; tech_req = required advance, names from techs.ruleset, or special:
; "None" => available from start; "Never" => never available
+; impr_req = required city improvement, names from buildings.ruleset
; obsolete_by = can be upgraded to and made obsolete by another unit by name
; move_type = "Land" or "Sea" or "Air" or "Heli"
; transport_cap = Number of units (ground, or air/missiles, depending on flags)
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.132
diff -u -r1.132 ruleset.c
--- server/ruleset.c 30 Jan 2003 19:26:08 -0000 1.132
+++ server/ruleset.c 30 Jan 2003 20:14:23 -0000
@@ -651,7 +651,11 @@
/* main stats: */
unit_type_iterate(i) {
u = &unit_types[i];
-
+
+ u->impr_requirement = find_improvement_by_name(
+ secfile_lookup_str_default(file, "None",
+ "%s.impr_req", sec[i]));
+
sval = secfile_lookup_str(file, "%s.move_type", sec[i]);
ival = unit_move_type_from_str(sval);
if (ival==0) {
@@ -2418,6 +2422,7 @@
packet.defense_strength = u->defense_strength;
packet.move_rate = u->move_rate;
packet.tech_requirement = u->tech_requirement;
+ packet.impr_requirement = u->impr_requirement;
packet.vision_range = u->vision_range;
packet.transport_capacity = u->transport_capacity;
packet.hp = u->hp;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2930) building requirements for units v2,
Per I. Mathisen via RT <=
|
|