[Freeciv-Dev] (PR#3745) Diplomacy patch part 3
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#3745) Diplomacy patch part 3 |
From: |
"Per I. Mathisen" <per@xxxxxxxxxxx> |
Date: |
Fri, 18 Apr 2003 04:58:17 -0700 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
This patch backports one new function from the AI diplomacy patch,
player_is_dangerous(), and optimizes the generation of the data this
function and the AI diplomacy patch uses for checking if other players are
allied or at war with players that we are allied to or allied to a player
that we are at war with. This new function is used in assess_danger() and
in aidata calculations.
Please look at and commit this and part 2 as soon as possible, so that I
can move forward on the next parts.
- Per
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.139
diff -u -r1.139 advmilitary.c
--- ai/advmilitary.c 2 Mar 2003 21:17:42 -0000 1.139
+++ ai/advmilitary.c 18 Apr 2003 11:51:12 -0000
@@ -439,9 +439,7 @@
int move_rate, dist, vulnerability;
bool igwall;
- if (!pplayers_at_war(city_owner(pcity), aplayer)) {
- /* Ignore players we are not at war with. This is not optimal,
- but will have to do until we have working diplomacy. */
+ if (!player_is_dangerous(city_owner(pcity), aplayer)) {
continue;
}
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.11
diff -u -r1.11 aidata.c
--- ai/aidata.c 4 Apr 2003 15:47:45 -0000 1.11
+++ ai/aidata.c 18 Apr 2003 11:51:12 -0000
@@ -72,8 +72,9 @@
ai->threats.sea = FALSE;
players_iterate(aplayer) {
- /* allies and ourselves we trust, we don't trust peace treaties that much
*/
- if (pplayers_allied(pplayer, aplayer)) continue;
+ if (!player_is_dangerous(pplayer, aplayer)) {
+ continue;
+ }
/* The idea is that if there aren't any hostile cities on
* our continent, the danger of land attacks is not big
@@ -194,6 +195,45 @@
ai->stats.workers[(int)map_get_continent(punit->x, punit->y)]++;
}
} unit_list_iterate_end;
+
+ /* Diplomacy */
+
+ /* Question: What can we accept as the reputation of a player before
+ * we start taking action to prevent us from being suckered?
+ * Answer: Very little. */
+ ai->diplomacy.acceptable_reputation =
+ GAME_DEFAULT_REPUTATION -
+ GAME_DEFAULT_REPUTATION / 4;
+
+ /* Set per-player variables. We must set all players, since players
+ * can be created during a turn, and we don't want those to have
+ * invalid values. */
+ for (i = 0; i < MAX_NUM_PLAYERS; i++) {
+ struct player *aplayer = get_player(i);
+
+ ai->diplomacy.other[i].is_allied_with_enemy = FALSE;
+ ai->diplomacy.other[i].at_war_with_ally = FALSE;
+ ai->diplomacy.other[i].is_allied_with_ally = FALSE;
+
+ players_iterate(check_pl) {
+ if (check_pl == pplayer || check_pl == aplayer
+ || !check_pl->is_alive) {
+ continue;
+ }
+ if (pplayers_allied(aplayer, check_pl)
+ && pplayers_at_war(pplayer, check_pl)) {
+ ai->diplomacy.other[i].is_allied_with_enemy = TRUE;
+ }
+ if (pplayers_allied(pplayer, check_pl)
+ && pplayers_at_war(aplayer, check_pl)) {
+ ai->diplomacy.other[i].at_war_with_ally = TRUE;
+ }
+ if (pplayers_allied(aplayer, check_pl)
+ && pplayers_allied(pplayer, check_pl)) {
+ ai->diplomacy.other[i].is_allied_with_ally = TRUE;
+ }
+ } players_iterate_end;
+ }
/*
* Priorities. NEVER set these to zero! Weight values are usually
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.5
diff -u -r1.5 aidata.h
--- ai/aidata.h 2 Jan 2003 11:59:29 -0000 1.5
+++ ai/aidata.h 18 Apr 2003 11:51:12 -0000
@@ -24,7 +24,19 @@
* start of every turn.
*/
+struct ai_diplomacy {
+ bool is_allied_with_enemy;
+ bool at_war_with_ally;
+ bool is_allied_with_ally;
+};
+
struct ai_data {
+ /* AI diplomacy and opinions on other players */
+ struct {
+ int acceptable_reputation;
+ struct ai_diplomacy other[MAX_NUM_PLAYERS];
+ } diplomacy;
+
/* Long-term threats, not to be confused with short-term danger */
struct {
bool invasions; /* check if we need to consider invasions */
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.81
diff -u -r1.81 aitools.c
--- ai/aitools.c 27 Feb 2003 22:14:37 -0000 1.81
+++ ai/aitools.c 18 Apr 2003 11:51:12 -0000
@@ -71,6 +71,26 @@
return amortize(value, delay + build_time);
}
+/**********************************************************************
+ There are some signs that a player might be dangerous: We are at
+ war with him, he has lousy reputation, he has done lots of ignoble
+ things to us, or he is an ally of one of our enemies (a ticking
+ bomb to be sure).
+***********************************************************************/
+bool player_is_dangerous(struct player *pplayer, struct player *aplayer)
+{
+ struct ai_data *ai = ai_data_get(pplayer);
+ struct ai_diplomacy *adip = &ai->diplomacy.other[aplayer->player_no];
+
+ if (pplayers_at_war(pplayer, aplayer)
+ || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel
+ || ai->diplomacy.acceptable_reputation > aplayer->reputation
+ || adip->is_allied_with_enemy) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
/**************************************************************************
Create a virtual unit to use in build want estimation. pcity can be
NULL.
Index: ai/aitools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v
retrieving revision 1.35
diff -u -r1.35 aitools.h
--- ai/aitools.h 13 Jan 2003 23:27:03 -0000 1.35
+++ ai/aitools.h 18 Apr 2003 11:51:12 -0000
@@ -67,4 +67,6 @@
int ai_evaluate_government(struct player *pplayer, struct government *g);
bool ai_wants_no_science(struct player *pplayer);
+bool player_is_dangerous(struct player *pplayer, struct player *aplayer);
+
#endif /* FC__AITOOLS_H */
- [Freeciv-Dev] (PR#3745) Diplomacy patch part 3,
Per I. Mathisen <=
|
|