From: <lpa...@us...> - 2012-12-11 01:12:15
|
Revision: 8502 http://planeshift.svn.sourceforge.net/planeshift/?rev=8502&view=rev Author: lpancallo Date: 2012-12-11 01:12:04 +0000 (Tue, 11 Dec 2012) Log Message: ----------- Autoformatting only. Modified Paths: -------------- trunk/src/npcclient/npc.cpp trunk/src/npcclient/npc.h trunk/src/npcclient/npcclient.cpp trunk/src/npcclient/npcclient.h Modified: trunk/src/npcclient/npc.cpp =================================================================== --- trunk/src/npcclient/npc.cpp 2012-12-11 00:59:44 UTC (rev 8501) +++ trunk/src/npcclient/npc.cpp 2012-12-11 01:12:04 UTC (rev 8502) @@ -1,7 +1,7 @@ /* * npc.cpp by Keith Fulton <ke...@pa...> * -* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) +* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) * * * This program is free software; you can redistribute it and/or @@ -59,13 +59,13 @@ #include "tribe.h" #include "npcbehave.h" -extern iDataConnection *db; +extern iDataConnection* db; NPC::NPC(psNPCClient* npcclient, NetworkManager* networkmanager, psWorld* world, iEngine* engine, iCollideSystem* cdsys): checked(false), hatelist(npcclient, engine, world), tick(NULL) -{ - brain=NULL; +{ + brain=NULL; pid=0; - last_update=0; + last_update=0; npcActor=NULL; movable=NULL; DRcounter=0; @@ -79,14 +79,14 @@ // Store the active locate in the stored locates structure. storedLocates.PutUnique("Active", activeLocate); - ang_vel=vel=999; + ang_vel=vel=999; walkVelocity=runVelocity=0.0; // Will be cached - region=NULL; + region=NULL; insideRegion = true; // We assume that we start inside the region, if it exists insideTribeHome = true; // We assume that we start inside tribe home. - last_perception=NULL; - debugging=0; - alive=false; + last_perception=NULL; + debugging=0; + alive=false; tribe=NULL; raceInfo=NULL; checkedSector=NULL; @@ -101,7 +101,7 @@ this->cdsys = cdsys; this->bufferMemory = NULL; - for (int i = 0; i < 10; i++) + for(int i = 0; i < 10; i++) { debugLog.Push(csString("")); } @@ -110,35 +110,35 @@ NPC::~NPC() { - if (brain) + if(brain) { - delete brain; + delete brain; brain = NULL; } - if (last_perception) + if(last_perception) { delete last_perception; last_perception = NULL; } - // Cleare some cached values + // Cleare some cached values region = NULL; activeLocate->sector = NULL; activeLocate->wp = NULL; raceInfo = NULL; - if (bufferMemory) + if(bufferMemory) { - delete bufferMemory; - bufferMemory = NULL; + delete bufferMemory; + bufferMemory = NULL; } } void NPC::Tick() { // If NPC is disabled it should not tick - if (disabled) + if(disabled) return; // Ensure NPC only has one tick at a time. @@ -173,36 +173,36 @@ float rot; InstanceID instance = INSTANCE_ALL; - if (npcActor) + if(npcActor) { psGameObject::GetPosition(npcActor,pos,rot,sector); instance = npcActor->GetInstance(); } - reply.AppendFmt(" Pos: %s Rot: %.2f Inst: %d\n", + reply.AppendFmt(" Pos: %s Rot: %.2f Inst: %d\n", npcActor?toString(pos,sector).GetDataSafe():"(none)", rot, instance); } reply.AppendFmt(" DR Counter: %d ", DRcounter); reply.AppendFmt("%s\n",disabled?"Disabled ":""); reply.AppendFmt(" Active locate: ( Pos: %s Angle: %.1f deg Radius: %.2f WP: %s )\n", - toString(activeLocate->pos,activeLocate->sector).GetDataSafe(), - activeLocate->angle*180/PI,activeLocate->radius, - activeLocate->wp?activeLocate->wp->GetName():"(None)"); + toString(activeLocate->pos,activeLocate->sector).GetDataSafe(), + activeLocate->angle*180/PI,activeLocate->radius, + activeLocate->wp?activeLocate->wp->GetName():"(None)"); reply.AppendFmt(" Spawn pos: %s\n", toString(spawnPosition,spawnSector).GetDataSafe()); - if (GetOwner()) + if(GetOwner()) { reply.AppendFmt(" Owner: %s\n",GetOwnerName()); } - if (GetRegion()) + if(GetRegion()) { reply.AppendFmt(" Region( Name: %s Inside: %s )\n", GetRegion()->GetName(), insideRegion?"Yes":"No"); } - if (GetTribe()) + if(GetTribe()) { - reply.AppendFmt(" Tribe( Name: %s Type: %s Inside home: %s )\n", - GetTribe()->GetName(),GetTribeMemberType().GetDataSafe(),insideTribeHome?"Yes":"No"); + reply.AppendFmt(" Tribe( Name: %s Type: %s Inside home: %s )\n", + GetTribe()->GetName(),GetTribeMemberType().GetDataSafe(),insideTribeHome?"Yes":"No"); } - if (GetTarget()) + if(GetTarget()) { reply.AppendFmt(" Target: %s\n",GetTarget()->GetName()); } @@ -217,14 +217,14 @@ { DumpState(); CPrintf(CON_CMDOUTPUT,"\n"); - + DumpBehaviorList(); CPrintf(CON_CMDOUTPUT,"\n"); DumpReactionList(); CPrintf(CON_CMDOUTPUT,"\n"); - DumpHateList(); + DumpHateList(); CPrintf(CON_CMDOUTPUT,"\n"); DumpDebugLog(); @@ -234,7 +234,7 @@ CPrintf(CON_CMDOUTPUT, "Buffers:\n"); int index = 0; BufferHash::GlobalIterator iter = npcBuffer.GetIterator(); - while (iter.HasNext()) + while(iter.HasNext()) { csString bufferName; csString value = iter.Next(bufferName); @@ -245,9 +245,9 @@ { CPrintf(CON_CMDOUTPUT, "Name: %s\n", bufferMemory->name.GetData()); CPrintf(CON_CMDOUTPUT, "Pos: x:%f y:%f z:%f\n", - bufferMemory->pos[0], - bufferMemory->pos[1], - bufferMemory->pos[2]); + bufferMemory->pos[0], + bufferMemory->pos[1], + bufferMemory->pos[2]); CPrintf(CON_CMDOUTPUT, "Has Sector:\n"); if(bufferMemory->GetSector()) CPrintf(CON_CMDOUTPUT, "Yes\n"); @@ -260,9 +260,9 @@ } csString controlled; - for (size_t i = 0; i < controlledActors.GetSize(); i++) + for(size_t i = 0; i < controlledActors.GetSize(); i++) { - if (controlledActors[i].IsValid()) + if(controlledActors[i].IsValid()) { controlled.AppendFmt(" %s",controlledActors[i]->GetName()); } @@ -278,7 +278,7 @@ psLinearMovement* NPC::GetLinMove() { - if (npcActor) + if(npcActor) { return npcActor->pcmove; } @@ -306,7 +306,7 @@ return brain; } -void NPC::SetBrain(NPCType *type, EventManager* eventmanager) +void NPC::SetBrain(NPCType* type, EventManager* eventmanager) { delete this->brain; this->type = type->GetName(); @@ -314,7 +314,7 @@ } -bool NPC::Load(iResultRow& row, csHash<NPCType*, const char*>& npctypes, EventManager* eventmanager, PID usePID) +bool NPC::Load(iResultRow &row, csHash<NPCType*, const char*> &npctypes, EventManager* eventmanager, PID usePID) { name = row["name"]; if(usePID.IsValid()) @@ -324,7 +324,7 @@ else { pid = row.GetInt("char_id"); - if ( pid == 0 ) + if(pid == 0) { Error2("NPC '%s' has no id attribute. Error in XML",name.GetDataSafe()); return false; @@ -332,7 +332,7 @@ } type = row["npctype"]; - if ( type.Length() == 0 ) + if(type.Length() == 0) { Error3("NPC '%s'(%s) has no type attribute. Error in XML",name.GetDataSafe(),ShowID(pid)); return false; @@ -341,24 +341,24 @@ region_name = row["region"]; // optional NPCType* t = npctypes.Get(type, NULL); - if (!t) + if(!t) { - Error4("NPC '%s'(%s) type '%s' is not found. Error in XML",name.GetDataSafe(),ShowID(pid),(const char *)type); + Error4("NPC '%s'(%s) type '%s' is not found. Error in XML",name.GetDataSafe(),ShowID(pid),(const char*)type); return false; } - if (row.GetFloat("ang_vel_override") != 0.0) + if(row.GetFloat("ang_vel_override") != 0.0) { ang_vel = row.GetFloat("ang_vel_override"); } - if (row.GetFloat("move_vel_override") != 0.0) + if(row.GetFloat("move_vel_override") != 0.0) { vel = row.GetFloat("move_vel_override"); } - const char *d = row["console_debug"]; - if (d && *d=='Y') + const char* d = row["console_debug"]; + if(d && *d=='Y') { debugging = 5; } @@ -367,8 +367,8 @@ debugging = 0; } - const char *e = row["disabled"]; - if (e && (*e=='Y' || *e=='y')) + const char* e = row["disabled"]; + if(e && (*e=='Y' || *e=='y')) { disabled = true; } @@ -389,9 +389,9 @@ "('%s', %d, '%s', '%s', %f, %f, '%c',%d)", name.GetData(), use_char_id.Unbox(), type.GetData(), region_name.GetData(), ang_vel, vel, IsDebugging() ? 'Y' : 'N', ownerPID.Unbox()); - if (r!=1) + if(r!=1) { - Error3("Error in InsertCopy: %s->%s",db->GetLastQuery(),db->GetLastError() ); + Error3("Error in InsertCopy: %s->%s",db->GetLastQuery(),db->GetLastError()); } else { @@ -400,15 +400,15 @@ return (r==1); } -void NPC::SetActor(gemNPCActor * actor) +void NPC::SetActor(gemNPCActor* actor) { npcActor = actor; // Initialize active location to a known ok value - if (npcActor) + if(npcActor) { - - iSector *sector; + + iSector* sector; psGameObject::GetPosition(actor,activeLocate->pos,activeLocate->angle,sector); movable = actor->pcmesh->GetMesh()->GetMovable(); } @@ -418,14 +418,14 @@ } } -void NPC::SetAlive( bool a ) +void NPC::SetAlive(bool a) { alive = a; } void NPC::Advance(csTicks when) { - if (last_update && !disabled) + if(last_update && !disabled) { brain->Advance(when-last_update, this); @@ -435,21 +435,21 @@ last_update = when; } -void NPC::TriggerEvent(Perception *pcpt, float maxRange, - csVector3 *basePos, iSector *baseSector, bool sameSector) +void NPC::TriggerEvent(Perception* pcpt, float maxRange, + csVector3* basePos, iSector* baseSector, bool sameSector) { - if (disabled) + if(disabled) { Printf(15,"Disabled so rejecting perception #s" - ,pcpt->ToString(this).GetData() ); + ,pcpt->ToString(this).GetData()); return; } - if (maxRange > 0.0) + if(maxRange > 0.0) { // This is a range based perception gemNPCActor* me = GetActor(); - if (!me) + if(!me) { Printf(15,"Can't do a ranged based check without an actor"); return; @@ -459,22 +459,22 @@ iSector* sector; psGameObject::GetPosition(me, pos, sector); - if (sameSector && sector != baseSector) + if(sameSector && sector != baseSector) { return; } float distance = world->Distance(pos, sector, *basePos, baseSector); - if (distance > maxRange) + if(distance > maxRange) { Printf(15,"The distance %.2f is outside range %.2f of perception %s", - distance, maxRange, pcpt->ToString(this).GetData() ); + distance, maxRange, pcpt->ToString(this).GetData()); return; } } - - Printf(10,"Got event %s",pcpt->ToString(this).GetData() ); + + Printf(10,"Got event %s",pcpt->ToString(this).GetData()); brain->FirePerception(this, pcpt); } @@ -484,16 +484,16 @@ TriggerEvent(&perc, -1, NULL, NULL, false); } -void NPC::SetLastPerception(Perception *pcpt) +void NPC::SetLastPerception(Perception* pcpt) { - if (last_perception) + if(last_perception) delete last_perception; last_perception = pcpt; } gemNPCActor* NPC::GetMostHated(float range, bool includeInvisible, bool includeInvincible, float* hate) { - iSector *sector=NULL; + iSector* sector=NULL; csVector3 pos; psGameObject::GetPosition(GetActor(), pos, sector); @@ -502,15 +502,15 @@ } -gemNPCActor* NPC::GetMostHated( csVector3& pos, iSector *sector, float range, LocationType * region, bool includeInvisible, bool includeInvincible, float* hate) +gemNPCActor* NPC::GetMostHated(csVector3 &pos, iSector* sector, float range, LocationType* region, bool includeInvisible, bool includeInvincible, float* hate) { gemNPCActor* hated = hatelist.GetMostHated(pos, sector, range, region, - includeInvisible, includeInvincible, hate); + includeInvisible, includeInvincible, hate); - if (hated) + if(hated) { Printf(5, "Found most hated: %s(%s)", hated->GetName(), ShowID(hated->GetEID())); - + } else { @@ -520,7 +520,7 @@ return hated; } -void NPC::AddToHateList(gemNPCActor *attacker, float delta) +void NPC::AddToHateList(gemNPCActor* attacker, float delta) { Printf("Adding %1.2f to hatelist score for %s(%s).", delta, attacker->GetName(), ShowID(attacker->GetEID())); @@ -532,41 +532,41 @@ } -float NPC::GetEntityHate(gemNPCActor *ent) +float NPC::GetEntityHate(gemNPCActor* ent) { return hatelist.GetHate(ent->GetEID()); } void NPC::RemoveFromHateList(EID who) { - if (hatelist.Remove(who)) + if(hatelist.Remove(who)) { Printf("Removed %s from hate list.", ShowID(who)); } } -void NPC::SetLocate(const csString& destination, const NPC::Locate& locate ) +void NPC::SetLocate(const csString &destination, const NPC::Locate &locate) { // Find or create locate Locate* current = storedLocates.Get(destination,NULL); - if (!current) + if(!current) { current = new Locate; storedLocates.PutUnique(destination,current); } - + // Copy content *current = locate; } -void NPC::GetActiveLocate(csVector3& pos, iSector*& sector, float& rot) +void NPC::GetActiveLocate(csVector3 &pos, iSector* §or, float &rot) { pos=activeLocate->pos; sector = activeLocate->sector; rot=activeLocate->angle; } -void NPC::GetActiveLocate(Waypoint*& wp) +void NPC::GetActiveLocate(Waypoint* &wp) { wp = activeLocate->wp; } @@ -581,43 +581,43 @@ Printf(5,"Copy locate from %s to %s (%X)",source.GetDataSafe(),destination.GetDataSafe(),flags); Locate* sourceLocate = storedLocates.Get(source,NULL); - if (!sourceLocate) + if(!sourceLocate) { Printf(5,"Failed to copy, no source found!"); return false; } Locate* destinationLocation = storedLocates.Get(destination,NULL); - if (!destinationLocation) + if(!destinationLocation) { destinationLocation = new Locate; storedLocates.PutUnique(destination,destinationLocation); } - - if (flags & LOCATION_POS) + + if(flags & LOCATION_POS) { destinationLocation->pos = sourceLocate->pos; } - if (flags & LOCATION_SECTOR) + if(flags & LOCATION_SECTOR) { destinationLocation->sector = sourceLocate->sector; } - if (flags & LOCATION_ANGLE) + if(flags & LOCATION_ANGLE) { destinationLocation->angle = sourceLocate->angle; } - if (flags & LOCATION_WP) + if(flags & LOCATION_WP) { destinationLocation->wp = sourceLocate->wp; } - if (flags & LOCATION_RADIUS) + if(flags & LOCATION_RADIUS) { destinationLocation->radius = sourceLocate->radius; } - if (flags & LOCATION_TARGET) + if(flags & LOCATION_TARGET) { destinationLocation->target = sourceLocate->target; - if (destination == "Active") + if(destination == "Active") { SetTarget(destinationLocation->target); } @@ -628,7 +628,7 @@ float NPC::GetAngularVelocity() { - if (ang_vel == 999) + if(ang_vel == 999) return brain->GetAngularVelocity(this); else return ang_vel; @@ -636,7 +636,7 @@ float NPC::GetVelocity() { - if (vel == 999) + if(vel == 999) return brain->GetVelocity(this); else return vel; @@ -645,7 +645,7 @@ float NPC::GetWalkVelocity() { // Cache value if not looked up before - if (walkVelocity == 0.0) + if(walkVelocity == 0.0) { walkVelocity = npcclient->GetWalkVelocity(npcActor->GetRace()); } @@ -656,7 +656,7 @@ float NPC::GetRunVelocity() { // Cache value if not looked up before - if (runVelocity == 0.0) + if(runVelocity == 0.0) { runVelocity = npcclient->GetRunVelocity(npcActor->GetRace()); } @@ -664,9 +664,9 @@ return runVelocity; } -LocationType *NPC::GetRegion() +LocationType* NPC::GetRegion() { - if (region) + if(region) { return region; } @@ -677,10 +677,11 @@ } } -void NPC::Disable( bool disable) +void NPC::Disable(bool disable) { // if not yet enabled, restart the tick - if (disabled && !disable) { + if(disabled && !disable) + { disabled = false; Tick(); } @@ -688,14 +689,14 @@ disabled = disable; // Stop the movement - + // Set Vel to zero again if(GetActor()) { - GetLinMove()->SetVelocity( csVector3(0,0,0) ); - GetLinMove()->SetAngularVelocity( 0 ); - + GetLinMove()->SetVelocity(csVector3(0,0,0)); + GetLinMove()->SetAngularVelocity(0); + //now persist networkmanager->QueueDRData(this); networkmanager->QueueImperviousCommand(GetActor(),true); @@ -710,7 +711,7 @@ float rot; InstanceID instance = INSTANCE_ALL; - if (npcActor) + if(npcActor) { psGameObject::GetPosition(npcActor,loc,rot,sector); instance = npcActor->GetInstance(); @@ -723,7 +724,7 @@ CPrintf(CON_CMDOUTPUT, "Instance: %d\n",instance); CPrintf(CON_CMDOUTPUT, "Debugging: %d\n",debugging); csString clients; - for (size_t i = 0; i < debugClients.GetSize(); i++) + for(size_t i = 0; i < debugClients.GetSize(); i++) { clients.AppendFmt(" %u",debugClients[i]); } @@ -752,7 +753,7 @@ CPrintf(CON_CMDOUTPUT, "Locates for %s (%s)\n", name.GetData(), ShowID(pid)); CPrintf(CON_CMDOUTPUT, "---------------------------------------------\n"); LocateHash::GlobalIterator iter = storedLocates.GetIterator(); - while (iter.HasNext()) + while(iter.HasNext()) { csString name; Locate* locate = iter.Next(name); @@ -760,9 +761,9 @@ CPrintf(CON_CMDOUTPUT, "%-15s Angle: %.2f\n","",locate->angle); CPrintf(CON_CMDOUTPUT, "%-15s Radius: %.2f\n","",locate->radius); CPrintf(CON_CMDOUTPUT, "%-15s WP: %s\n","",locate->wp?locate->wp->GetName():""); - + } - + } @@ -770,7 +771,7 @@ { CPrintf(CON_CMDOUTPUT, "Behaviors for %s (%s)\n", name.GetData(), ShowID(pid)); CPrintf(CON_CMDOUTPUT, "---------------------------------------------------------\n"); - + brain->DumpBehaviorList(this); } @@ -778,19 +779,19 @@ { CPrintf(CON_CMDOUTPUT, "Reactions for %s (%s)\n", name.GetData(), ShowID(pid)); CPrintf(CON_CMDOUTPUT, "---------------------------------------------------------\n"); - + brain->DumpReactionList(this); } void NPC::DumpHateList() { - iSector *sector=NULL; + iSector* sector=NULL; csVector3 pos; CPrintf(CON_CMDOUTPUT, "Hate list for %s (%s)\n", name.GetData(), ShowID(pid)); CPrintf(CON_CMDOUTPUT, "---------------------------------------------\n"); - if (GetActor()) + if(GetActor()) { psGameObject::GetPosition(GetActor(),pos,sector); hatelist.DumpHateList(pos,sector); @@ -801,11 +802,11 @@ { CPrintf(CON_CMDOUTPUT, "Debug log for %s (%s)\n", name.GetData(), ShowID(pid)); CPrintf(CON_CMDOUTPUT, "---------------------------------------------\n"); - for (size_t i = 0; i < debugLog.GetSize(); i++) + for(size_t i = 0; i < debugLog.GetSize(); i++) { CPrintf(CON_CMDOUTPUT,"%2d %s\n",i,debugLog[(nextDebugLogEntry+i)%debugLog.GetSize()].GetDataSafe()); } - + } @@ -831,7 +832,7 @@ psGameObject::GetPosition(GetActor(), loc, sector); csArray<gemNPCActor*> nearlist = npcclient->FindNearbyActors(sector, loc, range); - if (nearlist.GetSize() > 0) + if(nearlist.GetSize() > 0) { gemNPCActor* nearestEnt = NULL; csVector3 nearestLoc; @@ -839,20 +840,20 @@ float nearestRange=range; - for (size_t i=0; i<nearlist.GetSize(); i++) + for(size_t i=0; i<nearlist.GetSize(); i++) { - gemNPCActor *ent = nearlist[i]; + gemNPCActor* ent = nearlist[i]; // Filter own NPC actor if(ent == GetActor()) continue; csVector3 loc2; - iSector *sector2; + iSector* sector2; psGameObject::GetPosition(ent, loc2, sector2); float dist = world->Distance(loc, sector, loc2, sector2); - if (dist < nearestRange) + if(dist < nearestRange) { nearestRange = dist; nearestEnt = ent; @@ -860,7 +861,7 @@ nearestSector = sector2; } } - if (nearestEnt) + if(nearestEnt) { destPosition = nearestLoc; destSector = nearestSector; @@ -879,7 +880,7 @@ psGameObject::GetPosition(GetActor(), loc, sector); csArray<gemNPCActor*> nearlist = npcclient->FindNearbyActors(sector, loc, range); - if (nearlist.GetSize() > 0) + if(nearlist.GetSize() > 0) { gemNPCActor* nearestEnt = NULL; csVector3 nearestLoc; @@ -887,20 +888,20 @@ float nearestRange=range; - for (size_t i=0; i<nearlist.GetSize(); i++) + for(size_t i=0; i<nearlist.GetSize(); i++) { - gemNPCActor *ent = nearlist[i]; + gemNPCActor* ent = nearlist[i]; // Filter own NPC actor, and all players if(ent == GetActor() || !ent->GetNPC()) continue; csVector3 loc2; - iSector *sector2; + iSector* sector2; psGameObject::GetPosition(ent, loc2, sector2); float dist = world->Distance(loc, sector, loc2, sector2); - if (dist < nearestRange) + if(dist < nearestRange) { nearestRange = dist; nearestEnt = ent; @@ -908,7 +909,7 @@ nearestSector = sector2; } } - if (nearestEnt) + if(nearestEnt) { destPosition = nearestLoc; destSector = nearestSector; @@ -927,7 +928,7 @@ psGameObject::GetPosition(GetActor(), loc, sector); csArray<gemNPCActor*> nearlist = npcclient->FindNearbyActors(sector, loc, range); - if (nearlist.GetSize() > 0) + if(nearlist.GetSize() > 0) { gemNPCActor* nearestEnt = NULL; csVector3 nearestLoc; @@ -935,20 +936,20 @@ float nearestRange=range; - for (size_t i=0; i<nearlist.GetSize(); i++) + for(size_t i=0; i<nearlist.GetSize(); i++) { - gemNPCActor *ent = nearlist[i]; + gemNPCActor* ent = nearlist[i]; // Filter own NPC actor, and all NPCs if(ent == GetActor() || ent->GetNPC()) continue; csVector3 loc2; - iSector *sector2; + iSector* sector2; psGameObject::GetPosition(ent, loc2, sector2); float dist = world->Distance(loc, sector, loc2, sector2); - if (dist < nearestRange) + if(dist < nearestRange) { nearestRange = dist; nearestEnt = ent; @@ -956,7 +957,7 @@ nearestSector = sector2; } } - if (nearestEnt) + if(nearestEnt) { destPosition = nearestLoc; destSector = nearestSector; @@ -978,19 +979,19 @@ psGameObject::GetPosition(GetActor(), loc, sector); csArray<gemNPCObject*> nearlist = npcclient->FindNearbyEntities(sector,loc,range); - if (nearlist.GetSize() > 0) + if(nearlist.GetSize() > 0) { min_range=range; - for (size_t i=0; i<nearlist.GetSize(); i++) + for(size_t i=0; i<nearlist.GetSize(); i++) { - gemNPCObject *ent = nearlist[i]; + gemNPCObject* ent = nearlist[i]; NPC* npcFriend = ent->GetNPC(); - if (!npcFriend || npcFriend == this) + if(!npcFriend || npcFriend == this) continue; csVector3 loc2, isect; - iSector *sector2; + iSector* sector2; psGameObject::GetPosition(ent, loc2, sector2); float dist = (loc2 - loc).Norm(); @@ -1000,11 +1001,11 @@ // Is this friend visible? csIntersectingTriangle closest_tri; iMeshWrapper* sel = 0; - - dist = csColliderHelper::TraceBeam (npcclient->GetCollDetSys(), sector, - loc + csVector3(0, 0.6f, 0), loc2 + csVector3(0, 0.6f, 0), true, closest_tri, isect, &sel); + + dist = csColliderHelper::TraceBeam(npcclient->GetCollDetSys(), sector, + loc + csVector3(0, 0.6f, 0), loc2 + csVector3(0, 0.6f, 0), true, closest_tri, isect, &sel); // Not visible - if (dist > 0) + if(dist > 0) continue; min_range = (loc2 - loc).Norm(); @@ -1024,31 +1025,31 @@ psGameObject::GetPosition(GetActor(), loc, sector); csArray<gemNPCObject*> nearlist = npcclient->FindNearbyEntities(sector,loc,range); - if (nearlist.GetSize() > 0) + if(nearlist.GetSize() > 0) { min_range=range; - for (size_t i=0; i<nearlist.GetSize(); i++) + for(size_t i=0; i<nearlist.GetSize(); i++) { // Check if this is an Actor - gemNPCActor *ent = dynamic_cast<gemNPCActor*>(nearlist[i]); - if (!ent) + gemNPCActor* ent = dynamic_cast<gemNPCActor*>(nearlist[i]); + if(!ent) { continue; // No actor } - + // Check if this is an NPC - if (ent->GetNPC()) + if(ent->GetNPC()) { continue; // This is and NPC } - - if (ent->IsAlive()) + + if(ent->IsAlive()) { continue; } csVector3 loc2, isect; - iSector *sector2; + iSector* sector2; psGameObject::GetPosition(ent, loc2, sector2); float dist = (loc2 - loc).Norm(); @@ -1062,7 +1063,7 @@ return nearEnt; } -void NPC::Printf(const char *msg,...) +void NPC::Printf(const char* msg,...) { va_list args; @@ -1074,7 +1075,7 @@ va_end(args); } -void NPC::Printf(int debug, const char *msg,...) +void NPC::Printf(int debug, const char* msg,...) { va_list args; @@ -1086,12 +1087,12 @@ va_end(args); } -void NPC::VPrintf(int debug, const char *msg, va_list args) +void NPC::VPrintf(int debug, const char* msg, va_list args) { char str[1024]; - + if(!IsDebugging()) - return; + return; vsprintf(str, msg, args); @@ -1099,12 +1100,12 @@ debugLog[nextDebugLogEntry] = str; nextDebugLogEntry = (nextDebugLogEntry+1)%debugLog.GetSize(); - if (!IsDebugging(debug)) + if(!IsDebugging(debug)) return; CPrintf(CON_CMDOUTPUT, "%s (%s)> %s\n", GetName(), ShowID(pid), str); - for (size_t i = 0; i < debugClients.GetSize(); i++) + for(size_t i = 0; i < debugClients.GetSize(); i++) { networkmanager->QueueSystemInfoCommand(debugClients[i],"%s (%s)> %s", GetName(), ShowID(pid), str); } @@ -1113,25 +1114,25 @@ gemNPCObject* NPC::GetTarget() { // If something is targeted, use it. - if (target_id != 0) + if(target_id != 0) { // Check if visible - gemNPCObject * obj = npcclient->FindEntityID(target_id); - if (obj && obj->IsInvisible()) + gemNPCObject* obj = npcclient->FindEntityID(target_id); + if(obj && obj->IsInvisible()) { Printf(15, "GetTarget returning nothing, target is invisible"); return NULL; } - + return obj; } else // if not, try the last perception entity { - if (GetLastPerception()) + if(GetLastPerception()) { gemNPCObject* target = NULL; gemNPCObject* entity = GetLastPerception()->GetTarget(); - if (entity) + if(entity) { target = npcclient->FindEntityID(entity->GetEID()); } @@ -1142,9 +1143,9 @@ return NULL; } -void NPC::SetTarget(gemNPCObject *t) +void NPC::SetTarget(gemNPCObject* t) { - if (t == NULL) + if(t == NULL) { Printf(10,"Clearing target"); target_id = EID(0); @@ -1157,62 +1158,62 @@ } -gemNPCObject *NPC::GetOwner() +gemNPCObject* NPC::GetOwner() { - if (owner_id.IsValid()) + if(owner_id.IsValid()) { - return npcclient->FindEntityID( owner_id ); - } + return npcclient->FindEntityID(owner_id); + } return NULL; } -const char * NPC::GetOwnerName() +const char* NPC::GetOwnerName() { - if (owner_id.IsValid()) + if(owner_id.IsValid()) { - gemNPCObject *obj = npcclient->FindEntityID( owner_id ); - if (obj) + gemNPCObject* obj = npcclient->FindEntityID(owner_id); + if(obj) { return obj->GetName(); } - } + } - return ""; + return ""; } void NPC::SetOwner(EID owner_EID) { - if (owner_EID.IsValid()) + if(owner_EID.IsValid()) owner_id = owner_EID; } -void NPC::SetTribe(Tribe * new_tribe) +void NPC::SetTribe(Tribe* new_tribe) { tribe = new_tribe; } -Tribe * NPC::GetTribe() +Tribe* NPC::GetTribe() { return tribe; } -void NPC::SetTribeMemberType( const char* tribeMemberType ) +void NPC::SetTribeMemberType(const char* tribeMemberType) { this->tribeMemberType = tribeMemberType; } -const csString& NPC::GetTribeMemberType() const +const csString &NPC::GetTribeMemberType() const { return tribeMemberType; } RaceInfo_t* NPC::GetRaceInfo() { - if (!raceInfo && npcActor) + if(!raceInfo && npcActor) { raceInfo = npcclient->GetRaceInfo(npcActor->GetRace()); } - + return raceInfo; } @@ -1229,7 +1230,7 @@ void NPC::UpdateControlled() { - if (controlledActors.IsEmpty()) + if(controlledActors.IsEmpty()) { return; } @@ -1237,13 +1238,13 @@ csVector3 pos,vel; float yrot; iSector* sector; - + psGameObject::GetPosition(GetActor(), pos, yrot, sector); vel = GetLinMove()->GetVelocity(); - for (size_t i = 0; i < controlledActors.GetSize(); i++) + for(size_t i = 0; i < controlledActors.GetSize(); i++) { - if (controlledActors[i].IsValid()) + if(controlledActors[i].IsValid()) { gemNPCActor* controlled = controlledActors[i]; @@ -1253,9 +1254,9 @@ psGameObject::SetPosition(controlled, pos, sector); psGameObject::SetRotationAngle(controlled, yrot); controlled->pcmove->SetVelocity(vel); - + // Queue the new controlled position to the server. - networkmanager->QueueControlCommand(GetActor(), controlled ); + networkmanager->QueueControlCommand(GetActor(), controlled); } } } @@ -1263,9 +1264,9 @@ void NPC::CheckPosition() { // We only need to check the position once - - npcMesh *pcmesh = GetActor()->pcmesh; + npcMesh* pcmesh = GetActor()->pcmesh; + if(checked) { if(checkedPos == pcmesh->GetMesh()->GetMovable()->GetPosition() && checkedSector == pcmesh->GetMesh()->GetMovable()->GetSectors()->Get(0)) @@ -1288,7 +1289,7 @@ iSector* sector = pcmesh->GetMesh()->GetMovable()->GetSectors()->Get(0); // See what happens in the next 10 seconds int count = 100; - while (count--) + while(count--) { GetLinMove()->ExtrapolatePosition(0.1f); vel = GetLinMove()->GetVelocity(); @@ -1317,10 +1318,10 @@ void NPC::StoreSpawnPosition() { - psGameObject::GetPosition(GetActor(), spawnPosition, spawnSector ); + psGameObject::GetPosition(GetActor(), spawnPosition, spawnSector); } -const csVector3& NPC::GetSpawnPosition() const +const csVector3 &NPC::GetSpawnPosition() const { return spawnPosition; } @@ -1332,7 +1333,7 @@ void NPC::SetBufferMemory(Tribe::Memory* memory) { - if (bufferMemory == NULL) + if(bufferMemory == NULL) { bufferMemory = new Tribe::Memory(); } @@ -1350,7 +1351,7 @@ this->buildingSpot = buildingSpot; } - + /** Get the stored building spot for this NPC */ Tribe::Asset* NPC::GetBuildingSpot() @@ -1360,7 +1361,7 @@ -csString NPC::GetBuffer(const csString& bufferName) +csString NPC::GetBuffer(const csString &bufferName) { csString value = npcBuffer.Get(bufferName,""); @@ -1369,72 +1370,73 @@ return value; } -void NPC::SetBuffer(const csString& bufferName, const csString& value) +void NPC::SetBuffer(const csString &bufferName, const csString &value) { Printf(6,"Set Buffer(%s,%s)",bufferName.GetDataSafe(),value.GetDataSafe()); npcBuffer.PutUnique(bufferName,value); } -void NPC::ReplaceBuffers(csString& result) +void NPC::ReplaceBuffers(csString &result) { // Only replace if there is something to replace - if (result.Find("$NBUFFER[") == ((size_t)-1) ) return; + if(result.Find("$NBUFFER[") == ((size_t)-1)) return; BufferHash::GlobalIterator iter = npcBuffer.GetIterator(); - while (iter.HasNext()) + while(iter.HasNext()) { csString bufferName; csString value = iter.Next(bufferName); csString replace("$NBUFFER["); replace += bufferName; replace += "]"; - + result.ReplaceAll(replace,value); } } -void NPC::ReplaceLocations(csString& result) +void NPC::ReplaceLocations(csString &result) { size_t startPos,endPos; - + // Only replace if there is something to replace startPos = result.Find("$LOCATION["); - while (startPos != ((size_t)-1)) + while(startPos != ((size_t)-1)) { endPos = result.FindFirst(']',startPos); - if (endPos == ((size_t)-1)) return; // There should always be a ] after $LOCATION + if(endPos == ((size_t)-1)) return; // There should always be a ] after $LOCATION csString locationString = result.Slice(startPos+10,endPos-(startPos+10)); csArray<csString> strArr = psSplit(locationString,'.'); - if (strArr.GetSize() != 2) return; // Should always be a location and an attribute. - + if(strArr.GetSize() != 2) return; // Should always be a location and an attribute. + NPC::Locate* location = storedLocates.Get(strArr[0],NULL); - if (!location) + if(!location) { Error4("NPC %s(%s) Failed to find location %s in replace locations", GetName(),ShowID(GetEID()),strArr[0].GetDataSafe()); return; // Failed to find location } - + csString replace; - - if (strArr[1].CompareNoCase("targetEID")) + + if(strArr[1].CompareNoCase("targetEID")) { - if (location->target.IsValid()) + if(location->target.IsValid()) { replace = ShowID(location->target->GetEID()); } } - else if (strArr[1].CompareNoCase("targetName")) + else if(strArr[1].CompareNoCase("targetName")) { - if (location->target.IsValid()) + if(location->target.IsValid()) { replace = location->target->GetName(); } - } else + } + else { Error5("NPC %s(%s) Failed to find find attribute %s for location %s in replace locations", GetName(),ShowID(GetEID()),strArr[1].GetDataSafe(),strArr[0].GetDataSafe()); @@ -1475,8 +1477,8 @@ void HateList::AddHate(EID entity_id, float delta) { - HateListEntry *h = hatelist.Get(entity_id, 0); - if (!h) + HateListEntry* h = hatelist.Get(entity_id, 0); + if(!h) { h = new HateListEntry; h->entity_id = entity_id; @@ -1489,43 +1491,43 @@ } } -gemNPCActor *HateList::GetMostHated(csVector3& pos, iSector *sector, float range, LocationType * region, bool includeInvisible, bool includeInvincible, float* hate) +gemNPCActor* HateList::GetMostHated(csVector3 &pos, iSector* sector, float range, LocationType* region, bool includeInvisible, bool includeInvincible, float* hate) { - gemNPCObject *mostHated = NULL; + gemNPCObject* mostHated = NULL; float mostHateAmount=0.0; csArray<gemNPCObject*> list = npcclient->FindNearbyEntities(sector,pos,range); - for (size_t i=0; i<list.GetSize(); i++) + for(size_t i=0; i<list.GetSize(); i++) { - HateListEntry *h = hatelist.Get( list[i]->GetEID(),0 ); - if (h) + HateListEntry* h = hatelist.Get(list[i]->GetEID(),0); + if(h) { - gemNPCObject * obj = npcclient->FindEntityID(list[i]->GetEID()); + gemNPCObject* obj = npcclient->FindEntityID(list[i]->GetEID()); - if (!obj) continue; + if(!obj) continue; // Skipp if invisible or invincible - if (obj->IsInvisible() && !includeInvisible) continue; - if (obj->IsInvincible() && !includeInvincible) continue; - - if (!mostHated || h->hate_amount > mostHateAmount) + if(obj->IsInvisible() && !includeInvisible) continue; + if(obj->IsInvincible() && !includeInvincible) continue; + + if(!mostHated || h->hate_amount > mostHateAmount) { csVector3 objPos; iSector* objSector; psGameObject::GetPosition(obj, objPos, objSector); - + // Don't include if a region is defined and obj not within region. - if (region && !region->CheckWithinBounds(engine,objPos,objSector)) + if(region && !region->CheckWithinBounds(engine,objPos,objSector)) { continue; } - + mostHated = list[i]; mostHateAmount = h->hate_amount; } } } - if (hate) + if(hate) { *hate = mostHateAmount; } @@ -1544,28 +1546,28 @@ float HateList::GetHate(EID ent) { - HateListEntry *h = hatelist.Get(ent, 0); - if (h) + HateListEntry* h = hatelist.Get(ent, 0); + if(h) return h->hate_amount; else return 0; } -void HateList::DumpHateList(const csVector3& myPos, iSector *mySector) +void HateList::DumpHateList(const csVector3 &myPos, iSector* mySector) { csHash<HateListEntry*, EID>::GlobalIterator iter = hatelist.GetIterator(); CPrintf(CON_CMDOUTPUT, "%6s %5s %-40s %5s %s\n", "Entity","Hated","Pos","Range","Flags"); - while (iter.HasNext()) + while(iter.HasNext()) { - HateListEntry *h = (HateListEntry *)iter.Next(); + HateListEntry* h = (HateListEntry*)iter.Next(); csVector3 pos(9.9f,9.9f,9.9f); gemNPCObject* obj = npcclient->FindEntityID(h->entity_id); csString sectorName; - if (obj) + if(obj) { iSector* sector; psGameObject::GetPosition(obj,pos,sector); @@ -1577,11 +1579,11 @@ h->entity_id.Unbox(), h->hate_amount, toString(pos, sector).GetDataSafe(), world->Distance(pos,sector,myPos,mySector)); // Print flags - if (obj->IsInvisible()) + if(obj->IsInvisible()) { CPrintf(CON_CMDOUTPUT," Invisible"); } - if (obj->IsInvincible()) + if(obj->IsInvincible()) { CPrintf(CON_CMDOUTPUT," Invincible"); } Modified: trunk/src/npcclient/npc.h =================================================================== --- trunk/src/npcclient/npc.h 2012-12-11 00:59:44 UTC (rev 8501) +++ trunk/src/npcclient/npc.h 2012-12-11 01:12:04 UTC (rev 8502) @@ -1,7 +1,7 @@ /* * npc.h * -* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) +* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) * * * This program is free software; you can redistribute it and/or @@ -60,7 +60,7 @@ #define NPC_BRAIN_TICK 200 /** -* This object represents the entities which have attacked or +* This object represents the entities which have attacked or * hurt the NPC and prioritizes them. */ class HateList @@ -69,10 +69,15 @@ csHash<HateListEntry*, EID> hatelist; public: - HateList(psNPCClient* npcclient, iEngine* engine, psWorld* world) { this->npcclient = npcclient; this->engine = engine; this->world = world; } + HateList(psNPCClient* npcclient, iEngine* engine, psWorld* world) + { + this->npcclient = npcclient; + this->engine = engine; + this->world = world; + } void AddHate(EID entity_id, float delta); - + /** Find the most hated entity within range of given position * * Check the hate list and retrive most hated entity within range. @@ -85,12 +90,12 @@ * @param hate If diffrent from NULL, set upon return to the hate of the hated. * @return The hated entity */ - gemNPCActor *GetMostHated(csVector3& pos, iSector *sector, float range, LocationType * region, bool includeInvisible, bool includeInvincible, float* hate); + gemNPCActor* GetMostHated(csVector3 &pos, iSector* sector, float range, LocationType* region, bool includeInvisible, bool includeInvincible, float* hate); bool Remove(EID entity_id); - void DumpHateList(const csVector3& myPos, iSector *mySector); + void DumpHateList(const csVector3 &myPos, iSector* mySector); void Clear(); float GetHate(EID ent); - + private: psNPCClient* npcclient; iEngine* engine; @@ -132,18 +137,18 @@ typedef csHash<csString,csString> BufferHash; - NPCType *brain; + NPCType* brain; csString type; PID pid; csString name; csTicks last_update; - gemNPCActor *npcActor; - iMovable *movable; + gemNPCActor* npcActor; + iMovable* movable; uint8_t DRcounter; Locate* activeLocate; ///< The current "Active" locate LocateHash storedLocates; ///< List of stored locate locations - + float ang_vel,vel; float walkVelocity; float runVelocity; @@ -157,13 +162,13 @@ EID target_id; Tribe* tribe; - csString tribeMemberType; ///< What type/class is this NPC in the tribe. + csString tribeMemberType; ///< What type/class is this NPC in the tribe. bool insideTribeHome; ///< State variable for inside outside tribe home checks. - + csVector3 spawnPosition; ///< The stored position that this NPC where spawned iSector* spawnSector; ///< The stored sector that this NPC where spawned - RaceInfo_t *raceInfo; + RaceInfo_t* raceInfo; csArray< csWeakRef<gemNPCActor> > controlledActors; ///< Actors that are dragged/pushed around by this NPC. @@ -175,53 +180,77 @@ bool disabled; int fallCounter; // Incremented if the NPC fall off the map - + void Advance(csTicks when); public: HateList hatelist; - + NPC(psNPCClient* npcclient, NetworkManager* networkmanager, psWorld* world, iEngine* engine, iCollideSystem* cdsys); virtual ~NPC(); - + void Tick(); - - PID GetPID() { return pid; } + + PID GetPID() + { + return pid; + } /** * Return the entity ID if an entity exist else 0. */ EID GetEID(); - iMovable *GetMovable() { return movable; } - psLinearMovement *GetLinMove(); - uint8_t GetDRCounter() { return ++DRcounter;} - void SetDRCounter(uint8_t counter) { DRcounter = counter;} + iMovable* GetMovable() + { + return movable; + } + psLinearMovement* GetLinMove(); + uint8_t GetDRCounter() + { + return ++DRcounter; + } + void SetDRCounter(uint8_t counter) + { + DRcounter = counter; + } // Loads an NPC from one row of sc_npc_definitions, it also loads the corresponding brain. Used at boot time - bool Load(iResultRow& row,csHash<NPCType*, const char*>& npctypes, EventManager* eventmanager, PID usePID); + bool Load(iResultRow &row,csHash<NPCType*, const char*> &npctypes, EventManager* eventmanager, PID usePID); // Loads an NPC base information and his brain void Load(const char* name, PID pid, NPCType* type, const char* region_name, int debugging, bool disabled, EventManager* eventmanager); bool InsertCopy(PID use_char_id, PID ownerPID); - void SetActor(gemNPCActor * actor); - gemNPCActor * GetActor() { return npcActor; } - const char* GetName() {return name.GetDataSafe();} + void SetActor(gemNPCActor* actor); + gemNPCActor* GetActor() + { + return npcActor; + } + const char* GetName() + { + return name.GetDataSafe(); + } void SetAlive(bool a); - bool IsAlive() const { return alive; } + bool IsAlive() const + { + return alive; + } void Disable(bool disable = true); - bool IsDisabled() { return disabled; } + bool IsDisabled() + { + return disabled; + } - Behavior *GetCurrentBehavior(); - NPCType *GetBrain(); + Behavior* GetCurrentBehavior(); + NPCType* GetBrain(); /** * Sets a new brain (npctype) to this npc. * @param type The new type to assign to this npc. * @param eventmanager A pointer to the npcclient eventmanager. */ - void SetBrain(NPCType *type, EventManager* eventmanager); + void SetBrain(NPCType* type, EventManager* eventmanager); /** Callback for debug scope timers */ @@ -233,7 +262,7 @@ * and the "info <pid> npcclient console command. */ csString Info(); - + /** Dump all information for one NPC to the console. * * The main use of this fuction is the "print <pid>" @@ -278,8 +307,8 @@ * @param basePos The base position for range checks. * @param baseSector The base sector for range checks. * @param sameSector Only trigger if in same sector - */ - void TriggerEvent(Perception *pcpt, float maxRange=-1.0, + */ + void TriggerEvent(Perception* pcpt, float maxRange=-1.0, csVector3* basePos=NULL, iSector* baseSector=NULL, bool sameSector=false); @@ -290,10 +319,13 @@ * for the rest of the arguments */ void TriggerEvent(const char* pcpt); - - void SetLastPerception(Perception *pcpt); - Perception *GetLastPerception() { return last_perception; } + void SetLastPerception(Perception* pcpt); + Perception* GetLastPerception() + { + return last_perception; + } + /** Find the most hated entity within range of the NPC * * Check the hate list and retrive most hated entity within range. @@ -318,27 +350,27 @@ * @param hate If diffrent from NULL, set upon return to the hate of the hated. * @return The hated entity */ - gemNPCActor* GetMostHated(csVector3& pos, iSector *sector, float range, LocationType * region, bool includeInvisible, bool includeInvincible, float* hate); + gemNPCActor* GetMostHated(csVector3 &pos, iSector* sector, float range, LocationType* region, bool includeInvisible, bool includeInvincible, float* hate); - - float GetEntityHate(gemNPCActor *ent); - void AddToHateList(gemNPCActor *attacker,float delta); + + float GetEntityHate(gemNPCActor* ent); + void AddToHateList(gemNPCActor* attacker,float delta); void RemoveFromHateList(EID who); /** Set the NPCs locate. */ - void SetLocate(const csString& destination, const NPC::Locate& locate ); + void SetLocate(const csString &destination, const NPC::Locate &locate); /** Get the NPCs current active locate. */ - void GetActiveLocate(csVector3& pos, iSector*& sector, float& rot); + void GetActiveLocate(csVector3 &pos, iSector* §or, float &rot); /** Return the wp of the current active locate. * * @param wp will be set with the wp currently in the active locate. */ - void GetActiveLocate(Waypoint*& wp); - + void GetActiveLocate(Waypoint* &wp); + /** Get the radius of the last locate operatoins * * @return The radius of the last locate @@ -353,45 +385,54 @@ /** Replace $LOCATION[<location>.<attribute>] */ - void ReplaceLocations(csString& result); + void ReplaceLocations(csString &result); /** Switch the debuging state of this NPC. */ bool SwitchDebugging(); - + /** Set a new debug level for this NPC. * @param debug New debug level, 0 is no debugging */ void SetDebugging(int debug); - + /** Add a client to receive debug information * @param clentnum The client to add. */ void AddDebugClient(uint clientnum); - + /** Remove client from list of debug receivers. * @param clentnum The client to remove. */ void RemoveDebugClient(uint clientnum); - + float GetAngularVelocity(); float GetVelocity(); float GetWalkVelocity(); float GetRunVelocity(); - csString& GetRegionName() { return region_name; } - LocationType *GetRegion(); + csString &GetRegionName() + { + return region_name; + } + LocationType* GetRegion(); /** Check the inside region state of the npc. * */ - bool IsInsideRegion() { return insideRegion; } - + bool IsInsideRegion() + { + return insideRegion; + } + /** Set the inside region state * * Keep track of last perception for inbound our, outbound */ - void SetInsideRegion(bool inside) { insideRegion = inside; } + void SetInsideRegion(bool inside) + { + insideRegion = inside; + } /** Return the nearest actor within the given range. @@ -422,19 +463,19 @@ gemNPCActor* GetNearestPlayer(float range, csVector3 &destPosition, iSector* &destSector, float &destRange); gemNPCActor* GetNearestVisibleFriend(float range); - + gemNPCActor* GetNearestDeadActor(float range); - void Printf(const char *msg,...); - void Printf(int debug, const char *msg,...); - void VPrintf(int debug, const char *msg,va_list arg); + void Printf(const char* msg,...); + void Printf(int debug, const char* msg,...); + void VPrintf(int debug, const char* msg,va_list arg); - gemNPCObject *GetTarget(); - void SetTarget(gemNPCObject *t); + gemNPCObject* GetTarget(); + void SetTarget(gemNPCObject* t); - gemNPCObject *GetOwner(); + gemNPCObject* GetOwner(); const char* GetOwnerName(); - + /** Sets the owner of this npc. The server will send us the owner of * the entity connected to it so we can follow it's directions. * @param owner_EID the eid of the entity who owns this npc. @@ -442,37 +483,43 @@ void SetOwner(EID owner_EID); /** Set a new tribe for this npc */ - void SetTribe(Tribe * new_tribe); - + void SetTribe(Tribe* new_tribe); + /** Get the tribe this npc belongs to. * * @return Null if not part of a tribe */ - Tribe * GetTribe(); + Tribe* GetTribe(); /** Set the type/class for this npc in a tribe. */ - void SetTribeMemberType( const char* tribeMemberType ); + void SetTribeMemberType(const char* tribeMemberType); /** Return the type/class for this NPC's tribe membership if any. */ - const csString& GetTribeMemberType() const; + const csString &GetTribeMemberType() const; /** Check the inside tribe home state of the npc. * */ - bool IsInsideTribeHome() { return insideTribeHome; } - + bool IsInsideTribeHome() + { + return insideTribeHome; + } + /** Set the inside tribe home state * * Keep track of last perception for inbound our, outbound */ - void SetInsideTribeHome(bool inside) { insideTribeHome = inside; } + void SetInsideTribeHome(bool inside) + { + insideTribeHome = inside; + } /** Get the npc race info */ - RaceInfo_t * GetRaceInfo(); - + RaceInfo_t* GetRaceInfo(); + /** Take control of another entity. */ void TakeControl(gemNPCActor* actor); @@ -485,8 +532,14 @@ */ void UpdateControlled(); - bool IsDebugging() { return (debugging > 0);}; - bool IsDebugging(int debug) { return (debugging > 0 && debug <= debugging);}; + bool IsDebugging() + { + return (debugging > 0); + }; + bool IsDebugging(int debug) + { + return (debugging > 0 && debug <= debugging); + }; void CheckPosition(); @@ -496,25 +549,31 @@ * spawn position. */ void StoreSpawnPosition(); - + /** Return the position part of the spawn position */ - const csVector3& GetSpawnPosition() const; + const csVector3 &GetSpawnPosition() const; /** Return the sector part of the spawn position */ iSector* GetSpawnSector() const; - /** Increment the fall counter + /** Increment the fall counter * * Fall counter is used for debugging. */ - void IncrementFallCounter() { ++fallCounter; } + void IncrementFallCounter() + { + ++fallCounter; + } - /** Return the fall counter + /** Return the fall counter * * Fall counter is used for debugging. */ - int GetFallCounter() { return fallCounter; } + int GetFallCounter() + { + return fallCounter; + } /** Return a named buffer from the NPC. * @@ -523,26 +582,29 @@ * @param The buffer name. * @return The content of the named buffer. */ - csString GetBuffer(const csString& bufferName); + csString GetBuffer(const csString &bufferName); /** Set/Update the value of a named buffer. * * @param The buffer name. * @param The value to put in the buffer. */ - void SetBuffer(const csString& bufferName, const csString& value); + void SetBuffer(const csString &bufferName, const csString &value); /** Replace $NBUFFER[x] with values from the NPC buffer. * * @param result String to replace buffers in. */ - void ReplaceBuffers(csString& result); + void ReplaceBuffers(csString &result); - Tribe::Memory* GetBufferMemory() { return bufferMemory; } + Tribe::Memory* GetBufferMemory() + { + return bufferMemory; + } void SetBufferMemory(Tribe::Memory* memory); /** Set a building spot for this NPC */ void SetBuildingSpot(Tribe::Asset* buildingSpot); - + /** Get the stored building spot for this NPC */ Tribe::Asset* GetBuildingSpot(); @@ -557,7 +619,7 @@ BufferHash npcBuffer; ///< Used to store dynamic data Tribe::Memory* bufferMemory; ///< Used to store location data Tribe::Asset* buildingSpot; ///< Used to store current building spot. - + friend class psNPCTick; csArray<csString> debugLog; ///< Local debug log of last n print statments for this NPC. @@ -569,18 +631,21 @@ class psNPCTick : public psGameEvent { protected: - NPC *npc; + NPC* npc; public: - psNPCTick(int offsetticks, NPC *npc): psGameEvent(0,offsetticks,"psNPCTick"), npc(npc) {}; + psNPCTick(int offsetticks, NPC* npc): psGameEvent(0,offsetticks,"psNPCTick"), npc(npc) {}; virtual void Trigger() { - npc->tick = NULL; - npc->Tick(); + npc->tick = NULL; + npc->Tick(); } - virtual csString ToString() const { return "psNPCTick"; } + virtual csString ToString() const + { + return "psNPCTick"; + } }; struct HateListEntry Modified: trunk/src/npcclient/npcclient.cpp =================================================================== --- trunk/src/npcclient/npcclient.cpp 2012-12-11 00:59:44 UTC (rev 8501) +++ trunk/src/npcclient/npcclient.cpp 2012-12-11 01:12:04 UTC (rev 8502) @@ -1,7 +1,7 @@ /* * npcclient.cpp - author: Keith Fulton <ke...@pa...> * -* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) +* Copyright (C) 2003 Atomic Blue (in...@pl..., http://www.atomicblue.org) * * * This program is free software; you can redistribute it and/or @@ -74,22 +74,22 @@ #include "status.h" bool running; -extern iDataConnection *db; +extern iDataConnection* db; class psNPCClientTick : public psGameEvent { protected: - static psNPCClient *client; + static psNPCClient* client; public: - psNPCClientTick(int offsetticks, psNPCClient *c); + psNPCClientTick(int offsetticks, psNPCClient* c); virtual void Trigger(); // Abstract event processing function virtual csString ToString() const; }; psNPCClient* psNPCClient::npcclient = NULL; -psNPCClient::psNPCClient () : serverconsole(NULL) +psNPCClient::psNPCClient() : serverconsole(NULL) { npcclient = this; // Static pointer to self world = NULL; @@ -108,17 +108,17 @@ psNPCClient::~psNPCClient() { - + csArray<NPC*>::Iterator npcIter(npcs.GetIterator()); - while (npcIter.HasNext()) + while(npcIter.HasNext()) delete npcIter.Next(); npcs.Empty(); csHash<NPCType*, const char*>::GlobalIterator npcTypeIter(npctypes.GetIterator()); - while (npcTypeIter.HasNext()) + while(npcTypeIter.HasNext()) delete npcTypeIter.Next(); npctypes.Empty(); @@ -139,21 +139,21 @@ delete recipemanager; } -bool psNPCClient::Initialize(iObjectRegistry* object_reg,const char *_host, const char *_user, const char *_pass, int _port) +bool psNPCClient::Initialize(iObjectRegistry* object_reg,const char* _host, const char* _user, const char* _pass, int _port) { objreg = object_reg; configmanager = csQueryRegistry<iConfigManager> (object_reg); - if (!configmanager) + if(!configmanager) { - CPrintf (CON_ERROR, "Couldn't find Configmanager!\n"); + CPrintf(CON_ERROR, "Couldn't find Configmanager!\n"); return false; } engine = csQueryRegistry<iEngine> (object_reg); - if (!engine) + if(!engine) { - CPrintf (CON_ERROR, "Couldn't find Engine!\n"); + CPrintf(CON_ERROR, "Couldn't find Engine!\n"); return false; } @@ -175,9 +175,9 @@ db_port = configmanager->GetInt("PlaneShift.Database.npcport", 0); Debug4(LOG_STARTUP,0,COL_BLUE "Database Host: '%s' User: '%s' Databasename: '%s'\n" COL_NORMAL, - (const char*) db_host, (const char*) db_user, (co... [truncated message content] |