FIFE forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

FIFE 0.4.0 has been released on 15th of January, 2017!

Author Topic: Multiple cell objects (buildings)  (Read 963 times)

conan

  • Newbie
  • Posts: 17
    • View Profile
Multiple cell objects (buildings)
« on: January 19, 2015, 11:28:03 pm »

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!
Logged

helios

  • Developer
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
Re: Multiple cell objects (buildings)
« Reply #1 on: January 20, 2015, 11:26:31 am »

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.
Logged

conan

  • Newbie
  • Posts: 17
    • View Profile
Re: Multiple cell objects (buildings)
« Reply #2 on: January 20, 2015, 05:24:12 pm »

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: [Select]
cell.setCellType(fife.CTYPE_STATIC_BLOCKER)
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: [Select]
<object id="beach_bar" namespace="http://www.fifengine.net/xml/rio_de_hola" 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]"/>

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

helios

  • Developer
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
Re: Multiple cell objects (buildings)
« Reply #3 on: January 21, 2015, 10:36:54 am »

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

conan

  • Newbie
  • Posts: 17
    • View Profile
Re: Multiple cell objects (buildings)
« Reply #4 on: January 21, 2015, 12:13:39 pm »

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