home · contact · privacy
TCE: Add basic worldconf, default to it.
[plomrogue] / server / worldstate_write_helpers.py
1 # This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
2 # or any later version. For details on its copyright, license, and warranties,
3 # see the file NOTICE in the root directory of the PlomRogue source package.
4
5
6 from server.config.world_data import world_db
7
8
9 def write_inventory():
10     inventory = ""
11     if [] == world_db["Things"][0]["T_CARRIES"]:
12         inventory = "(none)\n"
13     else:
14         for id in world_db["Things"][0]["T_CARRIES"]:
15             type_id = world_db["Things"][id]["T_TYPE"]
16             name = world_db["ThingTypes"][type_id]["TT_NAME"]
17             inventory = inventory + name + "\n"
18     inventory += "%\n"
19     return inventory
20
21 def write_map(map, length):
22     string = ""
23     for i in range(length):
24         line = map[i * length:(i * length) + length].decode()
25         string = string + line + "\n"
26     return string
27
28 def write_fov_map():
29     length = world_db["MAP_LENGTH"]
30     fov = bytearray(b' ' * (length ** 2))
31     ord_v = ord("v")
32     for pos in [pos for pos in range(length ** 2)
33                     if ord_v == world_db["Things"][0]["fovmap"][pos]]:
34         fov[pos] = world_db["MAP"][pos]
35     for id in [id for tid in reversed(sorted(list(world_db["ThingTypes"])))
36                   for id in world_db["Things"]
37                   if not world_db["Things"][id]["carried"]
38                   if world_db["Things"][id]["T_TYPE"] == tid
39                   if world_db["Things"][0]["fovmap"][
40                        world_db["Things"][id]["pos"]] == ord_v]:
41         type = world_db["Things"][id]["T_TYPE"]
42         c = ord(world_db["ThingTypes"][type]["TT_SYMBOL"])
43         fov[world_db["Things"][id]["pos"]] = c
44     return write_map(fov, length)
45
46 def write_mem_map():
47     length = world_db["MAP_LENGTH"]
48     mem = world_db["Things"][0]["T_MEMMAP"][:]
49     for mt in [mt for tid in reversed(sorted(list(world_db["ThingTypes"])))
50                   for mt in world_db["Things"][0]["T_MEMTHING"]
51                   if mt[0] == tid]:
52          c = world_db["ThingTypes"][mt[0]]["TT_SYMBOL"]
53          mem[(mt[1] * length) + mt[2]] = ord(c)
54     return write_map(mem, length)