[Freeciv-Dev] Re: (PR#6992) Barbarian bug
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6992 >
On Sun, Nov 30, 2003 at 05:55:42AM -0800, Per I. Mathisen wrote:
>
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=6992 >
>
> On Sun, 30 Nov 2003, Raimar Falke wrote:
> > > The barb codereally needs a cleaning up. For now, I have made a braindead
> > > patch for S1_14 which should recover completely when this bug arises.
> > > Attached. I suggest it is committed before 1.14.1 is released.
> >
> > Any idea what is causing this? Is this problem also in CVS HEAD?
>
> The barb code has not been changed in CVS, except some cosmetic cleanups
> by me. I have no idea what is causing this.
Attached a new version of my kludge for observing the game.
New:
Check that max-players isn't exceeded.
Thomas
--
Thomas Strub *** eMail ue80@xxxxxxxxxxxxxxxxxxxxx
jb: people are stupid, they don't want to learn.
? dead-player3.diff
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.246.2.4
diff -u -r1.246.2.4 plrhand.c
--- server/plrhand.c 2003/11/15 11:21:50 1.246.2.4
+++ server/plrhand.c 2003/11/30 18:13:38
@@ -1643,6 +1643,81 @@
return cplayer;
}
+/**********************************************************************
+This function creates a dead player after the game has started.
+ - Thomas Strub
+***********************************************************************/
+struct player *dead_player(char *name)
+{
+ int *nations_used, i, num_nations_avail=game.playable_nation_count, pick;
+ int newplayer = game.nplayers;
+ struct player *cplayer = &game.players[newplayer];
+
+ nations_used = fc_calloc(game.playable_nation_count,sizeof(int));
+
+ /* make a new player */
+
+ server_player_init(cplayer, TRUE);
+
+ /* select a nation for the dead player. */
+
+ for(i=0; i<game.playable_nation_count;i++){
+ nations_used[i]=i;
+ }
+
+ players_iterate(other_player) {
+ if (other_player->nation < game.playable_nation_count) {
+ nations_used[other_player->nation] = -1;
+ num_nations_avail--;
+ }
+ } players_iterate_end;
+
+ pick = myrand(num_nations_avail);
+
+ for(i=0; i<game.playable_nation_count; i++){
+ if(nations_used[i] != -1)
+ pick--;
+ if(pick < 0) break;
+ }
+
+ cplayer->nation = nations_used[i];
+ free(nations_used);
+ nations_used = NULL;
+
+ /* Name the new player name */
+
+ sz_strlcpy(cplayer->name, name);
+ sz_strlcpy(cplayer->username, name);
+
+ cplayer->is_connected = FALSE;
+ cplayer->capital = TRUE;
+
+ cplayer->turn_done = TRUE; /* Have other things to think about - paralysis*/
+ cplayer->embassy = 0; /* no embassys */
+
+ /* Create the dead under human control */
+
+ cplayer->ai.control = FALSE;
+
+ /* The player is dead */
+
+ cplayer->is_alive = FALSE;
+ map_know_and_see_all(cplayer);
+
+ /* increase the number of players */
+
+ game.nplayers++;
+ game.max_players = game.nplayers;
+
+ /* So that clients get the correct game.nplayers: */
+ send_game_info(NULL);
+
+ /* Sending the other players the new player */
+ send_player_info(cplayer, NULL);
+
+ return cplayer;
+}
+
/**********************************************************************
civil_war_triggered:
* The capture of a capital is not a sure fire way to throw
Index: server/plrhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.h,v
retrieving revision 1.50
diff -u -r1.50 plrhand.h
--- server/plrhand.h 2002/10/09 20:54:20 1.50
+++ server/plrhand.h 2003/11/30 18:13:38
@@ -102,4 +102,5 @@
enum plr_info_level player_info_level(struct player *plr,
struct player *receiver);
+struct player *dead_player(char *arg);
#endif /* FC__PLRHAND_H */
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.256.2.3
diff -u -r1.256.2.3 stdinhand.c
--- server/stdinhand.c 2003/03/17 16:20:56 1.256.2.3
+++ server/stdinhand.c 2003/11/30 18:13:39
@@ -956,6 +956,7 @@
CMD_METASERVER,
CMD_AITOGGLE,
CMD_CREATE,
+ CMD_DEAD,
CMD_EASY,
CMD_NORMAL,
CMD_HARD,
@@ -1131,6 +1132,13 @@
N_("The 'create' command is only available before the game has "
"been started.")
},
+ {"dead", ALLOW_CTRL,
+ /* TRANS: translate text between <> only */
+ N_("dead <player-name>"),
+ N_("Create a dead \"player\" with a given name."),
+ N_("The 'dead' command is only working after the game has "
+ "been started.")
+ },
{"easy", ALLOW_CTRL,
/* TRANS: translate text between <> only */
N_("easy\n"
@@ -1788,6 +1796,70 @@
set_ai_level_directer(pplayer, game.skill_level);
}
+/**************************************************************************
+...
+**************************************************************************/
+static void create_dead(struct connection *caller, char *arg)
+{
+ struct player *pplayer;
+ PlayerNameStatus PNameStatus;
+
+ if (game.nplayers >= MAX_NUM_PLAYERS + 1)
+ {
+ cmd_reply(CMD_DEAD, caller, C_SYNTAX, _("Max number of players
exceeded."));
+ return;
+ }
+
+ if ((PNameStatus = test_player_name(arg)) == PNameEmpty)
+ {
+ cmd_reply(CMD_DEAD, caller, C_SYNTAX, _("Can't use an empty name."));
+ return;
+ }
+
+ if (PNameStatus == PNameTooLong)
+ {
+ cmd_reply(CMD_DEAD, caller, C_SYNTAX,
+ _("That name exceeds the maximum of %d chars."), MAX_LEN_NAME-1);
+ return;
+ }
+
+ if ((find_player_by_user(arg)))
+ {
+ cmd_reply(CMD_DEAD, caller, C_BOUNCE,
+ _("A connection with that name already exists."));
+ return;
+ }
+
+ if ((pplayer=find_player_by_name(arg)))
+ {
+ cmd_reply(CMD_DEAD, caller, C_BOUNCE,
+ _("A player already exists by that name."));
+ return;
+ }
+
+ /* This creates the dead player after the game has started */
+ if (!(game.is_new_game && (server_state==PRE_GAME_STATE ||
+ server_state==SELECT_RACES_STATE)))
+ {
+ pplayer = dead_player(arg);
+ } else {
+ /* no idea how to create a dead player before starting the game */
+ }
+
+ if (!pplayer)
+ {
+ cmd_reply(CMD_DEAD, caller, C_FAIL,
+ _("Error creating new dead player: %s."), arg);
+ return;
+ }
+
+ cmd_reply(CMD_DEAD, caller, C_OK,
+ _("%s as new dead player created."), pplayer->name);
+
+
+ freelog(LOG_DEBUG, "create dead player: %s", arg);
+ return;
+}
/**************************************************************************
...
@@ -3186,6 +3258,9 @@
break;
case CMD_CREATE:
create_ai_player(caller,arg);
+ break;
+ case CMD_DEAD:
+ create_dead(caller,arg);
break;
case CMD_EASY:
set_ai_level(caller, arg, 3);
|
|