This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Fire.py
executable file
·64 lines (52 loc) · 2.45 KB
/
Fire.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This file is distributed under the terms of the GNU General Public license.
# Copyright (C) 1999 Aloril (See the file COPYING for details).
import server
from atlas import Operation, Entity, Oplist
from world.utils import Ticks
class Fire(server.Thing):
"""fire to burn things up"""
tick_interval = 30
def __init__(self, cpp):
Ticks.init_ticks(self, self.tick_interval)
if self.parent:
print('initial burn')
self.send_world(Operation("consume", Entity(consume_type='fire'), to=self.parent))
else:
print('no parent')
def tick_operation(self, op):
res = Oplist()
if Ticks.verify_tick(self, op, res, self.tick_interval):
status_prop = self.props.status
if status_prop is not None:
if self.parent:
print("Flame eating into parent")
# We should send an Consume op to our parent.
# A 'fire' consume op should be ignored by most entities except those that are flammable.
res += Operation("consume", Entity(consume_type='fire'), to=self.parent)
# Reduce status of fire
res += Operation("set", Entity({"status!subtract": 0.2}), to=self)
else:
print("Fire entity without status props.")
return server.OPERATION_BLOCKED, res
return server.OPERATION_IGNORED
def nourish_operation(self, op):
print("Flame is nourished")
if not self.has_prop_float('status'):
print("Fire entity without status prop")
return server.OPERATION_BLOCKED
status_prop = self.props.status
if len(op) > 0:
arg = op[0]
if arg.consume_type == "fire":
new_status_prop = min(1, status_prop + 0.3)
return server.OPERATION_BLOCKED, Operation("set", Entity(status=new_status_prop), to=self)
return server.OPERATION_BLOCKED
# CHEAT! make it more realistic (like spreading to things that burn near)
def extinguish_operation(self, op):
"""If somebody tries to extinguish us, change status lower"""
status_prop = self.props.status
if status_prop is not None:
return server.OPERATION_HANDLED, Operation("set", Entity(self.id, {"status!subtract": 0.25}), to=self)
else:
print("Fire entity without status prop")
return server.OPERATION_HANDLED