From: <ma...@us...> - 2012-01-01 21:04:46
|
Revision: 7965 http://planeshift.svn.sourceforge.net/planeshift/?rev=7965&view=rev Author: magodra Date: 2012-01-01 21:04:40 +0000 (Sun, 01 Jan 2012) Log Message: ----------- - Made GetHighestNeed for behaviors only consider behaviors applicable for NPC state. E.g. when dead only consider behaviors applicable for dead npcs. Modified Paths: -------------- trunk/src/npcclient/npcbehave.cpp trunk/src/npcclient/npcbehave.h trunk/src/npcclient/perceptions.cpp Modified: trunk/src/npcclient/npcbehave.cpp =================================================================== --- trunk/src/npcclient/npcbehave.cpp 2012-01-01 21:03:31 UTC (rev 7964) +++ trunk/src/npcclient/npcbehave.cpp 2012-01-01 21:04:40 UTC (rev 7965) @@ -462,9 +462,9 @@ behaviors.Interrupt(npc); } -float NPCType::GetHighestNeed() +float NPCType::GetHighestNeed(NPC* npc) { - return behaviors.GetHighestNeed(); + return behaviors.GetHighestNeed(npc); } @@ -633,7 +633,7 @@ } // If the interrupt has change the needs, try once - if (GetHighestNeed() > active->CurrentNeed()) + if (GetHighestNeed(npc) > active->CurrentNeed()) { npc->Printf(3,"Need to rechedule since a new need is higest"); continue; // Start the check once more. @@ -751,21 +751,25 @@ return reply; } -float BehaviorSet::GetHighestNeed() +float BehaviorSet::GetHighestNeed(NPC* npc) { float highest = 0.0; float temp; for (size_t i=0; i<behaviors.GetSize(); i++) { - if ((temp = behaviors[i]->CurrentNeed()) > highest) + Behavior * b = behaviors[i]; + if (b->ApplicableToNPCState(npc)) { - highest = temp; + if ((temp = b->CurrentNeed()) > highest) + { + highest = temp; + } + if ((temp = b->NewNeed()) > highest) + { + highest = temp; + } } - if ((temp = behaviors[i]->NewNeed()) > highest) - { - highest = temp; - } } return highest; Modified: trunk/src/npcclient/npcbehave.h =================================================================== --- trunk/src/npcclient/npcbehave.h 2012-01-01 21:03:31 UTC (rev 7964) +++ trunk/src/npcclient/npcbehave.h 2012-01-01 21:04:40 UTC (rev 7965) @@ -162,7 +162,7 @@ /** Return hight current or new need. */ - float GetHighestNeed(); + float GetHighestNeed(NPC* npc); }; @@ -239,7 +239,7 @@ /** Return hight current or new need. */ - float GetHighestNeed(); + float GetHighestNeed(NPC *npc); float GetAngularVelocity(NPC *npc); float GetVelocity(NPC *npc); Modified: trunk/src/npcclient/perceptions.cpp =================================================================== --- trunk/src/npcclient/perceptions.cpp 2012-01-01 21:03:31 UTC (rev 7964) +++ trunk/src/npcclient/perceptions.cpp 2012-01-01 21:04:40 UTC (rev 7965) @@ -284,7 +284,7 @@ case DESIRE_GUARANTIED: who->Printf(10, "Guarantied need to behavior %s", affected[i]->GetName()); - float highest = who->GetBrain()->GetHighestNeed(); + float highest = who->GetBrain()->GetHighestNeed(who); if (who->GetCurrentBehavior() != affected[i]) { affected[i]->ApplyNeedAbsolute(who, highest + 25); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |