Author Topic: [done] unit entering area  (Read 1163 times)

treba

  • Guest
[done] unit entering area
« on: 5 October 2012, 18:27:42 »
hey,

i would like to request a event that fires when a unit enters a region.

i know this could be done already by registering all fields off that area with registerCellTriggerEventForFactionToLocation, but it's not quite nice to use as it would fire everytime the unit moves within the region.

« Last Edit: 10 October 2012, 05:53:45 by softcoder »

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: unit entering area
« Reply #1 on: 5 October 2012, 19:03:40 »
This needs more explanation. Do you want the event to fire each time the unit enters the region (meaning if the unit left the region and came back it would fire again?). OR do you mean fire the event once and thats it?

treba

  • Guest
Re: unit entering area
« Reply #2 on: 6 October 2012, 11:55:23 »
i'd say everytime it enters the region.
best would be something similar to registerCellTriggerEventForFactionToLocation, but having a region instead of a location.

maybe also without being limited to a faction. hope that doesn't influence the performance too much.

a query for the unit, like enteringUnit() would make it perfect.

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: unit entering area
« Reply #3 on: 6 October 2012, 12:20:41 »
how would you define a "region" ?
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

MoLAoS

  • Ornithopter
  • *****
  • Posts: 433
    • View Profile
Re: unit entering area
« Reply #4 on: 6 October 2012, 12:22:37 »
how would you define a "region" ?

GAE has this feature, in it a region is defined as a group of cells. I think it only support square or rectangular regions though.

treba

  • Guest
Re: unit entering area
« Reply #5 on: 8 October 2012, 08:37:33 »
i'd  say that a simple {x,y,h,w} or {minX,minY,maxX,maxY} would be fine

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: unit entering area
« Reply #6 on: 10 October 2012, 05:50:58 »
Added in current svn:

- added new cell trigger lua function to be able to detect when any unit enters or exits a region of cells:
int registerCellAreaTriggerEvent(Vec4i pos)
int triggeredEventAreaEntryUnitId()
int triggeredEventAreaExitUnitId()

The first registers a region from start xy to end x,y. Then ANY unit moving into OR out of the region triggers the event. To know which unit triggered the event check:
triggeredEventAreaEntryUnitId()

if this is <= 0 than the event is NOT an entry into the region but an Exit out of the region. The exit unit will be found in:
triggeredEventAreaExitUnitId()

So in the cell region trigger, the event is always going to set the entry or exit unit id so that you know if the unit is entering or exiting the region. The event is ONLY triggered when each unit enters or exits the region (not while walking around in it)

Example:

Code: [Select]
               <startup>
                        -- Register a region from cell 0,0 to 100,100
                        cell_area_event1 = registerCellAreaTriggerEvent({0,0,100,100})
                </startup>

                <cellTriggerEvent>
                        -- is this our region 0,0 to 100,100 event
                        if triggeredCellEventId() == cell_area_event1 then
                                -- if this returns > 0 than its a region entry trigger
                                if triggeredEventAreaEntryUnitId() > 0 then
                                        print('TEST cell_area_event1 ENTRY for unit: ' .. triggeredEventAreaEntryUnitId())

                                -- iotherwise its a region exit trigger
                                else
                                        print('TEST cell_area_event1 EXIT for unit: ' .. triggeredEventAreaExitUnitId())
                                end
                        end
                </cellTriggerEvent>


treba

  • Guest
Re: [done] unit entering area
« Reply #7 on: 10 October 2012, 07:47:07 »
thanks alot softcoder! you were diligent today =)

that makes things much easier for me!

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [done] unit entering area
« Reply #8 on: 10 October 2012, 14:00:33 »
Its a pleasure to help a good contributor to our work. And thanks for hosting a headless server for us and actually using the features we add :)

 

anything