What I want to do is this:
Create a building for each player in the game at a random point in the playable map area. But no two buildings can be within 24 range of each other. I can't get this to work, and this is the simple/easy part I believe.
I was doing something like this:
Code
Create 1 building for Player 1 at random point in map
Set Building[1] to last created unit
Set Temp_Point == random point in map
Do While - Distance between Temp_Point & Building[1] is equal to <24
Set Temp_Point == random point in map
End Do While
Create 1 Building for Player 2 at TempPoint
Set Building[2] to last created unit
Set Building[1] to last created unit
Set Temp_Point == random point in map
Do While - Distance between Temp_Point & Building[1] is equal to <24
Set Temp_Point == random point in map
End Do While
Create 1 Building for Player 2 at TempPoint
Set Building[2] to last created unit
Then this was repeated for each of the remaining 4 players, with another condition being added to the Do While statement, with an 'And' thingy. Eg. When creating player 6's location, the While loop will keep randomising the point until it is further than 24 away from P1, P2, P3, P4 AND p5.
I realise that there might be rare cases in which it is impossible for player 6 to have a start location - so I was going about adding validation to check the number of attempts it has taken to give player 6 a home. And if the attempts was over 1000, i would reset and start again at player 1.
BUT, for some reason, the above trigger (as shown) would spawn 2 buildings for player 1, and 2 buildings for player 2 - they wouldn't be closer than 24 to each other but for some reason, the trigger having only 2 lines as 'Create Unit' would end up creating 4 units.
----------------------------------------------------------- I rage quitted my map editor at this point -----------------------------------
I'm going to rebuild it from scratch again and hopefully try and figure it out myself - but in the mean time if anyone has any clues, I'd love to hear em.
Later on, I would like to create a 'circle' of units around the building (I can do this fine), to make a boundary of that buildings 'influence'. However, if two players boundaries overlap (which is impossible in the starting instance due to the 24 range limit on how close they can spawn), then the boundary units will move to an average point between each of them. The reason for this is, later on in the game your main (starting) building can be upgraded to increase it's 'control radius' - which gives you more land to exploit (currently leaving your control radius reverts your units to AI control).
------------------------------
This is ultimately a sort of proof of concept for emulating features such as in Civilisation IV (Culture), and even the Settlers game series, where you would build structures at strategic points to choke off enemy 'control' and gain more resources.
Edit: I cannot use 'Regions' for this since they are too limiting in their shapes. Since, yes, at the start everyone has a perfect 'circle' of control, but as the map fills up, you might get squashed or stretched depending on other players expanding territories around yours.
I will also like to know how to calculate 'if a unit is in the region', although i'm not using a region, i'm using a circle/group of units to define a boundary. I presume I will have to calculate the distance between the nearest boundary unit (to the unit that to the Starting Building. And so, if the unit (being checked)'s distance is greater to the starting building than the nearest boundary's distance - it would be outside? am I right?
Post has been edited 1 time(s), last time on May 16 2011, 4:54 pm by Cardinal.
None.