From: Anders R. <ma...@us...> - 2006-05-29 18:33:50
|
Update of /cvsroot/planeshift/planeshift/src/npcclient In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5008/src/npcclient Modified Files: npcbehave.cpp npcclient.cpp npcclient.h tribe.cpp Log Message: *** 2006-05-29 by Anders Reggestad - Added random functions to npcclient as wrappers to csRandomGen. - Fixed some comments that wasn't updated last time the code where changed. - Fixed move path to stop in a situation where the npc just continued on the path. - Added random pick of paths in tribe AI. Just to not have all NPCs do the same at the same time. Index: npcbehave.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcbehave.cpp,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** npcbehave.cpp 20 May 2006 11:51:01 -0000 1.122 --- npcbehave.cpp 29 May 2006 18:33:44 -0000 1.123 *************** *** 951,955 **** path.CalcLocalDest(pos, sector, localDest); ! // Using "true" teleports to dest location after proper time has elapsed and is therefore more tolerant of CD errors. // StartMoveTo(npc,eventmgr,localDest, sector,vel,action, false); StartMoveTo(npc, eventmgr, localDest, sector,vel,action, true); --- 951,956 ---- path.CalcLocalDest(pos, sector, localDest); ! // Using "true" teleports to dest location after proper time has ! // elapsed and is therefore more tolerant of CD errors. // StartMoveTo(npc,eventmgr,localDest, sector,vel,action, false); StartMoveTo(npc, eventmgr, localDest, sector,vel,action, true); *************** *** 2291,2295 **** psGameObject::GetPosition(npc->GetEntity(),pos,rot,sec); ! npc->Printf("MovePath Loc is %1.2f, %1.2f, %1.2f\n",pos.x,pos.y,pos.z); // None linear movement so we have to queue DRData updates. --- 2292,2296 ---- psGameObject::GetPosition(npc->GetEntity(),pos,rot,sec); ! npc->Printf("MovePath Loc is %1.2f, %1.2f, %1.2f Rot: %1.2f\n",pos.x,pos.y,pos.z,rot); // None linear movement so we have to queue DRData updates. *************** *** 2299,2302 **** --- 2300,2307 ---- if (!npc->GetLinMove()->IsPath()) { + npc->GetLinMove()->SetPathSpeed(0); + npc->GetLinMove()->SetVelocity( csVector3(0,0,0) ); + npcclient->GetNetworkMgr()->QueueDRData(npc->GetEntity(),npc->GetLinMove(),npc->GetDRCounter()); + npc->Printf("we are done..\n"); npc->ResumeScript(eventmgr, npc->GetBrain()->GetCurrentBehavior() ); Index: npcclient.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.cpp,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** npcclient.cpp 20 May 2006 10:09:50 -0000 1.93 --- npcclient.cpp 29 May 2006 18:33:44 -0000 1.94 *************** *** 69,76 **** psNPCClient::psNPCClient () { ! world = NULL; eventmanager = NULL; ! running = true; ! database = NULL; } --- 69,78 ---- psNPCClient::psNPCClient () { ! world = NULL; eventmanager = NULL; ! running = true; ! database = NULL; ! // Initialize the RNG using current time() as the seed value ! randomGen.Initialize(); } Index: npcclient.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/npcclient.h,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** npcclient.h 20 May 2006 10:09:50 -0000 1.52 --- npcclient.h 29 May 2006 18:33:44 -0000 1.53 *************** *** 20,26 **** #define __NPCCLIENT_H__ - #include <csutil/ref.h> #include <csutil/csstring.h> #include <csutil/hash.h> #include "net/pstypes.h" --- 20,27 ---- #define __NPCCLIENT_H__ #include <csutil/csstring.h> #include <csutil/hash.h> + #include <csutil/randomgen.h> + #include <csutil/ref.h> #include "net/pstypes.h" *************** *** 81,84 **** --- 82,96 ---- { return objreg; } + /** Returns a random number. + * + * @return Returns a random number between 0.0 and 1.0. + */ + float GetRandom() { return randomGen.Get(); } + /** Returns a random number with a limit. + * + * @return Returns a random number between 0 and limit. + */ + uint32 GetRandom(uint32 limit) { return randomGen.Get(limit); } + /** * Load and starts an optional script file that sets *************** *** 94,98 **** /** ! * This does 1 AI calc per NPC, then returns. */ void Tick(); --- 106,110 ---- /** ! * This does 1 AI calc per NPC, 1 AI calc per Tribe then returns. */ void Tick(); *************** *** 277,280 **** --- 289,294 ---- /// Counter used to start events at every nth client tick unsigned int tick_counter; + + csRandomGen randomGen; }; Index: tribe.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/npcclient/tribe.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tribe.cpp 16 May 2006 16:17:59 -0000 1.5 --- tribe.cpp 29 May 2006 18:33:44 -0000 1.6 *************** *** 77,83 **** if (behavior && strcmp(behavior->GetName(),"do nothing")==0) { ! Perception perception("tribe:path1"); ! npcclient->TriggerEvent(npc,&perception); } } --- 77,89 ---- if (behavior && strcmp(behavior->GetName(),"do nothing")==0) { ! if (npcclient->GetRandom() < 0.01) ! { ! csString path; ! path.Format("tribe:path%d",npcclient->GetRandom(2)+1); ! ! Perception perception(path); ! npcclient->TriggerEvent(npc,&perception); ! } } } |