home · contact · privacy
8ec4b354bc2707a80de03d2117d2e65a366bd58d
[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]["T_POSY"] * length
41                        + world_db["Things"][id]["T_POSX"]] == ord_v]:
42         type = world_db["Things"][id]["T_TYPE"]
43         c = ord(world_db["ThingTypes"][type]["TT_SYMBOL"])
44         fov[world_db["Things"][id]["T_POSY"] * length
45             + world_db["Things"][id]["T_POSX"]] = c
46     return write_map(fov, length)
47
48 def write_mem_map():
49     length = world_db["MAP_LENGTH"]
50     mem = world_db["Things"][0]["T_MEMMAP"][:]
51     for mt in [mt for tid in reversed(sorted(list(world_db["ThingTypes"])))
52                   for mt in world_db["Things"][0]["T_MEMTHING"]
53                   if mt[0] == tid]:
54          c = world_db["ThingTypes"][mt[0]]["TT_SYMBOL"]
55          mem[(mt[1] * length) + mt[2]] = ord(c)
56     return write_map(mem, length)