Author: cazfi
Date: Sat Sep 19 08:48:37 2015
New Revision: 29929

URL: http://svn.gna.org/viewcvs/freeciv?rev=29929&view=rev
Log:
Allow empty "startunits" when "startcity" is enabled

See patch #5887

Modified:
    branches/S2_6/server/gamehand.c
    branches/S2_6/server/settings.c
    branches/S2_6/server/srv_main.c
    branches/S2_6/server/stdinhand.c

Modified: branches/S2_6/server/gamehand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/gamehand.c?rev=29929&r1=29928&r2=29929&view=diff
==============================================================================
--- branches/S2_6/server/gamehand.c     (original)
+++ branches/S2_6/server/gamehand.c     Sat Sep 19 08:48:37 2015
@@ -417,6 +417,7 @@
   struct tile *player_startpos[player_slot_count()];
   int placed_units[player_slot_count()];
   int players_to_place = player_count();
+  int sulen;
 
   randomize_base64url_string(server.game_identifier,
                              sizeof(server.game_identifier));
@@ -751,15 +752,18 @@
   startpos_list_destroy(targeted_list);
   startpos_list_destroy(flexible_list);
 
+  sulen = strlen(game.server.start_units);
 
   /* Loop over all players, creating their initial units... */
   players_iterate(pplayer) {
+    struct tile *ptile;
+
     /* We have to initialise the advisor and ai here as we could make contact
      * to other nations at this point. */
     adv_data_phase_init(pplayer, FALSE);
     CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, FALSE);
 
-    struct tile *ptile = player_startpos[player_index(pplayer)];
+    ptile = player_startpos[player_index(pplayer)];
 
     fc_assert_action(NULL != ptile, continue);
 
@@ -769,10 +773,14 @@
                   NULL);
     }
 
-    /* Place the first unit. */
-    if (place_starting_unit(ptile, pplayer,
-                            game.server.start_units[0]) != NULL) {
-      placed_units[player_index(pplayer)] = 1;
+    if (sulen > 0) {
+      /* Place the first unit. */
+      if (place_starting_unit(ptile, pplayer,
+                              game.server.start_units[0]) != NULL) {
+        placed_units[player_index(pplayer)] = 1;
+      } else {
+        placed_units[player_index(pplayer)] = 0;
+      }
     } else {
       placed_units[player_index(pplayer)] = 0;
     }
@@ -787,7 +795,7 @@
     fc_assert_action(NULL != ptile, continue);
 
     /* Place global start units */
-    for (i = 1; i < strlen(game.server.start_units); i++) {
+    for (i = 1; i < sulen; i++) {
       struct tile *rand_tile = find_dispersed_position(pplayer, ptile);
 
       /* Create the unit of an appropriate type. */
@@ -814,7 +822,7 @@
     adv_data_phase_done(pplayer);
     CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
 
-    fc_assert_msg(0 < placed_units[player_index(pplayer)],
+    fc_assert_msg(game.server.start_city || 0 < 
placed_units[player_index(pplayer)],
                   _("No units placed for %s!"), player_name(pplayer));
   } players_iterate_end;
 

Modified: branches/S2_6/server/settings.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/settings.c?rev=29929&r1=29928&r2=29929&view=diff
==============================================================================
--- branches/S2_6/server/settings.c     (original)
+++ branches/S2_6/server/settings.c     Sat Sep 19 08:48:37 2015
@@ -852,13 +852,6 @@
   int len = strlen(value), i;
   Unit_Class_id  first_role;
   bool firstnative = FALSE;
-
-  if (len == 0) {
-    settings_snprintf(reject_msg, reject_msg_len,
-                      _("Starting units string cannot be empty."));
-
-    return FALSE;
-  }
 
   /* We check each character individually to see if it's valid. */
   for (i = 0; i < len; i++) {

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=29929&r1=29928&r2=29929&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Sat Sep 19 08:48:37 2015
@@ -2814,8 +2814,13 @@
     struct unit_type *utype = NULL;
     int sucount = strlen(game.server.start_units);
 
-    for (i = 0; utype == NULL && i < sucount; i++) {
-      utype = crole_to_unit_type(game.server.start_units[i], NULL);
+    if (sucount > 0) {
+      for (i = 0; utype == NULL && i < sucount; i++) {
+        utype = crole_to_unit_type(game.server.start_units[i], NULL);
+      }
+    } else {
+      /* First unit the initial city might build. */
+      utype = get_role_unit(L_FIRSTBUILD, 0);
     }
     fc_assert(utype != NULL);
 

Modified: branches/S2_6/server/stdinhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/stdinhand.c?rev=29929&r1=29928&r2=29929&view=diff
==============================================================================
--- branches/S2_6/server/stdinhand.c    (original)
+++ branches/S2_6/server/stdinhand.c    Sat Sep 19 08:48:37 2015
@@ -5639,6 +5639,12 @@
                       _("Not enough nations for all players; game will "
                         "not start."));
       return FALSE;
+    } else if (strlen(game.server.start_units) == 0 && 
!game.server.start_city) {
+      start_cmd_reply(caller, notify,
+                      _("Neither 'startcity' nor 'startunits' setting give "
+                        "players anything to start game with; game will "
+                        "not start."));
+      return FALSE;
     } else if (check) {
       return TRUE;
     } else if (!caller) {


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to