[Freeciv-Dev] (PR#12660) RFC Proposed Jenner patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12660 >
Here is my first attempt at making a patch. It is based on the
CVS version (patched up through the March 17-18 diffs). It applies
to just one file - "server/settlers.c".
The purpose of this patch (as you may have deduced from its
name) is to make smallpox extinct. However, it is only a first step
and more code is probably needed to finally eliminate smallpox. And
for those who like smallpox games, they can set cityfactor to 99 and
(hopefully) be happy.
I have tested this patch with several server-only autogames and
have not seen any problems. In those autogames I used the default
settings listed in doc/HACKING except for these two stmts:
set cityfactor 6
set startunits cccx # adding an extra settler to exercise the code
I also tried some games with higher values for cityfactor
(including some with cityfactor 14 - the default value). Even then,
none of the AIs had come close to reaching the top of the tech tree
by the year 2000. I think that's good news for novice players.
IMO, the biggest question is whether this patch is effective
against smallpox used by human players. I don't know. I would love
to have tested it for that but I can't. That is because I still
don't have a working civclient. :-(
If this patch (or some later patch) *is* effective against human
smallpoxing, then some additional code will be needed to:
1) Allow an exception for building a settler in order to disband a
city. (Does the AI ever do that?)
2) Make civclient display a msg when a city or settler cannot be
built because of the limits imposed by this patch.
There are many other issues raised by this technique for
attacking smallpox. But it is probably premature to talk about them
until we find out if this approach is workable. I, for one, am
certainly looking forward to trying it.
Technical stuff:
I used Paul Chitescu's mkpatch script to create the patch file.
That file lists the target file as "settlers.c", not
"server/settlers.c". I tried changing it from the former to the
latter but when I did, the "patch" cmd didn't like it. So I changed
it back. I don't know why it wouldn't work.
I read the CodingStyle file and tried to make my code conform.
However, there are still some things I wasn't sure about. E.g. In
the patch, I added a new function, "player_has_max_cities". I
didn't know whether I should:
1) add a header for it in settlers.h
2) use "static" in its definition
Based on how other functions in settlers.c were coded I chose
"no" on 1) and "yes" on 2) . But, for future reference, I would
appreciate some advice (or a link to some advice) on these issues.
In this email I'm synthesizing the MIME headers by hand.
Consequently, I'm not certain that RT will recognize them as valid.
So I will include the text of this patch twice in this email - once
as a text attachment and once as a gzip'd attachment. If neither
version gets through, then I'll try something else.
Comments and constructive criticism welcome. I tried to place
this patch's code where it would save some CPU (e.g. no sense
wasting CPU to choose a location for a city which will not be
built). But since I'm unfamiliar with almost all of the freeciv
code, I may have overlooked better location for it. Please feel
free to suggest a better location or technique.
-Eddie
--- settlers.c.orig Wed Mar 16 12:32:21 2005
+++ settlers.c Fri Mar 25 22:52:59 2005
@@ -1023,6 +1023,27 @@
}
/**************************************************************************
+ Count player's cities. Compare to maximum allowed.
+**************************************************************************/
+static bool player_has_max_cities(struct player *pplayer)
+{
+ int city_count = 0;
+
+ /* Count the cities that this player has. */
+ city_list_iterate(pplayer->cities, pcity) {
+ city_count++;
+ } city_list_iterate_end;
+
+ /* If that count meets or exceeds this limit, then return TRUE. */
+ if (city_count >= game.cityfactor
+ + get_gov_pplayer(pplayer)->empire_size_mod) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**************************************************************************
Find some work for our settlers and/or workers.
**************************************************************************/
#define LOG_SETTLER LOG_DEBUG
@@ -1049,9 +1070,11 @@
int sanity = punit->id;
/* Check that the mission is still possible. If the tile has become
- * unavailable or the player has been autotoggled, call it off. */
+ * unavailable, the player has been autotoggled, or the player already
+ * has the maximum number of buildable cities, then call it off. */
if (!unit_owner(punit)->ai.control
- || !city_can_be_built_here(ptile, punit)) {
+ || !city_can_be_built_here(ptile, punit)
+ || player_has_max_cities) {
UNIT_LOG(LOG_SETTLER, punit, "city founding mission failed");
ai_unit_new_role(punit, AIUNIT_NONE, NULL);
set_unit_activity(punit, ACTIVITY_IDLE);
@@ -1436,6 +1459,9 @@
{
struct player *pplayer = city_owner(pcity);
struct unit *virtualunit;
+ int city_count = 0;
+ int settlers_in_existence_count = 0;
+ int settlers_being_built_count = 0;
Unit_Type_id unit_type = best_role_unit(pcity, F_CITIES);
if (unit_type == U_LAST) {
@@ -1443,6 +1469,33 @@
return;
}
+ /* Count the cities that this player has.
+ * Also count how many of those cities are building a settler. */
+ city_list_iterate(pplayer->cities, pcity) {
+ city_count++;
+ if (unit_type_flag(pcity->currently_building, F_CITIES)) {
+ settlers_being_built_count++;
+ }
+ } city_list_iterate_end;
+
+ /* Count the settlers that this player has. */
+ unit_list_iterate(pplayer->units, punit) {
+ if (unit_flag(punit, F_CITIES)) {
+ settlers_in_existence_count++;
+ }
+ } unit_list_iterate_end;
+
+ /* If the total of cities, potential cities (i.e. settlers), and
+ * potential settlers (i.e. settlers under construction), exceeds
+ * this limit then we don't want to build yet another settler
+ * (because we won't be able to use it to build a city). */
+ if (city_count + settlers_in_existence_count
+ + settlers_being_built_count >= game.cityfactor
+ + get_gov_pplayer(pplayer)->empire_size_mod) {
+ pcity->ai.founder_want = 0;
+ return;
+ }
+
/* Create a localized "virtual" unit to do operations with. */
virtualunit = create_unit_virtual(pplayer, pcity, unit_type, 0);
virtualunit->tile = pcity->tile;
proposed_jenner.patch.gz
Description: application/gzip
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12660) RFC Proposed Jenner patch,
(Eddie Anderson) <=
|
|