[freeciv-ai] (PR#12453) Great Library and AI
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12453 >
I think that the AI should do the same as most players do after building
Great Library - set maximum tax rates, no science.
AI doesn't need any research if there are still techs which can be given
to it for free. I implemented it through the ai_wants_no_science()
function. The calculations are done only once per turn, so the patch
doesn't make AI slower.
See attached patch
--
mateusz
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.53
diff -u -r1.53 aidata.c
--- ai/aidata.c 5 Mar 2005 13:37:04 -0000 1.53
+++ ai/aidata.c 6 Mar 2005 13:31:13 -0000
@@ -116,6 +116,46 @@
}
/**************************************************************************
+ Check if the player still takes advantage of EFT_TECH_PARASITE.
+ Research is useless if there are still techs which may be given to the
+ player for free.
+**************************************************************************/
+static bool player_has_really_useful_tech_parasite(struct player* pplayer)
+{
+ int players_needed = get_player_bonus(pplayer, EFT_TECH_PARASITE);
+
+ if (players_needed == 0) {
+ return FALSE;
+ }
+
+ tech_type_iterate(tech) {
+ int players_having;
+
+ if (get_invention(pplayer, tech) == TECH_KNOWN
+ || !tech_is_available(pplayer, tech)) {
+ continue;
+ }
+
+ players_having = 0;
+
+ players_iterate(aplayer) {
+ if (aplayer == pplayer || !aplayer->is_alive) {
+ continue;
+ }
+
+ if (get_invention(aplayer, tech) == TECH_KNOWN ||
+ aplayer->research.researching == tech) {
+ players_having++;
+ if (players_having >= players_needed) {
+ return TRUE;
+ }
+ }
+ } players_iterate_end;
+ } tech_type_iterate_end;
+ return FALSE;
+}
+
+/**************************************************************************
Analyze rulesets. Must be run after rulesets after loaded, unlike
_init, which must be run before savegames are loaded, which is usually
before rulesets.
@@ -409,6 +449,14 @@
*punit->ai.cur_pos = punit->tile;
} unit_list_iterate_end;
} players_iterate_end;
+
+ /* Research want */
+ if (is_future_tech(pplayer->research.researching) ||
+ player_has_really_useful_tech_parasite(pplayer)) {
+ ai->wants_no_science = TRUE;
+ } else {
+ ai->wants_no_science = FALSE;
+ }
}
/**************************************************************************
@@ -494,4 +542,5 @@
ai->diplomacy.player_intel[i].asked_about_ceasefire = 0;
ai->diplomacy.player_intel[i].warned_about_space = 0;
}
+ ai->wants_no_science = FALSE;
}
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.23
diff -u -r1.23 aidata.h
--- ai/aidata.h 2 Mar 2005 10:43:57 -0000 1.23
+++ ai/aidata.h 6 Mar 2005 13:31:25 -0000
@@ -142,6 +142,9 @@
} govt;
int revolution; /* The best gov of the now available */
} goal;
+
+ /* If the ai doesn't want/need any research */
+ bool wants_no_science;
};
void ai_data_init(struct player *pplayer);
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.137
diff -u -r1.137 aitools.c
--- ai/aitools.c 2 Mar 2005 10:43:57 -0000 1.137
+++ ai/aitools.c 6 Mar 2005 13:31:25 -0000
@@ -792,5 +792,5 @@
**************************************************************************/
bool ai_wants_no_science(struct player *pplayer)
{
- return is_future_tech(pplayer->research.researching);
+ return ai_data_get(pplayer)->wants_no_science;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freeciv-ai] (PR#12453) Great Library and AI,
Mateusz Stefek <=
|
|