Exemple #1
0
 def tick_operation(self, op):
     """periodically reassess situation
     
     This method is automatically invoked by the C++ BaseMind code, due to its *_operation name.
     """
     args = op.get_args()
     if len(args) != 0:
         if args[0].name == "think":
             # It's a "thinking" op, which is the base of the AI behaviour.
             # At regular intervals the AI needs to assess its goals; this is done through "thinking" ops.
             op_tick = Operation("tick")
             # just copy the args from the previous tick
             op_tick.set_args(args)
             op_tick.set_future_seconds(const.basic_tick + self.jitter)
             op_tick.set_to(self.id)
             for t in self.pending_things:
                 thing = self.map.get(t)
                 if thing and thing.type[0]:
                     self.add_thing(thing)
             self.pending_things = []
             result = self.think()
             if self.message_queue:
                 result = self.message_queue + result
                 self.message_queue = None
             return op_tick + result
Exemple #2
0
 def move_it_to_loc(self, me):
     if self.wait > 0:
         self.wait = self.wait - 1
         return
     if type(self.location) == str:
         self.location = me.get_knowledge("location", self.location)
     elif not isLocation(self.location):
         self.location = Location(self.location, Point3D(0.0, 0.0, 0.0))
     if type(self.what) == str:
         if (self.what in me.things) == 0:
             return
         what = me.things[self.what][0]
         if self.speed == 0 or what.location.parent.id != self.location.parent.id:
             return Operation("move", Entity(what.id,
                                             location=self.location))
         iloc = what.location.copy()
         vel = what.location.pos.unit_vector_to(self.location.pos)
         iloc.velocity = vel * self.speed
         self.location.velocity = Vector3D(0.0, 0.0, 0.0)
         m_op1 = Operation("move", Entity(what.id, location=iloc))
         m_op2 = Operation("move", Entity(what.id, location=self.location))
         time = ((self.location.pos - what.location.pos).mag() / self.speed)
         self.wait = (time / const.basic_tick) + 1
         m_op2.set_future_seconds(time)
         return Oplist(m_op1, m_op2)
Exemple #3
0
 def tick_operation(self, op):
     """periodically reassess situation
     
     This method is automatically invoked by the C++ BaseMind code, due to its *_operation name.
     """
     args = op.get_args()
     if len(args) != 0:
         if args[0].name == "think":
             # It's a "thinking" op, which is the base of the AI behaviour.
             # At regular intervals the AI needs to assess its goals; this is done through "thinking" ops.
             op_tick = Operation("tick")
             # just copy the args from the previous tick
             op_tick.set_args(args)
             op_tick.set_future_seconds(const.basic_tick + self.jitter)
             op_tick.set_to(self.id)
             for t in self.pending_things:
                 thing = self.map.get(t)
                 if thing and thing.type[0]:
                     self.add_thing(thing)
             self.pending_things = []
             result = self.think()
             if self.message_queue:
                 result = self.message_queue + result
                 self.message_queue = None
             return op_tick + result
Exemple #4
0
    def setup_operation(self, op):
        """called once by world after object has been made
           send first tick operation to object
           
        This method is automatically invoked by the C++ BaseMind code, due to its *_operation name."""

        # Setup a tick operation for thinking
        think_tick_op = Operation("tick")
        think_tick_op.set_to(self.id)
        think_tick_op.set_args([Entity(name="think")])

        # Setup a tick operation for moving
        move_tick_op = Operation("tick")
        move_tick_op.set_to(self.id)
        move_tick_op.set_args([Entity(name="move")])
        move_tick_op.set_future_seconds(0.2)

        return Operation("look") + think_tick_op + move_tick_op
Exemple #5
0
 def shoot_operation(self, op):
     ammo = op[0].id
     to_ = op[1].id
     target = server.world.get_object(to_)
     vel = target.location.pos - self.location.parent.location.pos
     time = vel.mag() / 5
     vel = vel.unit_vector() * 5
     loc1 = Location(self.location.parent.location.parent,
                     self.location.parent.location.pos)
     loc1.velocity = vel
     loc2 = Location(target.location.parent, Point3D(0, 0, 0))
     loc2.velocity = Vector3D(0, 0, 0)
     m1 = Operation("move", Entity(ammo, location=loc1), to=ammo)
     m2 = Operation("move", Entity(ammo, location=loc2), to=ammo)
     m2.set_future_seconds(time)
     t = Operation("set", Entity(to_, status=-1), to=to_)
     t.set_future_seconds(time)
     return Oplist(m1, m2, t)
Exemple #6
0
    def setup_operation(self, op):
        """called once by world after object has been made
           send first tick operation to object
           
        This method is automatically invoked by the C++ BaseMind code, due to its *_operation name."""
        # CHEAT!: add memory, etc... initialization (or some of it to __init__)

        # Setup a tick operation for thinking
        think_tick_op = Operation("tick")
        think_tick_op.set_to(self.id)
        think_tick_op.set_args([Entity(name="think")])

        # Setup a tick operation for moving
        move_tick_op = Operation("tick")
        think_tick_op.set_to(self.id)
        move_tick_op.set_args([Entity(name="move")])
        move_tick_op.set_future_seconds(0.2)

        return Operation("look") + think_tick_op + move_tick_op
Exemple #7
0
 def tick_operation(self, op):
     world = self.parent
     res = Oplist()
     optick = Operation("tick", to=self)
     res = res + optick
     if self.props.rain < 0.1:
         optick.set_future_seconds(randint(60, 300))
         self.rain = uniform(0.1, 0.9)
         self.visibility = 10 / (self.props.rain * self.props.rain)
         res = res + Operation(
             "set", Entity(world.id, moisture=1), to=world)
     else:
         moisture = world.moisture
         optick.set_future_seconds(randint(600, 2400))
         self.props.rain = 0.0
         self.props.visibility = 1000
         res = res + Operation(
             "set", Entity(world.id, moisture=moisture - 0.5), to=world)
     res = res + Operation("set",
                           Entity(self.id,
                                  rain=self.props.rain,
                                  visibility=self.props.visibility),
                           to=self)
     return res