diff options
author | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-12-26 19:20:00 +0100 |
---|---|---|
committer | lapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-12-26 19:20:00 +0100 |
commit | 92e0ba66459af6a5ac7ef53fb24a681db100f901 (patch) | |
tree | a0a882edd2337178634701141856bc9c131f342c | |
parent | GameMode Switch added to Core Functions (/gm 0 | /gm 1) needs permission core.changegm (diff) | |
download | cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar.gz cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar.bz2 cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar.lz cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar.xz cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.tar.zst cuberite-92e0ba66459af6a5ac7ef53fb24a681db100f901.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cMonster.cpp | 74 | ||||
-rw-r--r-- | source/cMonster.h | 2 |
2 files changed, 46 insertions, 30 deletions
diff --git a/source/cMonster.cpp b/source/cMonster.cpp index 217cd5367..2f7567b15 100644 --- a/source/cMonster.cpp +++ b/source/cMonster.cpp @@ -154,6 +154,12 @@ void cMonster::Tick(float a_Dt) Distance *= 3;
m_Speed->x = Distance.x;
m_Speed->z = Distance.z;
+
+ if (m_EMState == ESCAPING)
+ { //Runs Faster when escaping :D otherwise they just walk away
+ m_Speed->x *= 2.f;
+ m_Speed->z *= 2.f;
+ }
}
else
{
@@ -383,7 +389,12 @@ void cMonster::SetState(const char* a_str) //monster sez: Do I see the player
void cMonster::CheckEventSeePlayer()
{
- cMonster::ListClosePlayers(this);
+ cPlayer *Closest = FindClosestPlayer();
+
+ if(Closest)
+ {
+ EventSeePlayer(Closest);
+ }
}
void cMonster::CheckEventLostPlayer()
@@ -423,7 +434,7 @@ void cMonster::InStateIdle(float a_Dt) { MTRand r1;
int rem = r1.randInt()%6 + 1;
//LOG("Moving: int: %3.3f rem: %i",idle_interval,rem);
- idle_interval = 0;
+ idle_interval -= 1; //So nothing gets dropped when the server hangs for a few seconds
Vector3f Dist;
Dist.x = (float)((r1.randInt()%11)-5);
Dist.z = (float)((r1.randInt()%11)-5);
@@ -444,7 +455,7 @@ void cMonster::InStateBurning(float a_Dt) { char bblock = GetWorld()->GetBlock( (int)m_Pos->x, (int)m_Pos->y +1, (int)m_Pos->z );
if(m_FireDamageInterval > 1) {
- m_FireDamageInterval = 0;
+ m_FireDamageInterval -= 1;
TakeDamage(1, this);
m_BurnPeriod++;
@@ -527,42 +538,47 @@ void cMonster::ListMonsters() { cRoot::Get()->GetWorld()->UnlockEntities();
}
-//Checks for Players close by and if they are visible
-void cMonster::ListClosePlayers(cMonster *m) {
- int tries = 0;
- cTracer LineOfSight(cRoot::Get()->GetWorld() );
- cWorld::EntityList Entities = cRoot::Get()->GetWorld()->GetEntities();
- for( cWorld::EntityList::iterator itr = Entities.begin(); itr != Entities.end(); ++itr) {
- tries++;
- if((*itr)->GetEntityType() == cEntity::E_PLAYER){
- Vector3f pos = (*itr)->GetPosition();
- if((pos - *(m->m_Pos)).Length() <= m->m_SightDistance){
- if(!LineOfSight.Trace(*(m->m_Pos),(pos - *(m->m_Pos)),(int)(pos - *(m->m_Pos)).Length()))
- {
- m->EventSeePlayer(*itr);
- return; //get the first one in sight later we can reiterate and check
- //for the closest out of all that match and make it more realistic
-
- }
- }
-
- }
- if(tries > 100)
+//Checks for Players close by and if they are visible return the closest
+cPlayer *cMonster::FindClosestPlayer()
+{
+ cTracer LineOfSight(cRoot::Get()->GetWorld());
+ cWorld::PlayerList Players = cRoot::Get()->GetWorld()->GetAllPlayers();
+
+ float ClosestDistance = m_SightDistance + 1.f; //Something that is higher than the max :D
+ cPlayer* ClosestPlayer = 0;
+
+ for( cWorld::PlayerList::iterator itr = Players.begin(); itr != Players.end(); ++itr)
+ {
+ Vector3f Pos = (*itr)->GetPosition();
+ float Distance = (Pos - *(m_Pos)).Length();
+
+ if(Distance <= m_SightDistance)
{
- m->EventLosePlayer();
- return;
+ if(!LineOfSight.Trace(*(m_Pos),(Pos - *(m_Pos)),(int)(Pos - *(m_Pos)).Length()))
+ {
+ if(Distance < ClosestDistance)
+ {
+ ClosestDistance = Distance;
+ ClosestPlayer = *itr;
+ }
+ }
}
}
+ return ClosestPlayer;
}
-void cMonster::GetMonsterConfig(const char* pm_name) {
+void cMonster::GetMonsterConfig(const char* pm_name)
+{
cRoot::Get()->GetMonsterConfig()->Get()->AssignAttributes(this, pm_name);
}
-void cMonster::SetAttackRate(int ar) {
+void cMonster::SetAttackRate(int ar)
+{
m_AttackRate = (float)ar;
}
-void cMonster::SetAttackRange(float ar) {
+
+void cMonster::SetAttackRange(float ar)
+{
m_AttackRange = ar;
}
void cMonster::SetAttackDamage(float ad) {
diff --git a/source/cMonster.h b/source/cMonster.h index 6523c2e52..90340311e 100644 --- a/source/cMonster.h +++ b/source/cMonster.h @@ -35,7 +35,7 @@ public: virtual void CheckEventSeePlayer();
virtual void EventSeePlayer(cEntity *);
float m_SightDistance;
- static void ListClosePlayers(cMonster *);
+ virtual cPlayer *FindClosestPlayer(); //non static is easier. also virtual so other mobs can implement their own searching algo
virtual void GetMonsterConfig(const char* pm_name);
virtual void EventLosePlayer();
virtual void CheckEventLostPlayer();
|