Author Topic: No way to retreive unit's coordinates?  (Read 1555 times)

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
No way to retreive unit's coordinates?
« on: March 28, 2023, 02:07:57 pm »
Long story short, I'm trying to create an alien with a "dread aura" that drains morale of nearby x-com soldiers, and I want the intensity to scale with distance between the alien and the soldier. Except there seems to be no way to get unit's XYZ coordinates on the battlescape map? There are ways to get facing direction, and even turret turn angle, but I see nothing for actual position. That can't be right, can it? Any suggestions for a workaround?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8713
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #1 on: March 28, 2023, 02:15:28 pm »
getPosition.getX
getPosition.getY
getPosition.getZ

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #2 on: March 28, 2023, 02:18:26 pm »
Thanks a lot.

This does, however, bring the question of why I can't see it in the ref linked on ufopaedia. Is it outdated by now? Where do I get the up to date one then?

Offline Yankes

  • Commander
  • *****
  • Posts: 3246
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #3 on: March 28, 2023, 02:26:54 pm »
What link?
Beside, best place to check for uptodate data is exe itself, when you enable verbose logging, script engine dump all meta data to log, and there you can check actual script API.

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #4 on: March 28, 2023, 02:50:38 pm »

Offline Yankes

  • Commander
  • *****
  • Posts: 3246
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #5 on: March 28, 2023, 03:27:42 pm »
Code: [Select]
[16-09-2019_13-43-50] [DEBUG] Script info for: recolorUnitSprite
From this page, its from 3 years ago.

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #6 on: March 28, 2023, 04:17:56 pm »
Serves me right for trying to use the wiki.  :D

If I may, another quick question. I have 2 newTurnUnit scripts, with offsets 11 and 12. Will the game run offset 11 for each unit, and THEN offset 12 for each unit, or will it run 11 and 12 for one unit, 11 and 12 for the next, etc?

Offline Yankes

  • Commander
  • *****
  • Posts: 3246
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #7 on: March 28, 2023, 04:32:20 pm »
Second version. All global scripts hooks run as one whole operation on one unit. This mean you need finish processing one unit before any thing can be done for next one.

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #8 on: March 28, 2023, 06:01:13 pm »
Hm. Guess my idea can't work then, because a unit can't know the location of all other units in newTurnUnit and the order doesn't allow passing that information between units. What about local scripts? If I have a newTurnUnit defined on an armor, and another one globally, would that allow "going back and forth" between processing units?

Offline Yankes

  • Commander
  • *****
  • Posts: 3246
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #9 on: March 28, 2023, 07:27:28 pm »
No, "global" and "local" are called at same moment on same unit, only place where you define them rule set differ.

Overall currently cross-processing of unit in lacking, I had not time to sit down and thing to how best expand scripts to make it easy.
Some workaround is when you process you special unit, you get its position and then search tiles around it, and for each tile see if there is any unit there.
Then you can apply some changes, but be care full, this unit could be in different stage of end-turn processing.

Offline Amoebka

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: No way to retreive unit's coordinates?
« Reply #10 on: March 28, 2023, 07:34:47 pm »
Yeah, I thought about that, but I suspect searching 10000 tiles 20 times every half turn isn't going to be very fast.