• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to link a house to a citizen

Status
Not open for further replies.
Level 3
Joined
Jul 15, 2014
Messages
39
So we have a unit and its house. How do we link them together so that next 2 actions are possible.

1. Unit can check if he has house (ability for example) which will select his house for player1 or tell that he has no house (if it was destroyed).
2. If you see a house u can find which unit is its owner (by casting special checking ability for example).



What kind of link that could be? I tried that way: to set same custom value to both unit and his house.
So that if i know the units custom value, i need to check custom value of all existing houses and i can find the one equal. And if i know house's custom value i need to loop through all the units on the map.

The problem with my method is that this looping seems very expensive. And them units gona be able to check on each other pretty often.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Use a unit indexer to handle the custom data of units.
Then make 2 arrays of units - One for the houses and other for the units. When a house is assigned to anyone, then you use the custom value of the unit as array index for the house in array and the custom value of the house as array index for the unit.

set House[CustomValue(unit)] = house
set Unit[CustomValue(house)] = unit

Now you can just read the custom value of a unit/house and immediately jump to the other in an array.
If one house can be linked to several units, then you can use a unit group array instead of a unit array.
 
Status
Not open for further replies.
Top