Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] (PR#2629) create dead
Home

[Freeciv-Dev] (PR#2629) create dead

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2629) create dead
From: "ue80@xxxxxxxxxxxxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 22 Dec 2002 07:34:47 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Hi,

this is a repost of my create dead patch.

As long there is no easy way to spectate the game its a solution to do
that.

Thomas
-- 
Thomas Strub  ***  eMail ue80@xxxxxxxxxxxxxxxxxxxxx
Nur weil das Aufzeichnen, Kopieren und Schnüffeln bei elektronischem 
Datenverkehr leichter als bei der klassischen Post ist, darf man es nicht
einfach tun.

? dead-player1-cvs20021222.diff
? dead-player1.diff
? dead-player2.diff
? common/aicore/.deps
? common/aicore/Makefile
? common/aicore/Makefile.in
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.253
diff -u -r1.253 plrhand.c
--- server/plrhand.c    2002/12/18 17:36:20     1.253
+++ server/plrhand.c    2002/12/22 15:26:45
@@ -1648,6 +1648,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.51
diff -u -r1.51 plrhand.h
--- server/plrhand.h    2002/12/18 17:36:20     1.51
+++ server/plrhand.h    2002/12/22 15:26:45
@@ -96,4 +96,5 @@
 bool civil_war_triggered(struct player *pplayer);
 void civil_war(struct player *pplayer);
 
+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.269
diff -u -r1.269 stdinhand.c
--- server/stdinhand.c  2002/12/21 09:45:42     1.269
+++ server/stdinhand.c  2002/12/22 15:26:47
@@ -961,6 +961,7 @@
   CMD_METASERVER,
   CMD_AITOGGLE,
   CMD_CREATE,
+  CMD_DEAD,
   CMD_EASY,
   CMD_NORMAL,
   CMD_HARD,
@@ -1136,6 +1137,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"
@@ -1794,7 +1802,65 @@
   set_ai_level_directer(pplayer, game.skill_level);
 }
 
+/**************************************************************************
+...
+**************************************************************************/
+static void create_dead(struct connection *caller, char *arg)
+{
+  struct player *pplayer;
+  PlayerNameStatus PNameStatus;
+       
+  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;
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
@@ -3201,6 +3267,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);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2629) create dead, ue80@xxxxxxxxxxxxxxxxxxxxx via RT <=