General Category > Game creators corner

Multiple cell objects (buildings)


Hi all!

I'm making my TBS game on FIFE. It's great! I only have one problem.

I'm trying to implement "building" type of objects. These are like units but they can't move and they generally occupy more than one cell. Something like castles in Age of Empires. I was looking how to be able to have instances that occupy more than one cell and I haven't really found an easy way of doing this.

I found MultiCell objects, but this seems unnecessarily difficult, since I just have one image for the building (won't need rotating) and they all generally occupy just 4x4 cells.

My crazy idea would be to associate an "area", using areaID and automatically block the cells within this area. However, I haven't really understood how to do this (how to generate an area etc.). I was looking into using CellCache -> CellsInRect. Is this overly complicated? Is there an easier way to do it?

Thank you in advance!

Heya conan  :)

It's right that MultiCell objects are difficult. But so you can create all sorts of shapes, or face the situation if you use a hexgrid.
I think in your case the simplest solution would be to set the other three cells to blocking too. The Cell class have the setCellType() function for that purpose.
Another problem that can occur if you have objects/images that are larger as your cell geometry is ordering. There is no general solution but try to use the bottom cell of your 4x4 object for the real instance/object and the upper cells for additional blockers.

It should be also possible to do that with areas but thats more work as the extra blockers.

Hi helios!

Thank you so much for your quick answer! It helped me a lot! Your way of doing it is certainly simpler than what I was thinking (which included padding the remaining cells with some dummy instances etc. etc.)

I now implemented it and I would like to explain it for further references.

In order to let the "construction" of buildings, I made a class that is similar to a normal unit but when it is created and placed on the map, it does the following:
 Uses the "bottom left" cell as the instance "anchor".
 Cycles through the cells where the building is supposed to be. This is specially easy since we can just add one to the X and Y till we get to the height and width of the building.
 Sets the cell type by using
--- Code: ---cell.setCellType(fife.CTYPE_STATIC_BLOCKER)
--- End code ---

Additionally, I had to shift the instance image. In order to do this one can add the "y_offset" to the image in the xml that describes the object. For instance:

--- Code: ---<object id="beach_bar" namespace="" blocking="1" static="1" anchor_x="500" anchor_y="500">
<image source="beach_bar/000.png" direction="0"[b] x_offset="0" y_offset="-110[/b]"/>
--- End code ---

Once again, thank you helios for your help and I might come asking again soon ;)

Glad I could help :)
Is the different x and y anchor needed? I thought that is only useful for "real" multi cell objects.

Yeah right, I don't need this anchor property.


[0] Message Index

Go to full version