mirror of
https://github.com/worldforge/cyphesis
synced 2026-08-13 12:26:04 -04:00
Since not all entities have physical location, which is more and more true now that we have domains. Entities that are placed in non-physical domains don't have any location data. This also makes it easier to streamline the sending of properties, since we only need to send the properties that actually have changed. In addition, this helps with removing circular references, since the "m_parent" field no longer is a Ref.
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
# This file is distributed under the terms of the GNU General Public license.
|
|
# Copyright (C) 2007 Al Riddoch (See the file COPYING for details).
|
|
|
|
from random import uniform
|
|
|
|
from atlas import Operation, Entity
|
|
from rules import Location
|
|
|
|
from mind.goals.dynamic.DynamicGoal import DynamicGoal
|
|
|
|
|
|
class Chase(DynamicGoal):
|
|
"""Chase after something that has moved."""
|
|
|
|
def __init__(self, kinds, desc="Chase after things."):
|
|
DynamicGoal.__init__(self, trigger="sight_move", desc=desc)
|
|
self.kinds = kinds
|
|
|
|
def event(self, me, original_op, op):
|
|
# FIXME Now that this code is trigger goal, has this update been done?
|
|
other = me.map.update(op[0], op.get_seconds())
|
|
if other.id == me.entity.id:
|
|
return
|
|
# target=op[0].location.copy()
|
|
if other.parent.id != me.entity.parent.id:
|
|
return
|
|
if hasattr(other, "type") and other.type[0] not in self.kinds:
|
|
return
|
|
destination = other.location.pos
|
|
distance = destination.distance(me.entity.location.pos)
|
|
if distance < 1:
|
|
return
|
|
# CHeat, random chance that it ignores movement
|
|
if uniform(0, 30 / distance) < 1:
|
|
return
|
|
target = Location(me.entity.parent)
|
|
velocity = destination - me.entity.location.pos
|
|
if velocity.mag() == 0:
|
|
return
|
|
target.velocity = velocity.unit_vector()
|
|
target.pos = destination
|
|
return Operation("move", Entity(me.entity.id, location=target))
|