Copyright VirtualSim 2004-2020 - All rights reserved
Attack
Let's open attack sample.
Select in the main toolbar, then open attack.db in data/db/samples/console/attack
Description
This example shows 2 things:
1- How to create 100 entities randomly from a catalog.
See the Logic createEntity for that. This logic is attached to the scenario player.
2- A simple logic that triggers the following behavior:
detects foes
select one random if not already attacking or being attacked
show line of attack
invite target to attack (duel)
fight and randomly kill
reengage after fight
Here, three logics have been defined.
One is given to the scenario Player. It is intended to create all the entities at start, randomly on the gaming area:
WCoord pos(RANDOM(-200,200),RANDOM(-200,200),0);
Entity* basic = new Entity("basic", pos);
nb++;
printf("%d\n", nb);
if (nb >= L:numb_ent) return DONE;
return AGAIN;
The second logic Attack is given to each entity on the game play.
The principle is simple:
Whenever an entity detects something around it (_Visual event), it selects randomly one "target" which is not already in a duel, then informs this target about a duel by sending it an event _Target. This events switch off the visual sensor then start the Attack. One of the two entities will be killed. The winner will restart the logic and fight again. The scenario stops when only one entity is left.
Runtime
During the scenario, a graph shows the number of entities fighting in duels.