Mobs are assigned MaxHealth from monsters.ini; reading monsters.ini doesn't need settings.ini values anymore.
Fixes FS #409. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1662 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
5951bc76ec
commit
a3c8b12ee9
@ -431,6 +431,15 @@ void cEntity::Heal(int a_HitPoints)
|
||||
|
||||
|
||||
|
||||
void cEntity::SetHealth(int a_Health)
|
||||
{
|
||||
m_Health = std::max(0, std::min(m_MaxHealth, a_Health));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
|
||||
{
|
||||
if (m_AttachedTo != NULL)
|
||||
|
@ -236,9 +236,12 @@ public:
|
||||
/// Heals the specified amount of HPs
|
||||
void Heal(int a_HitPoints);
|
||||
|
||||
/// Returns the health of this pawn
|
||||
/// Returns the health of this entity
|
||||
int GetHealth(void) const { return m_Health; }
|
||||
|
||||
/// Sets the health of this entity; doesn't broadcast any hurt animation
|
||||
void SetHealth(int a_Health);
|
||||
|
||||
// tolua_end
|
||||
|
||||
virtual void Tick(float a_Dt, cChunk & a_Chunk);
|
||||
|
@ -12,11 +12,11 @@
|
||||
|
||||
struct cMonsterConfig::sAttributesStruct
|
||||
{
|
||||
AString m_name;
|
||||
float m_SightDistance;
|
||||
float m_AttackDamage;
|
||||
float m_AttackRange;
|
||||
float m_AttackRate;
|
||||
AString m_Name;
|
||||
double m_SightDistance;
|
||||
double m_AttackDamage;
|
||||
double m_AttackRange;
|
||||
double m_AttackRate;
|
||||
int m_MaxHealth;
|
||||
};
|
||||
|
||||
@ -55,37 +55,25 @@ cMonsterConfig::~cMonsterConfig()
|
||||
|
||||
void cMonsterConfig::Initialize()
|
||||
{
|
||||
sAttributesStruct Attributes;
|
||||
cIniFile SettingsIniFile("settings.ini");
|
||||
cIniFile MonstersIniFile("monsters.ini");
|
||||
|
||||
if (!SettingsIniFile.ReadFile() || !MonstersIniFile.ReadFile())
|
||||
if (!MonstersIniFile.ReadFile())
|
||||
{
|
||||
LOGWARNING("cMonsterConfig: Must have both settings.ini and monsters.ini to configure attributes\n\tusing default attributes \n");
|
||||
LOGWARNING("%s: Cannot read monsters.ini file, monster attributes not available", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
m_pState->MonsterTypes = SettingsIniFile.GetValue("Monsters", "Types", "");
|
||||
|
||||
if ( m_pState->MonsterTypes.empty() )
|
||||
for (int i = (int)MonstersIniFile.NumKeys(); i >= 0; i--)
|
||||
{
|
||||
LOGWARNING("cMonsterConfig: No Monster types listed in config file, using default attributes \n");
|
||||
return;
|
||||
}
|
||||
|
||||
AStringVector SplitList = StringSplit(m_pState->MonsterTypes, ",");
|
||||
for (unsigned int i = 0; i < SplitList.size(); ++i)
|
||||
{
|
||||
if (!SplitList[i].empty())
|
||||
{
|
||||
Attributes.m_name = SplitList[i];
|
||||
Attributes.m_AttackDamage = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackDamage", 0);
|
||||
Attributes.m_AttackRange = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackRange", 0);
|
||||
Attributes.m_SightDistance = (float)MonstersIniFile.GetValueF(SplitList[i], "SightDistance", 0);
|
||||
Attributes.m_AttackRate = (float)MonstersIniFile.GetValueF(SplitList[i], "AttackRate", 0);
|
||||
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(SplitList[i], "MaxHealth", 0);
|
||||
sAttributesStruct Attributes;
|
||||
AString Name = MonstersIniFile.KeyName(i);
|
||||
Attributes.m_Name = Name;
|
||||
Attributes.m_AttackDamage = MonstersIniFile.GetValueF(Name, "AttackDamage", 0);
|
||||
Attributes.m_AttackRange = MonstersIniFile.GetValueF(Name, "AttackRange", 0);
|
||||
Attributes.m_SightDistance = MonstersIniFile.GetValueF(Name, "SightDistance", 0);
|
||||
Attributes.m_AttackRate = MonstersIniFile.GetValueF(Name, "AttackRate", 0);
|
||||
Attributes.m_MaxHealth = MonstersIniFile.GetValueI(Name, "MaxHealth", 1);
|
||||
m_pState->AttributesList.push_front(Attributes);
|
||||
}
|
||||
} // for i - SplitList[]
|
||||
}
|
||||
|
||||
@ -98,13 +86,13 @@ void cMonsterConfig::AssignAttributes(cMonster * a_Monster, const AString & a_Na
|
||||
std::list<sAttributesStruct>::const_iterator itr;
|
||||
for (itr = m_pState->AttributesList.begin(); itr != m_pState->AttributesList.end(); ++itr)
|
||||
{
|
||||
if (itr->m_name.compare(a_Name) == 0)
|
||||
if (itr->m_Name.compare(a_Name) == 0)
|
||||
{
|
||||
a_Monster->SetAttackDamage (itr->m_AttackDamage);
|
||||
a_Monster->SetAttackRange (itr->m_AttackRange);
|
||||
a_Monster->SetSightDistance(itr->m_SightDistance);
|
||||
a_Monster->SetAttackDamage ((float)itr->m_AttackDamage);
|
||||
a_Monster->SetAttackRange ((float)itr->m_AttackRange);
|
||||
a_Monster->SetSightDistance((float)itr->m_SightDistance);
|
||||
a_Monster->SetAttackRate ((int)itr->m_AttackRate);
|
||||
a_Monster->SetMaxHealth ((short)itr->m_MaxHealth);
|
||||
a_Monster->SetMaxHealth (itr->m_MaxHealth);
|
||||
return;
|
||||
}
|
||||
} // for itr - m_pState->AttributesList[]
|
||||
|
@ -27,11 +27,12 @@
|
||||
|
||||
cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */)
|
||||
: cEntity(etPickup, ((double)(a_MicroPosX)) / 32, ((double)(a_MicroPosY)) / 32, ((double)(a_MicroPosZ)) / 32, 0.2, 0.2)
|
||||
, m_Health(5)
|
||||
, m_Timer( 0.f )
|
||||
, m_Item(a_Item)
|
||||
, m_bCollected( false )
|
||||
{
|
||||
m_MaxHealth = 1;
|
||||
m_Health = 1;
|
||||
SetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ);
|
||||
m_Gravity = -3.0;
|
||||
}
|
||||
|
@ -43,8 +43,6 @@ public:
|
||||
short GetAge(void) const { return (short)(m_Timer / 50); }
|
||||
|
||||
private:
|
||||
short m_Health;
|
||||
|
||||
Vector3d m_ResultingSpeed; //Can be used to modify the resulting speed for the current tick ;)
|
||||
|
||||
Vector3d m_WaterSpeed;
|
||||
|
@ -2354,6 +2354,7 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, int a_EntityTy
|
||||
}
|
||||
}
|
||||
Monster->SetPosition(a_PosX, a_PosY, a_PosZ);
|
||||
Monster->SetHealth(Monster->GetMaxHealth());
|
||||
Monster->Initialize(this);
|
||||
BroadcastSpawnEntity(*Monster);
|
||||
return Monster->GetUniqueID();
|
||||
|
Loading…
Reference in New Issue
Block a user