home · contact · privacy
Server/py: Extend command_makeworld().
[plomrogue] / plomrogue-server.py
index 94925ed2bf0f4886787f35e5fd373a010050d08e..3d4d0bdd0d411fb9f5f7dde87a3353b6d3f4b7a9 100755 (executable)
@@ -361,15 +361,38 @@ def command_seedmap(seed_string):
 
 def command_makeworld(seed_string):
     # DUMMY.
-    setter(None, "SEED_MAP", 0, 4294967295)(seed_string)
     setter(None, "SEED_RANDOMNESS", 0, 4294967295)(seed_string)
-    # TODO: Test for existence of player thing and 'wait' thing action?
+    player_will_be_generated = False
+    for ThingType in world_db["ThingTypes"]:
+        if 0 == ThingType:
+            if 0 < world_db["ThingTypes"][ThingType]["TT_START_NUMBER"]:
+                player_will_be_generated = True
+            break
+    if not player_will_be_generated:
+        print("Ignoring beyond SEED_MAP: " +
+              "No player type with start number >0 defined.")
+        return
+    wait_action = False
+    for ThingAction in world_db["ThingActions"]:
+        if "wait" == world_db["ThingActions"][ThingAction]["TA_NAME"]:
+            wait_action = True
+    if not wait_action:
+        print("Ignoring beyond SEED_MAP: " +
+              "No thing action with name 'wait' defined.")
+        return
+    setter(None, "SEED_MAP", 0, 4294967295)(seed_string)
+    world_db["Things"] = {}
+    remake_map()
+    world_db["WORLD_ACTIVE"] = 1
+    world_db["TURN"] = 1
+    # TODO: Generate things (player first, with updated memory)
+    atomic_write(io_db["path_out"], "NEW_WORLD\n", do_append=True)
 
 
 def command_maplength(maplength_string):
     # DUMMY.
     set_world_inactive()
-    # TODO: remove map
+    # TODO: remove map (is this necessary? no memory management trouble …)
     world_db["Things"] = {}
     setter(None, "MAP_LENGTH", 1, 256)(maplength_string)
 
@@ -378,8 +401,11 @@ def command_worldactive(worldactive_string):
     # DUMMY.
     val = integer_test(worldactive_string, 0, 1)
     if val:
-        if 0 != world_db["WORLD_ACTIVE"] and 0 == val:
-            set_world_inactive()
+        if 0 != world_db["WORLD_ACTIVE"]:
+            if 0 == val:
+                set_world_inactive()
+            else:
+                print("World already active.")
         elif 0 == world_db["WORLD_ACTIVE"]:
             wait_exists = False
             for ThingAction in world_db["ThingActions"]: