HowToAddGrowers

From Arianne
Jump to navigation Jump to search

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!