home · contact · privacy
Server: Add WORLD_ACTIVE checks.
[plomrogue] / server / update_map_memory.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 def update_map_memory(t, age_map=True):
7     """Update t's T_MEMMAP with what's in its FOV now,age its T_MEMMEPTHMAP."""
8     from server.utils import c_pointer_to_bytearray, libpr
9     from server.config.world_data import world_db
10
11     def age_some_memdepthmap_on_nonfov_cells():
12         # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so:
13         # ord_v = ord("v")
14         # ord_0 = ord("0")
15         # ord_9 = ord("9")
16         # for pos in [pos for pos in range(world_db["MAP_LENGTH"] ** 2)
17         #             if not ord_v == t["fovmap"][pos]
18         #             if ord_0 <= t["T_MEMDEPTHMAP"][pos]
19         #             if ord_9 > t["T_MEMDEPTHMAP"][pos]
20         #             if not rand.next() % (2 **
21         #                                   (t["T_MEMDEPTHMAP"][pos] - 48))]:
22         #     t["T_MEMDEPTHMAP"][pos] += 1
23         memdepthmap = c_pointer_to_bytearray(t["T_MEMDEPTHMAP"])
24         fovmap = c_pointer_to_bytearray(t["fovmap"])
25         libpr.age_some_memdepthmap_on_nonfov_cells(memdepthmap, fovmap)
26
27     def update_mem_and_memdepthmap_via_fovmap():
28         # OUTSOURCED FOR PERFORMANCE REASONS TO libplomrogue.so:
29         # for pos in [pos for pos in range(world_db["MAP_LENGTH"] ** 2)
30         #             if ord_v == t["fovmap"][pos]]:
31         #     t["T_MEMDEPTHMAP"][pos] = ord_0
32         #     t["T_MEMMAP"][pos] = world_db["MAP"][pos]
33         memdepthmap = c_pointer_to_bytearray(t["T_MEMDEPTHMAP"])
34         memmap = c_pointer_to_bytearray(t["T_MEMMAP"])
35         fovmap = c_pointer_to_bytearray(t["fovmap"])
36         map = c_pointer_to_bytearray(world_db["MAP"])
37         libpr.update_mem_and_memdepthmap_via_fovmap(map, fovmap, memdepthmap,
38                                                     memmap)
39
40     if not t["T_MEMMAP"]:
41         t["T_MEMMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
42     if not t["T_MEMDEPTHMAP"]:
43         t["T_MEMDEPTHMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
44     update_mem_and_memdepthmap_via_fovmap()
45     if age_map:
46         age_some_memdepthmap_on_nonfov_cells()
47     ord_v = ord("v")
48     t["T_MEMTHING"] = [mt for mt in t["T_MEMTHING"]
49                        if ord_v != t["fovmap"][(mt[1] * world_db["MAP_LENGTH"])
50                                                + mt[2]]]
51     maplength = world_db["MAP_LENGTH"]
52     [t["T_MEMTHING"].append((world_db["Things"][id]["T_TYPE"],
53                              world_db["Things"][id]["T_POSY"],
54                              world_db["Things"][id]["T_POSX"]))
55      for id in world_db["Things"]
56      if not world_db["Things"][id]["carried"]
57      if not world_db["ThingTypes"][world_db["Things"][id]["T_TYPE"]]
58                                                               ["TT_LIFEPOINTS"]
59      if ord_v == t["fovmap"][world_db["Things"][id]["pos"]]]