2000-12-04 20:08:21 +00:00
|
|
|
#This file is distributed under the terms of the GNU General Public license.
|
|
|
|
|
#Copyright (C) 1999 Aloril (See the file COPYING for details).
|
|
|
|
|
|
|
|
|
|
from atlas import *
|
|
|
|
|
from common import log,const
|
|
|
|
|
|
2009-07-01 14:07:28 +01:00
|
|
|
import server
|
|
|
|
|
|
2000-12-04 20:08:21 +00:00
|
|
|
# Rate at which energy is used per tick
|
|
|
|
|
energyConsumption = 0.01
|
|
|
|
|
# Rate at which food boosts energy
|
|
|
|
|
foodConsumption = 0.1
|
|
|
|
|
# Weight lost when energy is exhausted
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
massConsumption = 1.0
|
|
|
|
|
# Energy gained when mass is lost
|
2000-12-04 20:08:21 +00:00
|
|
|
energyGain = 0.5
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
# Excess energy that is to be turned into mass
|
2000-12-04 20:08:21 +00:00
|
|
|
energyLoss = 0.1
|
|
|
|
|
# Weight gained from the excess energy
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
massGain = 0.5
|
2000-12-04 20:08:21 +00:00
|
|
|
|
2009-07-01 14:07:28 +01:00
|
|
|
class Animal(server.Thing):
|
2000-12-04 20:08:21 +00:00
|
|
|
"""This is base class for all kind of animals"""
|
2000-12-13 12:10:48 +00:00
|
|
|
def __init__(self, cppthing, **kw):
|
|
|
|
|
self.base_init(cppthing, kw)
|
2005-11-30 Al Riddoch <alriddoch@zepler.org>
* rulesets/basic/world/objects/Thing.py: Remove self.attributes
from the base class for all python scripts.
* rulesets/mason/world/objects/Weather.py,
rulesets/basic/world/objects/plants/Tree.py,
rulesets/basic/world/objects/animals/Animal.py,
data/basic.xml, data/mason.xml: Don't use set_kw to handle default
attributes, and add the to the .xml rules files.
* rulesets/basic/world/objects/buildings/House.py,
rulesets/basic/world/objects/buildings/StoneHouse.py,
rulesets/basic/world/objects/tools/Bow.py,
rulesets/basic/world/objects/tools/Sword.py,
rulesets/mason/world/objects/animals/Deer.py,
rulesets/mason/world/objects/animals/Pig.py,
rulesets/mason/world/objects/outdoor/Campfire.py,
rulesets/mason/world/objects/outdoor/Gravestone.py,
rulesets/mason/world/objects/plants/seeds/Acorn.py,
rulesets/mason/world/objects/plants/seeds/Apple.py,
rulesets/mason/world/objects/plants/seeds/Fircone.py,
rulesets/mason/world/objects/plants/seeds/Seed.py,
rulesets/mason/world/objects/tools/Cleaver.py,
rulesets/mason/world/objects/undead/Skeleton.py,
rulesets/werewolf/world/objects/characters/Villager.py,
rulesets/werewolf/world/objects/tools/Gallows.py:
Don't import set_kw from misc, as its now obsolete and unused.
2005-11-30 22:37:50 +00:00
|
|
|
self.status=1.0
|
|
|
|
|
self.mass=1.0
|
2000-12-04 20:08:21 +00:00
|
|
|
self.food=0
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
self.maxmass=50
|
2000-12-04 20:08:21 +00:00
|
|
|
self.tickcount=0
|
|
|
|
|
def tick_operation(self, op):
|
|
|
|
|
"""check energy state and see if we are starving"""
|
|
|
|
|
#CHEAT!: fix this with changing tick model to:
|
|
|
|
|
#use tick_list in worldrouter where it's stored next tick for each
|
|
|
|
|
#object
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
#print self, self.status, self.mass
|
2009-05-21 16:34:27 +01:00
|
|
|
res = Oplist()
|
2000-12-04 20:08:21 +00:00
|
|
|
self.tickcount=self.tickcount+1
|
|
|
|
|
if self.tickcount<30:
|
|
|
|
|
return res
|
|
|
|
|
self.tickcount=0
|
|
|
|
|
## if not res:
|
|
|
|
|
## res = Operation("tick",to=self)
|
2005-04-10 Al Riddoch <alriddoch@zepler.org>
* rulesets/Py_Operation.cpp, rulesets/Py_Optime.cpp,
rulesets/Py_Optime.h rulesets/Python_API.cpp:
Remove the Optime class from the API and force scripts to use
setFutureSeconds() to modify operation dispatch time.
* rulesets/acorn/world/objects/Weather.py,
rulesets/acorn/world/objects/plants/Tree.py,
rulesets/acorn/world/objects/plants/seeds/Acorn.py,
rulesets/acorn/world/objects/plants/seeds/Apple.py,
rulesets/acorn/world/objects/plants/seeds/Seed.py,
rulesets/basic/mind/NPCMind.py,
rulesets/basic/mind/goals/common/move.py,
rulesets/basic/world/objects/animals/Animal.py,
rulesets/basic/world/objects/buildings/House.py,
rulesets/basic/world/objects/elements/Fire.py,
rulesets/basic/world/objects/plants/Tree.py,
rulesets/basic/world/objects/tools/Bow.py,
rulesets/mason/world/objects/Weather.py,
rulesets/mason/world/objects/plants/seeds/Acorn.py,
rulesets/mason/world/objects/plants/seeds/Apple.py,
rulesets/mason/world/objects/plants/seeds/Fircone.py,
rulesets/mason/world/objects/plants/seeds/Seed.py:
Fix up all the python scripts to use setFutureSeconds on
ops instead of time.sadd.
2005-04-11 00:54:15 +00:00
|
|
|
## res.setFutureSeconds(const.basic_tick)
|
2000-12-04 20:08:21 +00:00
|
|
|
ent = Entity(self.id)
|
|
|
|
|
if self.food>=foodConsumption and self.status < 2.0:
|
|
|
|
|
self.status = self.status + foodConsumption
|
|
|
|
|
self.food = self.food - foodConsumption
|
|
|
|
|
#Send a private sight op to ourselves so our mind know how much food we have
|
|
|
|
|
res.append(Operation("sight", Operation("set", Entity(self.id, food=self.food)), to=self))
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
if self.status>(1.5+energyLoss) and self.mass < self.maxmass:
|
2000-12-04 20:08:21 +00:00
|
|
|
self.status = self.status - energyLoss
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
ent.mass = self.mass + massGain
|
|
|
|
|
if self.status<=energyConsumption and self.mass>massConsumption:
|
2000-12-04 20:08:21 +00:00
|
|
|
ent.status = self.status - energyConsumption + energyGain
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
ent.mass = self.mass - massConsumption
|
2000-12-04 20:08:21 +00:00
|
|
|
else:
|
|
|
|
|
ent.status = self.status - energyConsumption
|
|
|
|
|
res.append(Operation("set", ent, to = self))
|
|
|
|
|
return res
|
|
|
|
|
def nourish_operation(self, op):
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
mass=op[0].mass
|
|
|
|
|
self.food = self.food + mass
|
2000-12-04 20:08:21 +00:00
|
|
|
#ent = Entity(self.id)
|
|
|
|
|
#ent.status = self.status + energyGain
|
|
|
|
|
#return Operation("set", ent, to = self)
|
|
|
|
|
#Send a private sight op to ourselves so our mind know how much food we have
|
|
|
|
|
return Operation("sight", Operation("set", Entity(self.id, food=self.food)), to=self)
|
|
|
|
|
def eat_operation(self, op):
|
|
|
|
|
ent=Entity(self.id,status=-1)
|
|
|
|
|
res = Operation("set",ent,to=self)
|
2001-03-07 11:49:43 +00:00
|
|
|
to_ = op.from_
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
nour=Entity(to_,mass=self.mass)
|
2001-03-07 11:49:43 +00:00
|
|
|
res = res + Operation("nourish",nour,to=to_)
|
2000-12-04 20:08:21 +00:00
|
|
|
return res
|