[Freeciv-Dev] patch: Building dependencies
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I have begun looking at generalising the buildings ruleset again. Here is
a small patch that adds dependencies to other buildings, both to city
improvements and to world wonders. I have not tested the spacerace
change; can somebody test this for me or send me a spacerace savegame?
I also put in one typo fix :)
Next I will try to add generalised terrain dependencies into the ruleset
(port, hydro dam, etc).
Yours,
Per
diff -u2r -X ../diff-ignore ../freeciv-orig/client/packhand.c
./client/packhand.c
--- ../freeciv-orig/client/packhand.c Tue Jan 4 00:03:13 2000
+++ ./client/packhand.c Mon Jan 3 23:24:39 2000
@@ -1169,4 +1169,5 @@
b->obsolete_by = p->obsolete_by;
b->variant = p->variant;
+ b->requires = p->requires;
free(b->helptext);
diff -u2r -X ../diff-ignore ../freeciv-orig/common/city.c ./common/city.c
--- ../freeciv-orig/common/city.c Tue Jan 4 00:03:13 2000
+++ ./common/city.c Tue Jan 4 00:26:28 2000
@@ -341,15 +341,7 @@
city_got_building(pcity, B_NUCLEAR)) && (id==B_POWER || id==B_HYDRO ||
id==B_NUCLEAR))
return 0;
- if (id==B_RESEARCH && !city_got_building(pcity, B_UNIVERSITY))
+ if (is_wonder(id) && get_improvement_type(id)->requires!=B_LAST &&
!city_got_building(pcity, get_improvement_type(id)->requires))
return 0;
- if (id==B_UNIVERSITY && !city_got_building(pcity, B_LIBRARY))
- return 0;
- if (id==B_STOCK && !city_got_building(pcity, B_BANK))
- return 0;
- if (id == B_SEWER && !city_got_building(pcity, B_AQUEDUCT))
- return 0;
- if (id==B_BANK && !city_got_building(pcity, B_MARKETPLACE))
- return 0;
- if (id==B_MFG && !city_got_building(pcity, B_FACTORY))
+ if (!is_wonder(id) && get_improvement_type(id)->requires!=B_LAST &&
!game.global_wonders[get_improvement_type(id)->requires])
return 0;
if ((id==B_HARBOUR || id==B_COASTAL || id == B_OFFSHORE || id == B_PORT) &&
!is_terrain_near_tile(pcity->x, pcity->y, T_OCEAN))
@@ -365,7 +357,4 @@
return 0;
if (id == B_SSTRUCTURAL || id == B_SCOMP || id == B_SMODULE) {
- if (!game.global_wonders[B_APOLLO]) {
- return 0;
- } else {
struct player *p=city_owner(pcity);
if (p->spaceship.state >= SSHIP_LAUNCHED)
@@ -377,5 +366,4 @@
if (id == B_SMODULE && p->spaceship.modules >= NUM_SS_MODULES)
return 0;
- }
}
if (is_wonder(id)) {
diff -u2r -X ../diff-ignore ../freeciv-orig/common/city.h ./common/city.h
--- ../freeciv-orig/common/city.h Tue Jan 4 00:03:13 2000
+++ ./common/city.h Mon Jan 3 14:39:38 2000
@@ -47,4 +47,5 @@
int obsolete_by;
int variant;
+ int requires;
char *helptext;
};
diff -u2r -X ../diff-ignore ../freeciv-orig/common/packets.c ./common/packets.c
--- ../freeciv-orig/common/packets.c Tue Jan 4 00:03:13 2000
+++ ./common/packets.c Mon Jan 3 23:25:12 2000
@@ -2356,4 +2356,5 @@
cptr=put_uint8(cptr, packet->obsolete_by);
cptr=put_uint8(cptr, packet->variant);
+ cptr=put_uint8(cptr, packet->requires);
cptr=put_string(cptr, packet->name);
@@ -2387,4 +2388,5 @@
iget_uint8(&iter, &packet->obsolete_by);
iget_uint8(&iter, &packet->variant);
+ iget_uint8(&iter, &packet->requires);
iget_string(&iter, packet->name, sizeof(packet->name));
diff -u2r -X ../diff-ignore ../freeciv-orig/common/packets.h ./common/packets.h
--- ../freeciv-orig/common/packets.h Mon Jan 3 13:47:29 2000
+++ ./common/packets.h Mon Jan 3 23:21:29 2000
@@ -540,4 +540,5 @@
int obsolete_by;
int variant;
+ int requires;
char *helptext; /* same as for packet_ruleset_unit, above */
};
diff -u2r -X ../diff-ignore ../freeciv-orig/data/default/buildings.ruleset
./data/default/buildings.ruleset
--- ../freeciv-orig/data/default/buildings.ruleset Tue Jan 4 00:03:13 2000
+++ ./data/default/buildings.ruleset Tue Jan 4 00:34:38 2000
@@ -37,4 +37,6 @@
; variant = controls hardwired effects options, unique to each
; building; 0 means default effect; see README.rulesets
+; requires = optional dependency on the presence of a specific
+; building in the city, or, if it is a wonder, in the world
; helptext = optional help text string; should escape all raw newlines
; so that xgettext parsing works
@@ -77,4 +79,5 @@
upkeep = 3
variant = 0
+requires = _("Marketplace")
helptext = _("\
Together with the Marketplace improvement, a Bank increases the\
@@ -454,4 +457,5 @@
upkeep = 3
variant = 0
+requires = _("University")
helptext = _("\
Together with a Library and a University, a Research Lab increases\
@@ -494,4 +498,5 @@
upkeep = 2
variant = 0
+requires = _("Aqueduct")
; auto-help
@@ -514,4 +519,5 @@
upkeep = 0
variant = 0
+requires = _("Apollo Program")
helptext = _("\
Space Components can be differentiated into Propulsion and Fuel\
@@ -531,4 +537,5 @@
upkeep = 0
variant = 0
+requires = _("Apollo Program")
helptext = _("\
Space Modules are the most expensive parts of spaceships. There\
@@ -557,4 +564,5 @@
upkeep = 0
variant = 0
+requires = _("Apollo Program")
helptext = _("\
Space Structurals form the base of your spaceship. All other\
@@ -574,4 +582,5 @@
upkeep = 4
variant = 0
+requires = _("Bank")
helptext = _("\
Together with a Marketplace and a Bank, a Stock Exchange boosts\
@@ -628,4 +637,5 @@
upkeep = 3
variant = 0
+requires = _("Library")
helptext = _("\
Together with a Library, a University increases the science\
@@ -771,4 +781,5 @@
upkeep = 0
variant = 0
+requires = _("Factory")
helptext = _("\
Works as if you had a Hydro Plant in every city. (This reduces\
diff -u2r -X ../diff-ignore ../freeciv-orig/server/citytools.c
./server/citytools.c
--- ../freeciv-orig/server/citytools.c Tue Jan 4 00:03:13 2000
+++ ./server/citytools.c Mon Jan 3 15:00:52 2000
@@ -450,5 +450,5 @@
/**************************************************************************
-corruption, corruption is halfed during love the XXX days.
+corruption, corruption is halved during love the XXX days.
**************************************************************************/
int city_corruption(struct city *pcity, int trade)
diff -u2r -X ../diff-ignore ../freeciv-orig/server/ruleset.c ./server/ruleset.c
--- ../freeciv-orig/server/ruleset.c Tue Jan 4 00:03:13 2000
+++ ./server/ruleset.c Mon Jan 3 23:47:30 2000
@@ -756,12 +756,26 @@
}
}
-
+
/**************************************************************************
-...
+ Converts the name of an improvement into its index number
+**************************************************************************/
+static int ruleset_find_building(char *building_name)
+{
+ struct improvement_type *b;
+ int i=0;
+ b = &improvement_types[i];
+ while ((strcmp(building_name,b->name) != 0) && (i != B_LAST )) {
+ b = &improvement_types[++i];
+ }
+ return i;
+}
+
+/**************************************************************************
+ Loads and interprets buildings.ruleset
**************************************************************************/
static void load_ruleset_buildings(char *ruleset_subdir)
{
struct section_file file;
- char *filename, *datafile_options;
+ char *filename, *datafile_options, *t;
char **sec;
int i, j, nval;
@@ -797,8 +811,21 @@
b->shield_upkeep = secfile_lookup_int(&file, "%s.upkeep", sec[i]);
b->variant = secfile_lookup_int(&file, "%s.variant", sec[i]);
-
+
b->helptext = lookup_helptext(&file, sec[i]);
}
+ /* Baby one more time ... 'cos we need all names read first */
+ for ( i=0; i<B_LAST; i++ ) {
+ b = &improvement_types[i];
+ t = secfile_lookup_str_default(&file, "none", "%s.requires", sec[i]);
+ b->requires = ruleset_find_building(t);
+ if (b->requires != B_LAST) {
+ if (0 == strcmp(t,"none")) {
+ freelog(LOG_FATAL, "Cannot find building %s required for %s in
ruleset\n", t, b->name);
+ exit(1);
+ }
+ }
+ }
+
/* Some more consistency checking: */
for( i=0; i<B_LAST; i++ ) {
@@ -1684,4 +1711,5 @@
packet.obsolete_by = b->obsolete_by;
packet.variant = b->variant;
+ packet.requires = b->requires;
packet.helptext = b->helptext; /* pointer assignment */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] patch: Building dependencies,
Per Inge Mathisen <=
|
|