HowToAddGrowers: Difference between revisions

From Arianne
Jump to navigation Jump to search
imported>Teiv
imported>Teiv
(No difference)

Revision as of 15:29, 17 December 2007

Add an grower is as easy as add an item. This tutorial descripes how to add it, for example we add an apple.

To prepare for the tutorial you have to get a copy of stendhal source, you can visit Sourceforge Project Page to get a copy.


Edit food.xml

First step is to add the apple to food.xml (since 0.65 the files are splited from items.xml).

  <item name="apple">
    <type class="food" subclass="apple" tileid="-1"/>
    <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>


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:

  <implementation class-name="games.stendhal.server.entity.item.Food"/>    <attributes>

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

The image for 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.
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.

Edit PassiveEntityRespawnPointFactory.java

You have to open src/games/stendhal/server/entity/mapstuff/spawner/PassiveEntityRespawnPointFactory.java to add the apple 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("apple",500);
   break;

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.

Comments

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.