mirror of
https://gitea.sffnetwork.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-11-24 19:39:47 +00:00
the whole game
This commit is contained in:
parent
816e9060b4
commit
f0617a5d22
2069 changed files with 581500 additions and 0 deletions
57
src/world/entity/ai/goal/BreakDoorGoal.h
Executable file
57
src/world/entity/ai/goal/BreakDoorGoal.h
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__BreakDoorGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__BreakDoorGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity->ai.goal;
|
||||
|
||||
#include "DoorInteractGoal.h"
|
||||
|
||||
#include "../../Entity.h"
|
||||
#include "../../../level/tile/LevelEvent.h"
|
||||
#include "../../../level/Level.h"
|
||||
#include "../../../level/tile/DoorTile.h"
|
||||
#include "../../../../SharedConstants.h"
|
||||
|
||||
class BreakDoorGoal: public DoorInteractGoal
|
||||
{
|
||||
typedef DoorInteractGoal super;
|
||||
public:
|
||||
BreakDoorGoal(Monster* mob)
|
||||
: super(mob)
|
||||
{}
|
||||
|
||||
bool canUse() {
|
||||
if (!super::canUse()) return false;
|
||||
return !doorTile->isOpen(mob->level, doorX, doorY, doorZ);
|
||||
}
|
||||
|
||||
void start() {
|
||||
super::start();
|
||||
breakTime = SharedConstants::TicksPerSecond * 12;
|
||||
}
|
||||
|
||||
bool canContinueToUse() {
|
||||
float d = mob->distanceToSqr((float)doorX, (float)doorY, (float)doorZ);
|
||||
return breakTime >= 0 && !doorTile->isOpen(mob->level, doorX, doorY, doorZ) && d < 2 * 2;
|
||||
}
|
||||
|
||||
void tick() {
|
||||
super::tick();
|
||||
if (mob->random.nextInt(20) == 0) {
|
||||
//mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_WOODEN_DOOR, doorX, doorY, doorZ, 0);
|
||||
}
|
||||
|
||||
//LOGI("time: %d\n", breakTime);
|
||||
|
||||
if (--breakTime == 0) {
|
||||
/*if (mob->level->difficulty == Difficulty.HARD)*/ {
|
||||
mob->level->setTile(doorX, doorY, doorZ, 0);
|
||||
//mob->level->levelEvent(LevelEvent::SOUND_ZOMBIE_DOOR_CRASH, doorX, doorY, doorZ, 0);
|
||||
//mob->level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, doorX, doorY, doorZ, doorTile->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
int breakTime;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__BreakDoorGoal_H__*/
|
||||
79
src/world/entity/ai/goal/DoorInteractGoal.h
Executable file
79
src/world/entity/ai/goal/DoorInteractGoal.h
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__DoorInteractGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__DoorInteractGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity.ai.goal;
|
||||
|
||||
#include "Goal.h"
|
||||
|
||||
#include "../PathNavigation.h"
|
||||
#include "../../monster/Monster.h"
|
||||
#include "../../../level/pathfinder/Path.h"
|
||||
#include "../../../level/tile/DoorTile.h"
|
||||
|
||||
class DoorInteractGoal: public Goal
|
||||
{
|
||||
public:
|
||||
DoorInteractGoal(Monster* mob)
|
||||
: mob(mob)
|
||||
{}
|
||||
|
||||
bool canUse() {
|
||||
if (!mob->horizontalCollision) return false;
|
||||
PathNavigation* pathNav = mob->getNavigation();
|
||||
Path* path = pathNav->getPath();
|
||||
if (path == NULL || path->isDone() || !pathNav->canOpenDoors)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < Mth::Min(path->getIndex() + 2, path->getSize()); ++i) {
|
||||
Node* n = path->get(i);
|
||||
doorX = n->x;
|
||||
doorY = n->y + 1;
|
||||
doorZ = n->z;
|
||||
if (mob->distanceToSqr((float)doorX, mob->y, (float)doorZ) > 1.5f * 1.5f) continue;
|
||||
doorTile = getDoorTile(doorX, doorY, doorZ);
|
||||
if (doorTile == NULL) continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
doorX = Mth::floor(mob->x);
|
||||
doorY = Mth::floor(mob->y + 1);
|
||||
doorZ = Mth::floor(mob->z);
|
||||
doorTile = getDoorTile(doorX, doorY, doorZ);
|
||||
return doorTile != NULL;
|
||||
}
|
||||
|
||||
bool canContinueToUse() {
|
||||
return !passed;
|
||||
}
|
||||
|
||||
void start() {
|
||||
passed = false;
|
||||
doorOpenDirX = doorX + 0.5f - mob->x;
|
||||
doorOpenDirZ = doorZ + 0.5f - mob->z;
|
||||
}
|
||||
|
||||
void tick() {
|
||||
float newDoorDirX = doorX + 0.5f - mob->x;
|
||||
float newDoorDirZ = doorZ + 0.5f - mob->z;
|
||||
float dot = doorOpenDirX * newDoorDirX + doorOpenDirZ * newDoorDirZ;
|
||||
if (dot < 0) {
|
||||
passed = true;
|
||||
}
|
||||
}
|
||||
private:
|
||||
DoorTile* getDoorTile(int x, int y, int z) {
|
||||
int tileId = mob->level->getTile(x, y, z);
|
||||
if (tileId != Tile::door_wood->id) return NULL;
|
||||
DoorTile* doorTile = (DoorTile*) Tile::tiles[tileId];
|
||||
return doorTile;
|
||||
}
|
||||
protected:
|
||||
Monster* mob;
|
||||
int doorX, doorY, doorZ;
|
||||
DoorTile* doorTile;
|
||||
private:
|
||||
bool passed;
|
||||
float doorOpenDirX, doorOpenDirZ;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__DoorInteractGoal_H__*/
|
||||
44
src/world/entity/ai/goal/Goal.h
Executable file
44
src/world/entity/ai/goal/Goal.h
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__Goal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__Goal_H__
|
||||
|
||||
//package net.minecraft.world.entity.ai.goal;
|
||||
|
||||
class Goal
|
||||
{
|
||||
public:
|
||||
Goal()
|
||||
: _requiredControlFlags(0)
|
||||
{}
|
||||
virtual ~Goal() {}
|
||||
|
||||
virtual bool canUse() = 0;
|
||||
|
||||
virtual bool canContinueToUse() {
|
||||
return canUse();
|
||||
}
|
||||
|
||||
virtual bool canInterrupt() {
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void start() {
|
||||
}
|
||||
|
||||
virtual void stop() {
|
||||
}
|
||||
|
||||
virtual void tick() {
|
||||
}
|
||||
|
||||
void setRequiredControlFlags(int requiredControlFlags) {
|
||||
_requiredControlFlags = requiredControlFlags;
|
||||
}
|
||||
|
||||
int getRequiredControlFlags() {
|
||||
return _requiredControlFlags;
|
||||
}
|
||||
private:
|
||||
int _requiredControlFlags;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__Goal_H__*/
|
||||
104
src/world/entity/ai/goal/GoalSelector.h
Executable file
104
src/world/entity/ai/goal/GoalSelector.h
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__GoalSelector_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__GoalSelector_H__
|
||||
|
||||
//package net.minecraft.world.entity.ai.goal;
|
||||
|
||||
#include "Goal.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class GoalSelector
|
||||
{
|
||||
class InternalGoal {
|
||||
public:
|
||||
InternalGoal(short prio, Goal* goal)
|
||||
: prio(prio),
|
||||
goal(goal),
|
||||
isUsing(false)
|
||||
{}
|
||||
|
||||
Goal* goal;
|
||||
short prio;
|
||||
bool isUsing;
|
||||
};
|
||||
public:
|
||||
~GoalSelector() {
|
||||
for (unsigned int i = 0; i < goals.size(); ++i) {
|
||||
delete goals[i].goal;
|
||||
}
|
||||
}
|
||||
|
||||
void addGoal(int prio, Goal* goal) {
|
||||
goals.push_back(InternalGoal(prio, goal));
|
||||
}
|
||||
|
||||
void tick() {
|
||||
std::vector<InternalGoal> toStart;
|
||||
|
||||
for (std::vector<InternalGoal>::iterator it = goals.begin(); it != goals.end(); ++it) {
|
||||
InternalGoal& ig = *it;
|
||||
bool isUsing = ig.isUsing; //usingGoals.contains(ig);
|
||||
|
||||
if (isUsing) {
|
||||
if (!canUseInSystem(ig) || !ig.goal->canContinueToUse()) {
|
||||
ig.goal->stop();
|
||||
ig.isUsing = false;
|
||||
//usingGoals.remove(ig);
|
||||
} else continue;
|
||||
}
|
||||
|
||||
if (!canUseInSystem(ig) || !ig.goal->canUse()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
toStart.push_back(ig);
|
||||
//usingGoals.add(ig);
|
||||
ig.isUsing = true;
|
||||
}
|
||||
|
||||
//bool debug = false;
|
||||
//if (debug && toStart.size() > 0) printf("Starting: ");
|
||||
for (std::vector<InternalGoal>::iterator it = toStart.begin(); it != toStart.end(); ++it) {
|
||||
InternalGoal& ig = *it;
|
||||
//if (debug) printf(" %s, ", ig.goal.toString() + ", ");
|
||||
ig.goal->start();
|
||||
}
|
||||
|
||||
//if (debug && usingGoals.size() > 0) printf("Running: ");
|
||||
for (std::vector<InternalGoal>::iterator it = goals.begin(); it != goals.end(); ++it) {
|
||||
InternalGoal& ig = *it;
|
||||
if (ig.isUsing) {
|
||||
//if (debug) printf(" %s\n", ig.goal.toString());
|
||||
ig.goal->tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//std::vector<InternalGoal>& getRunningGoals() {
|
||||
// return usingGoals;
|
||||
//}
|
||||
private:
|
||||
bool canUseInSystem(InternalGoal& goal) {
|
||||
for (std::vector<InternalGoal>::iterator it = goals.begin(); it != goals.end(); ++it) {
|
||||
InternalGoal& ig = *it;
|
||||
if (ig.goal == goal.goal && ig.prio == goal.prio)
|
||||
continue;
|
||||
if (goal.prio >= ig.prio) {
|
||||
if (ig.isUsing && !canCoExist(goal, ig))
|
||||
return false;
|
||||
} else if (ig.isUsing && !ig.goal->canInterrupt())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool canCoExist(InternalGoal& goalA, InternalGoal& goalB) {
|
||||
return (goalA.goal->getRequiredControlFlags() & goalB.goal->getRequiredControlFlags()) == 0;
|
||||
}
|
||||
|
||||
std::vector<InternalGoal> goals;
|
||||
//std::vector<InternalGoal> usingGoals;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__GoalSelector_H__*/
|
||||
94
src/world/entity/ai/goal/MeleeAttackGoal.h
Executable file
94
src/world/entity/ai/goal/MeleeAttackGoal.h
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__MeleeAttackGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__MeleeAttackGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity.ai.goal;
|
||||
|
||||
#include "Goal.h"
|
||||
|
||||
#include "../control/Control.h"
|
||||
#include "../../monster/Monster.h"
|
||||
#include "../../../level/Level.h"
|
||||
#include "../../../level/pathfinder/Path.h"
|
||||
#include "../Sensing.h"
|
||||
|
||||
class MeleeAttackGoal: public Goal
|
||||
{
|
||||
public:
|
||||
MeleeAttackGoal(Monster* mob, float speed, bool trackTarget, int attackType = 0)
|
||||
: mob(mob),
|
||||
level(mob->level),
|
||||
speed(speed),
|
||||
trackTarget(trackTarget),
|
||||
attackTime(0),
|
||||
attackType(attackType),
|
||||
path(NULL)
|
||||
{
|
||||
setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
|
||||
}
|
||||
~MeleeAttackGoal() {
|
||||
if (path) {
|
||||
LOGI("mag-deleting %p (%d)\n", path, path->id);
|
||||
delete path;
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override*/
|
||||
bool canUse() {
|
||||
Mob* bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if (attackType != 0 && !mob->isPlayer()) return false; //!attackType.isAssignableFrom(bestTarget.getClass())) return false;
|
||||
target = bestTarget;
|
||||
if (path) {
|
||||
LOGI("mag-canuse-deleting %p (%d)\n", path, path->id);
|
||||
delete path;
|
||||
}
|
||||
path = mob->getNavigation()->createPath(target);
|
||||
return path != NULL;
|
||||
}
|
||||
|
||||
bool canContinueToUse() {
|
||||
Mob* bestTarget = mob->getTarget();
|
||||
if (bestTarget == NULL) return false;
|
||||
if (attackType != 0 && !mob->isPlayer()) return false;//!attackType.isAssignableFrom(bestTarget.getClass())) return false;
|
||||
target = bestTarget;
|
||||
if (!trackTarget) return !mob->getNavigation()->isDone();
|
||||
return true;
|
||||
}
|
||||
|
||||
void start() {
|
||||
mob->getNavigation()->moveTo(path, speed, false);
|
||||
}
|
||||
|
||||
void stop() {
|
||||
target = NULL;
|
||||
mob->getNavigation()->stop();
|
||||
}
|
||||
|
||||
void tick() {
|
||||
//mob->getLookControl().setLookAt(target, 30, 30);
|
||||
if (trackTarget || mob->sensing->canSee(target)) {
|
||||
//LOGI("target: %p @ %f, %f, %f\n", target, target->x, target->y, target->z);
|
||||
mob->getNavigation()->moveTo(target, speed);
|
||||
}
|
||||
|
||||
attackTime = Mth::Max(attackTime - 1, 0);
|
||||
|
||||
float meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
|
||||
if (mob->distanceToSqr(target->x, target->bb.y0, target->z) > meleeRadiusSqr) return;
|
||||
if (attackTime > 0) return;
|
||||
attackTime = 20;
|
||||
mob->doHurtTarget(target);
|
||||
}
|
||||
|
||||
private:
|
||||
Level* level;
|
||||
Monster* mob;
|
||||
Mob* target;
|
||||
int attackTime;
|
||||
float speed;
|
||||
Path* path;
|
||||
int attackType;
|
||||
bool trackTarget;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__MeleeAttackGoal_H__*/
|
||||
54
src/world/entity/ai/goal/RandomStrollGoal.h
Executable file
54
src/world/entity/ai/goal/RandomStrollGoal.h
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__RandomStrollGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__RandomStrollGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity.ai.goal;
|
||||
|
||||
#include "Goal.h"
|
||||
|
||||
#include "../../../../SharedConstants.h"
|
||||
#include "../../PathfinderMob.h"
|
||||
#include "../control/Control.h"
|
||||
#include "../util/RandomPos.h"
|
||||
#include "../../../phys/Vec3.h"
|
||||
#include "../util/RandomPos.h"
|
||||
|
||||
class RandomStrollGoal: public Goal
|
||||
{
|
||||
public:
|
||||
RandomStrollGoal(PathfinderMob* mob, float speed)
|
||||
: mob(mob),
|
||||
speed(speed)
|
||||
{
|
||||
setRequiredControlFlags(Control::MoveControlFlag);
|
||||
}
|
||||
|
||||
/*@Override*/
|
||||
bool canUse() {
|
||||
if (mob->getNoActionTime() >= SharedConstants::TicksPerSecond * 5) return false;
|
||||
if (mob->random.nextInt(120) != 0) return false;
|
||||
|
||||
Vec3 pos;
|
||||
if (!RandomPos::getPos(pos, mob, 10, 7)) return false;
|
||||
wantedX = pos.x;
|
||||
wantedY = pos.y;
|
||||
wantedZ = pos.z;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*@Override*/
|
||||
bool canContinueToUse() {
|
||||
return !mob->getNavigation()->isDone();
|
||||
}
|
||||
|
||||
/*@Override*/
|
||||
void start() {
|
||||
mob->getNavigation()->moveTo(wantedX, wantedY, wantedZ, speed);
|
||||
}
|
||||
|
||||
private:
|
||||
PathfinderMob* mob;
|
||||
float wantedX, wantedY, wantedZ;
|
||||
float speed;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL__RandomStrollGoal_H__*/
|
||||
41
src/world/entity/ai/goal/target/HurtByTargetGoal.h
Executable file
41
src/world/entity/ai/goal/target/HurtByTargetGoal.h
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__HurtByTargetGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__HurtByTargetGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity->ai.goal.target;
|
||||
|
||||
#include "TargetGoal.h"
|
||||
#include "../../../../phys/AABB.h"
|
||||
|
||||
class HurtByTargetGoal: public TargetGoal
|
||||
{
|
||||
typedef TargetGoal super;
|
||||
public:
|
||||
HurtByTargetGoal(Monster* mob, bool alertSameType)
|
||||
: super(mob, 16, false),
|
||||
alertSameType(alertSameType)
|
||||
{
|
||||
setRequiredControlFlags(TargetGoal::TargetFlag);
|
||||
}
|
||||
|
||||
bool canUse() {
|
||||
return canAttack(mob->getLastHurtByMob(), true);
|
||||
}
|
||||
|
||||
void start() {
|
||||
mob->setTarget(mob->getLastHurtByMob());
|
||||
|
||||
// if (alertSameType) {
|
||||
// List<Entity> nearby = mob.level->getEntitiesOfClass(mob.getClass(), AABB.newTemp(mob.x, mob.y, mob.z, mob.x + 1, mob.y + 1, mob.z + 1).grow(within, 4, within));
|
||||
// for (Entity* ent : nearby) {
|
||||
// Mob other = (Mob) ent;
|
||||
// if (this->mob == other) continue;
|
||||
// if (other.getTarget() != NULL) continue;
|
||||
// other.setTarget(mob.getLastHurtByMob());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
private:
|
||||
bool alertSameType;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__HurtByTargetGoal_H__*/
|
||||
42
src/world/entity/ai/goal/target/NearestAttackableTargetGoal.h
Executable file
42
src/world/entity/ai/goal/target/NearestAttackableTargetGoal.h
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__NearestAttackableTargetGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__NearestAttackableTargetGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity->ai.goal.target;
|
||||
|
||||
/* import net.minecraft.world.entity->* */
|
||||
#include "TargetGoal.h"
|
||||
#include "../../../player/Player.h"
|
||||
|
||||
|
||||
class NearestAttackableTargetGoal: public TargetGoal
|
||||
{
|
||||
typedef TargetGoal super;
|
||||
public:
|
||||
NearestAttackableTargetGoal(Monster* mob, int targetType, float within, int randomInterval, bool mustSee)
|
||||
: super(mob, within, mustSee),
|
||||
targetType(targetType),
|
||||
randomInterval(randomInterval)
|
||||
{
|
||||
setRequiredControlFlags(TargetGoal::TargetFlag);
|
||||
}
|
||||
|
||||
bool canUse() {
|
||||
if (randomInterval > 0 && mob->random.nextInt(randomInterval) != 0) return false;
|
||||
Mob* potentialTarget = NULL;
|
||||
if (targetType == 1) potentialTarget = mob->level->getNearestPlayer(mob, within); //@todo: targetType
|
||||
//else potentialTarget = (Mob*) mob->level->getClosestEntityOfClass(targetType, mob->bb.grow(within, 4, within), mob);
|
||||
if (!canAttack(potentialTarget, false)) return false;
|
||||
target = potentialTarget;
|
||||
return true;
|
||||
}
|
||||
|
||||
void start() {
|
||||
mob->setTarget(target);
|
||||
}
|
||||
private:
|
||||
Mob* target;
|
||||
int targetType;
|
||||
int randomInterval;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__NearestAttackableTargetGoal_H__*/
|
||||
57
src/world/entity/ai/goal/target/TargetGoal.h
Executable file
57
src/world/entity/ai/goal/target/TargetGoal.h
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__TargetGoal_H__
|
||||
#define NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__TargetGoal_H__
|
||||
|
||||
//package net.minecraft.world.entity->ai.goal.target;
|
||||
|
||||
/* import net.minecraft.world.entity->* */
|
||||
#include "../Goal.h"
|
||||
/* import net.minecraft.world.entity->monster.* */
|
||||
#include "../../../player/Player.h"
|
||||
|
||||
class Monster;
|
||||
|
||||
class TargetGoal: public Goal
|
||||
{
|
||||
public:
|
||||
static const int TargetFlag = 1;
|
||||
|
||||
TargetGoal(Monster* mob, float within, bool mustSee)
|
||||
: mob(mob),
|
||||
within(within),
|
||||
mustSee(mustSee)
|
||||
{}
|
||||
|
||||
bool canContinueToUse() {
|
||||
Mob* target = mob->getTarget();
|
||||
if (target == NULL) return false;
|
||||
if (!target->isAlive()) return false;
|
||||
if (mob->distanceToSqr(target) > within * within) return false;
|
||||
if (mustSee && !mob->sensing->canSee(target)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
mob->setTarget(NULL);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool canAttack(Mob* target, bool allowInvulnerable) {
|
||||
if (target == NULL) return false;
|
||||
if (target == mob) return false;
|
||||
if (!target->isAlive()) return false;
|
||||
if (target->bb.y1 <= mob->bb.y0 || target->bb.y0 >= mob->bb.y1) return false;
|
||||
//if (target instanceof Creeper || target instanceof Ghast) return false;
|
||||
|
||||
if (target->isPlayer()) {
|
||||
if (!allowInvulnerable && ((Player*) target)->abilities.invulnerable) return false;
|
||||
}
|
||||
if (mustSee && !mob->sensing->canSee(target)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
Monster* mob;
|
||||
float within;
|
||||
bool mustSee;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_WORLD_ENTITY_AI_GOAL_TARGET__TargetGoal_H__*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue