[WF-General] A little help

Alistair Riddoch alriddoch at googlemail.com
Tue May 5 04:43:17 PDT 2009

2009/5/5 Amey Parulekar <amey.par at gmail.com>:
>> The parent of "oak" is not "acorn" though. Where did
>> you find something that suggested that? The parent of the "oak" class
>> is the "tree" class. The "acorn" class inherits from, or has as its
>> parent the "seed" class.
> In data/plants.xml,

This is the "acorn" class. You can tell by the line which specifies
the "id" further down. Sections of the class are in alphabetical order
as the file is machine processed. I will go through the section and
explain each part.

> <map>

The "attributes" section defines the default Atlas attributes that all
acorns have. Inside the server these are called properties because
they affect how the acorn is simulated. Each attribute has a
visibility to define who can see it, and a default value.

>    <map name="attributes">

The "biomass" attribute causes the acorn to be edible, and defines the
level of nutrition the eating entity gets from it.

>      <map name="biomass">
>        <float name="default">0.05</float>
>        <string name="visibility">public</string>
>      </map>

The "germinates" property defines to the seed simulation code what
kind of plant this seed will grow into.

>      <map name="germinates">
>        <string name="default">oak</string>
>        <string name="visibility">public</string>
>      </map>

The "mass" property is simply the mass of an acorn in kilograms, and
is used by the physics system in cyphesis as you would expect.

>      <map name="mass">
>        <float name="default">0.05</float>
>        <string name="visibility">public</string>
>      </map>

The "transient" property specifies that this entity disappears from
the world after a period of time, and that it is not a permanent
feature of the world map, so should not be stored in the database.

>      <map name="transient">
>        <float name="default">1800</float>
>        <string name="visibility">public</string>
>      </map>

This is the end of the "attributes" section.

>    </map>

The "id" of the class is it's primary identifier. This class is "acorn".

>    <string name="id">acorn</string>

The "objtype" is the object type. This specifies that this is a class.
All objects in these files are classes or "op_definition", which
define new types of operation.

>    <string name="objtype">class</string>

The "parents" specifiy the class this object inherits from. It is a
list for historical reasons, but the implementations require that it
only has one entry.

>    <list name="parents">
>      <string>seed</string>
>    </list>

The "script" defines the python object associated with this class,
which is created every time the entity is used in the world. You can
find the script in rulesets/mason/world/objects/plants/seeds/Acorn.py.

>    <map name="script">
>      <string name="language">python</string>
>      <string name="name">world.objects.plants.seeds.Acorn.Acorn</string>
>    </map>
>  </map>
> Like you said, the parent is "seed", but then there's "acorn" in there
> as well. I guess I got confused by that. What function does acorn
> serve here?

I hope my comments above have clarified that this is the class for
"acorn", and it inherits from "seed" because an acorn is a type of
seed. I hope you now understand why "oak" is in there, but why it is
not the class for "oak". If not please let me know and I will try and
explain in more detail.

> I think I've understood the way tasks are defined in tasks.xml, and to
> define fishing as an activity, I would have to define it as:
>  <map>
>    <map name="attributes">
>    </map>
>    <string name="id">fishing</string>
>    <string name="objtype">class</string>
>    <list name="parents">
>      <string>task</string>
>    </list>
>    <map name="activation">
>      <string name="operation">fish</string>
>      <string name="tool">fishing_pole</string>
>      <string name="target">ocean</string>
>    </map>
>    <map name="script">
>      <string name="language">python</string>
>      <string name="name">world.tasks.Fish</string>
>    </map>
>  </map>
> right?

This is very close to correct. Well done. In fact there is no ocean
object in game at the moment, but this is probably something we will
have to work on defining.

> But I have two problems here. One, fishing should be available for any
> moderately large body of water, like ponds and lakes, and not just for
> oceans. How would I go about associating an activity with multiple
> entities?

This is where inheritance is useful. Classes for "pond", "lake",
"ocean", "river" etc could all inherit from a base class for all
bodies of water. Getting this right can be tricky, but we'll have to
see what we can make work. We'll need to discuss with the client
developers a way to usefully define bodies of water as entities.

> And secondly, the <string
> name="name">world.tasks.(activity)</string> part. These are the python
> scripts in "rulesets/mason/world/tasks", right? So to create a fishing
> activity, I would have to create a new script for the same there. But
> the files there have a lot of functions like "new_loc =
> target.location.copy()". How do I find out what methods are available
> for which objects, and in turn add my own?

Adding new methods requires extending the exposed API to the C++ core,
and is quite involved. For now, if you need something you should let
me know and I'll look into it. The functions exposed on the various
C++ classes are implemented in rulesets/Py_Foo.cpp where Foo is the
C++ class available.

I would strongly suggest you make a point of logging on to Google Talk
whenever you are online, and ask me questions on there whenever you
have them. It is way more effective for getting quick answers than
email or irc. I've CCed the general mailing list on this mail as I
think it contains lots of useful information. I hope you don't mind.

Alistair Riddoch
alriddoch at googlemail.com

More information about the General mailing list