HowToAddGrowers: Difference between revisions

From Arianne
Jump to navigation Jump to search
Content deleted Content added
imported>Teiv
imported>Kymara
update to include other types of grower and some examples
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Add an grower is as easy as add an item. This tutorial descripes how to add it, for example we add an apple.
Adding an grower is as easy as adding an item. To prepare for the tutorial you have to get a copy of stendhal source, you can visit [http://sourceforge.net/project/showfiles.php?group_id=1111&package_id=145790 Sourceforge Project Page] to get a copy.


= Types of Grower =
To prepare for the tutorial you have to get a copy of stendhal source, you can visit [http://sourceforge.net/project/showfiles.php?group_id=1111&package_id=145790 Sourceforge Project Page] to get a copy.
The type of grower we are using for this example is called a 'passive' grower. An coconut grows at a spot, and it looks like an coconut has fallen to ground. The grower image on the ground is the same as the image of the item in your bag and to get it to bag you drag and drop. Or you can eat it directly from ground. Other examples of passive entities which just grow from ground are wood, iron ore, spinach, mushroom and toadstools. These times use ''PassiveEntityRespawnPoint''.


But there are other types of grower. For example think of the carrots growing in the grain field in semos plains. There, the grower image is a planted carrot. What you see in bag is a whole carrot. To get it from ground to bag you must right click and Pick it, or double click it to get into bag. These types use ''VegetableGrower''.


Even more advanced is the grain itself. This has several different images as it grows from just planted to ripe. You can only pick grain if you have a scythe. These types use ''GrainField''.
= Edit food.xml =
First step is to add the apple to food.xml (since 0.65 the files are splited from items.xml).


= Passive grower example - the coconut =
<pre>
The passive grower is the simplest example which is why we start with coconut.
<item name="apple">
== Create item ==
<type class="food" subclass="apple" tileid="-1"/>
First step is to add the coconut to data/conf/items/food.xml
<description>You see a nice shiny apple.</description>
<implementation class-name="games.stendhal.server.entity.item.Food"/> <attributes>
<amount value="20"/>
<frequency value="30"/>
<quantity value="1"/>
<regen value="3"/>
</attributes>
<weight value="1.0"/>
<value value="1"/>
<equipable>
<slot name="lhand"/>
<slot name="rhand"/>
<slot name="bag"/>
</equipable>
</item>
</pre>


This is all explained in the [[HowToAddItemsStendhal]] tutorial.

Most of the attributes are explained in the [[HowToAddItemsStendhal]] tutorial. For the grower there one important line at the begining. This line tell the server that this item is a grower:
<pre>
<implementation class-name="games.stendhal.server.entity.item.Food"/> <attributes>
</pre>


How to add the picture for an item is also descriped in [[HowToAddItemsStendhal]].
How to add the picture for an item is also descriped in [[HowToAddItemsStendhal]].


= The image for editor =
== Create image for map editor ==
To be able to add the apple to the map you have to make a tiled for the apple. It must have a white background and a border of 1 pixel around. The picture need a size of 32x32 pixel. <br>
To be able to add the item to the map you have to make a tile for it. It must have a white background and a black border of 1 pixel around. Each tile has a size of 32x32 pixel, but if you have more than one similar item which you wish to make a grower for, you may line up the tiles. Then give the whole picture of the lined up tiles a generic name to describe all the items in it. For example, a picture with fruits in is then saved to tiled/tileset/logic/item/fruits.png . Later we will refer to this generic name you chose as the ''clazz''.<br>
This picture you have to put in tiled/tileset/logic/item in your source dirctory. After put it in there, you are able to put the image on your map, where the apple should spawn. But at this moment stendhal would not compile. One more step to let it spawn.


Now that the image is part of your tileset, you are able to put the image on your map, in the 'objects' layer, where the item should spawn. But at this moment Stendhal would not compile. One more step to tell the server exactly what a tile with a picture of a coconut on it means ...
= Edit PassiveEntityRespawnPointFactory.java =

You have to open src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java to add the apple finally to game.<br>
== Edit PassiveEntityRespawnPointFactory.java ==
You have to open ''src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java'' to add the coconut finally to game.<br>
If you add apple to fruits.png in tileset you have to add apple to:
If you add apple to fruits.png in tileset you have to add apple to:
<pre>
<pre>
clazz.contains("fruits")
clazz.contains("fruits")
</pre>
</pre>
When you add a new kind of grower you have to add a new '''clazz''', an example you find in the file itself. After the switch you have to add following code:
When you add a new kind of grower you have to add a new ''clazz'', an example you find in the file itself. After the switch you have to add following code:
<pre>
<pre>
case 0:
case 0:
passiveEntityrespawnPoint = new PassiveEntityRespawnPoint("apple",500);
passiveEntityrespawnPoint = new PassiveEntityRespawnPoint("coconut",500);
break;
break;
</pre>
</pre>
The number after '''case''', is the number of the picture in your tileset file (starting with zero). Between the brackets belong the information for the item you wish to add. The '''500''' means that the apple will respawn in 500 turns.
The number after ''case'', is the number of the picture in your tileset file, '''counting from zero for the first tile'''. Between the brackets belong the information for the item you wish to add. The ''500'' means that the item will respawn in 500 turns. (One turn is 300ms on the live server, if you want to work out what that is in real time).



After this all is done and you can add the item to your map.
After this all is done and you can add the item to your map.


= Vegetable Grower example - a carrot =
= Comments =
To add a vegetable grower which should have a certain image when it is not ripe, and another image when it is ripe, and another image for the item in bag, we look at the carrot example.
If you like to add an other grower you just have to do the steps ahead. And have a look at ''src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java'', the most parts will be self-explanatory.
== Create item ==
as above
== Create image for map editor ==
as above
== Edit PassiveEntityRespawnPointFactory.java ==
When you come to edit ''src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java'', you again start with saying what file you are using:
<pre>
clazz.contains("vegetable")
</pre>
(say)
then the next part you make sure you're saying you use a VegetableGrower, for the item e.g. :
<pre>
case 1:
passiveEntityrespawnPoint = new VegetableGrower("carrot");
break;
</pre>
The case '1' is because it is the number 1 picture in the vegetable.png when we start counting from 0.
==Create grower images==
Now we need a picture of the carrot growing, it should be 32x64 with the topmost tile being an image of the unripe seed. We usually make this a blank tile, in fact. The ripe planted carrot is in the bottom most tile. The image must be saved in ''data/sprites/items/grower/'' with the name ''item''_grower.png. For example carrot_grower.png. If you got the name exactly right, that image is automatically used for the growing carrot.


= More complicated examples =
If you like to add an other grower then a fruit, you have to edit one of the other XML-Files in ''data/conf/items/''.
... such as grain field are beyond the scope of this tutorial. However all you need to know should be within the files in ''src/games/stendhal/server/entity/mapstuff/spawner'', which themselves have comments to explain what is happening. Good luck!

Latest revision as of 17:31, 17 December 2007

Adding an grower is as easy as adding an item. To prepare for the tutorial you have to get a copy of stendhal source, you can visit Sourceforge Project Page to get a copy.

Types of Grower

The type of grower we are using for this example is called a 'passive' grower. An coconut grows at a spot, and it looks like an coconut has fallen to ground. The grower image on the ground is the same as the image of the item in your bag and to get it to bag you drag and drop. Or you can eat it directly from ground. Other examples of passive entities which just grow from ground are wood, iron ore, spinach, mushroom and toadstools. These times use PassiveEntityRespawnPoint.

But there are other types of grower. For example think of the carrots growing in the grain field in semos plains. There, the grower image is a planted carrot. What you see in bag is a whole carrot. To get it from ground to bag you must right click and Pick it, or double click it to get into bag. These types use VegetableGrower.

Even more advanced is the grain itself. This has several different images as it grows from just planted to ripe. You can only pick grain if you have a scythe. These types use GrainField.

Passive grower example - the coconut

The passive grower is the simplest example which is why we start with coconut.

Create item

First step is to add the coconut to data/conf/items/food.xml

This is all explained in the HowToAddItemsStendhal tutorial.

How to add the picture for an item is also descriped in HowToAddItemsStendhal.

Create image for map editor

To be able to add the item to the map you have to make a tile for it. It must have a white background and a black border of 1 pixel around. Each tile has a size of 32x32 pixel, but if you have more than one similar item which you wish to make a grower for, you may line up the tiles. Then give the whole picture of the lined up tiles a generic name to describe all the items in it. For example, a picture with fruits in is then saved to tiled/tileset/logic/item/fruits.png . Later we will refer to this generic name you chose as the clazz.

Now that the image is part of your tileset, you are able to put the image on your map, in the 'objects' layer, where the item should spawn. But at this moment Stendhal would not compile. One more step to tell the server exactly what a tile with a picture of a coconut on it means ...

Edit PassiveEntityRespawnPointFactory.java

You have to open src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java to add the coconut finally to game.
If you add apple to fruits.png in tileset you have to add apple to:

clazz.contains("fruits")

When you add a new kind of grower you have to add a new clazz, an example you find in the file itself. After the switch you have to add following code:

case 0:
   passiveEntityrespawnPoint = new PassiveEntityRespawnPoint("coconut",500);
   break;

The number after case, is the number of the picture in your tileset file, counting from zero for the first tile. Between the brackets belong the information for the item you wish to add. The 500 means that the item will respawn in 500 turns. (One turn is 300ms on the live server, if you want to work out what that is in real time).

After this all is done and you can add the item to your map.

Vegetable Grower example - a carrot

To add a vegetable grower which should have a certain image when it is not ripe, and another image when it is ripe, and another image for the item in bag, we look at the carrot example.

Create item

as above

Create image for map editor

as above

Edit PassiveEntityRespawnPointFactory.java

When you come to edit src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java, you again start with saying what file you are using:

clazz.contains("vegetable")

(say) then the next part you make sure you're saying you use a VegetableGrower, for the item e.g. :

 
case 1:
   passiveEntityrespawnPoint = new VegetableGrower("carrot");
   break;

The case '1' is because it is the number 1 picture in the vegetable.png when we start counting from 0.

Create grower images

Now we need a picture of the carrot growing, it should be 32x64 with the topmost tile being an image of the unripe seed. We usually make this a blank tile, in fact. The ripe planted carrot is in the bottom most tile. The image must be saved in data/sprites/items/grower/ with the name item_grower.png. For example carrot_grower.png. If you got the name exactly right, that image is automatically used for the growing carrot.

More complicated examples

... such as grain field are beyond the scope of this tutorial. However all you need to know should be within the files in src/games/stendhal/server/entity/mapstuff/spawner, which themselves have comments to explain what is happening. Good luck!