home · contact · privacy
b8cab9740abd995b4e8938c61644b079c06a45ca
[plomrogue] / server / decrement_lifepoints.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 decrement_lifepoints(t):
7     """Decrement t's lifepoints by 1; if to zero, corpse it, drop its stuff.
8
9     If t is the player avatar, only blank its fovmap, so that the client may
10     still display memory data. On non-player things, erase fovmap and memory.
11     On kill, return dying type's TT_LIFEPOINTS, else 0.
12     """
13     from server.config.world_data import world_db
14     from server.io import log
15     t["T_LIFEPOINTS"] -= 1
16     if 0 == t["T_LIFEPOINTS"]:
17         live_tid = t["T_TYPE"]
18         for tid in t["T_CARRIES"]:
19             t["T_CARRIES"].remove(tid)
20             world_db["Things"][tid]["T_POSY"] = t["T_POSY"]
21             world_db["Things"][tid]["T_POSX"] = t["T_POSX"]
22             world_db["Things"][tid]["carried"] = False
23         t["T_TYPE"] = world_db["ThingTypes"][t["T_TYPE"]]["TT_CORPSE_ID"]
24         if world_db["Things"][0] == t:
25             t["fovmap"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2))
26             log("You die.")
27             log("See README on how to start over.")
28         else:
29             t["fovmap"] = False
30             t["T_MEMMAP"] = False
31             t["T_MEMDEPTHMAP"] = False
32             t["T_MEMTHING"] = []
33         return world_db["ThingTypes"][live_tid]["TT_LIFEPOINTS"]
34     return 0