Closed zchaoz closed 12 years ago
Ok, I tried my old methods written in the SensoryCortex.cs. isContainAgent(Agent Type) is working flawlessly now.
Will test it for Wolf and update it later today
I should mention that currently, your implementation of 'isContainAgent' (with its redundant loops) is by a factor of 2 the least efficient code in the entire system. I still keep by what I said last week, that you should just perform all those operations in a single loop, in the AI state, or otherwise implement some kind of caching arrangement to store the results within a single frame.
As I mentioned above, a single loop doesn't solve most of the problems I'm having.
For example, an array of SensedObjects has {Sheep, Sheep, Wolf, Shepherd, Sheep}
If I use a single loop, it will check for each object in the array by using an If Else statement like below:
If( Obj is not Wolf) -> Panic decrease 1 Else If (Obj is Wolf) -> Panic increase 1
So at the end of the loop, the Panic level will decrease, not increase like I want to. As the result, the Sheep never reaches another AI state.
I also took a look at your suggestion. It works but I think it has the same efficiency as the "isContainAgent", period. It goes something like:
Foreach Obj in SensedObjects.
If Obj is Wolf --> bool thereIsWolf = true; If Obj is Shepherd --> bool thereIsSheperd = true;
Each frame, both variables above is reset to false.
I understand what you mean here, but there's still no reason why you can't do it all in a single loop, like so:
int totalwolves int totalsheep int totalshepherds
foreach(whatever) switch on agent type: if wolf: totalwolves++ if sheep: totalsheep++ if shepherd: totalsheherds++
Then AT THE END, tally these up and apply the appropriate logic based on the existing numbers:
if(totalwolves > 0) then panic increase else panic decrease by (totalsheep * calmingrate)
So, you can do it in a single loop by collecting ALL the data you need at once.
thanks, I'd already done that before your comment.
Trying to make it simpler now.
About the method for SensedObject, can you add a method that can return if SensedObject array contains a wolf or sheep or shepherd?
Foreach works but it is not as my intend. For example:
I have a SensedObject array like {WOLF, SHEEP, SHEEP}
With foreach, it will check for each object in the array. In my code, i wrote something like:
If(Obj is WOLF) --> Increase Panic Level by 1
Else if(Obj is not WOLF) --> Decrease Panic level by 0.5
So, if there is only one WOLF in the SensedObject array, Panic Level will never increase! I can fix this by modify the "Increase Panic Level" rating to 3 or 4 but that doesn't solve anything.