Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13723) barbarian creation starts invalid revolution
Home

[Freeciv-Dev] (PR#13723) barbarian creation starts invalid revolution

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13723) barbarian creation starts invalid revolution
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 20 Aug 2005 18:41:11 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13723 >

(gdb) bt
#0  get_government_name (gov=0x0) at government.c:131
#1  0x0807c50d in finish_revolution (pplayer=0x826cefc) at plrhand.c:258
#2  0x0807caf3 in update_revolution (pplayer=0x826cefc) at plrhand.c:412
#3  0x0804fba4 in begin_phase (is_new_phase=true) at srv_main.c:561
#4  0x080519da in main_loop () at srv_main.c:1588
#5  0x080521ff in srv_loop () at srv_main.c:1898
#6  0x08051d0d in srv_main () at srv_main.c:1718
#7  0x0804ad14 in main (argc=1, argv=0xbfaf5854) at civserver.c:242
(gdb) select 1
(gdb) p government
$1 = (struct government *) 0x0
(gdb) p pplayer->name
$1 = "Theodoric", '\0' <repeats 22 times>

All the revolution code assumes that when a player is in revolution the 
target_government is valid.  There is a check for anarchy which is the 
"no-target-set" value.

This is sort of a remnant from when this was an integer rather than a 
pointer value.  In those days instead of NULL we'd have 0 and instead of 
the above crash the government would erronously be set to whatever the 
first government is.

When barbarians are created their government is set to anarchy. 
revolution_finishes is set to 1 ( *** this is also a bug, it should be 0 
*** ).  The revolution finishes the next turn and *bam*, the server crashes.

So what should happen here?  In the old code the barbarian would go into 
  government 0 (probably despotism) ( *** this bug, if it is a bug, 
probably affects 2.0 *** ).  But now it's a crash.  We should set the 
target government when the barbarian is created: either to 
government_when_anarchy to keep the barbarian in anarchy, or to some 
other value chosen by the AI.

The attached patch fixes the crash in the simplest way.  This should 
probably apply to 2.0 also.  Note this does change the behavior since 
the revolution now won't end until the AI sets a government.  But maybe 
that's the intent.

Per, please comment.

-jason

Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.99
diff -p -u -r1.99 barbarian.c
--- server/barbarian.c  18 Aug 2005 06:44:28 -0000      1.99
+++ server/barbarian.c  21 Aug 2005 01:27:23 -0000
@@ -154,7 +154,8 @@ static struct player *create_barbarian_p
   sz_strlcpy(barbarians->username, ANON_USER_NAME);
   barbarians->is_connected = FALSE;
   barbarians->government = game.government_when_anarchy;
-  barbarians->revolution_finishes = 1;
+  barbarians->target_government = game.government_when_anarchy;
+  barbarians->revolution_finishes = 0;
   barbarians->capital = FALSE;
   barbarians->economic.gold = 100;
 
set mapseed 992600984
set gameseed 1124583501
set aifill 5
set timeout -1
start

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13723) barbarian creation starts invalid revolution, Jason Short <=