How do I handle multiple instances in line-of-sight combat

Get help using Construct 2

Post » Fri Feb 05, 2016 9:31 am

Hi all,

I am trying to find the best of way of handling combat in a tank-based game where most of the combatants are NPC AI who drive about shooting one another using the pathfinding module and line of sight.

I have come up against a problem handling the fact that both objects have "LINE OF SIGHT". Let's call them Team1 (red tanks) and Team2 (blue tanks). What I have been so far is this:

Team1 is within line of sight of Team2
Pick Instance 0 of Team1
Set Team1.InCombat = 1
Pick Instance 0 of Team2
Set Team2.InCombat = 1
.........

Team2 is within line of sight of Team1
Pick Instance 0 of Team1
Set Team1.InCombat = 2
Pick Instance 0 of Team2
Set Team2.InCombat = 2
.......

As you can see I am trying to identify which set of code to run based on whether Team1 saw Team2 first, or Team2 saw Team1 first. Is this how I should be handling it?

Things get more complicated from here. Basically I want to be able to have multiple tanks in combat with each other at the same time using the same mechanics as above, but I'll summarise my intent:

1) Tanks enter combat by driving around until they come within line of sight of eachother.
2) Regardless of who saw who first, the two tanks enter combat with eachother until it is resolved.
3) First step of combat is to turn and face one another
4) Only when they pointing directly at each other can they start firing (this can mean that one tank can start firing before the other as it reaches angle(x,y,x1,y1) (or indeed [angle(x,y,x1,y1) -180]) first.
5) When one tank is destroyed the order needs to be given to the victorious tank (or tanks) to continue pathfinding. I am having most trouble here when multiple tanks are engaged in a fight with only one example of a tank.

Image

Most of my mockups end with two or more tanks entering combat with one. When combat is resolved (let's say Team1 won) the victorious Team1.instance1 deals with its own pathfinding and drives off, leaving Team1.instance2 sitting there because I have failed to keep track of the UIDs of who was in a battle.

Can someone explain the best method of handling multiple instances like this? I want 2on1 or even 3on1 battles to be a possibility, but I can't believe that the best way to do this is to keep copy pasting my code and putting in "Pick instance 0" "pick instance 1" "pick instance 2". How would you even go about handling 50-100 instances individually?

Thanks for your help.
Lncredible
B
8
S
2
Posts: 59
Reputation: 686

Post » Mon Feb 08, 2016 6:47 pm

You have to use Arrays or Hashmaps (like @rexrainbow 's Hash plugin) to track an indeterminate number of instances of object UIDs.

Then you can loop through those to run checks on every possible object. (For loops)
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests