mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- bugfix for multiple models per skilltype (let existing model finish animating before allow next random model to be selected)
- started work on a new feature called 'attack-boost' that should prove VERY INTERESTING once fully implemented (shhh its a secret)
This commit is contained in:
parent
e0860309c0
commit
5dda269151
@ -276,6 +276,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||
computeTotalUpgrade();
|
||||
|
||||
//starting skill
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
this->currSkill = getType()->getFirstStOfClass(scStop);
|
||||
livingUnits.insert(id);
|
||||
livingUnitsp.insert(this);
|
||||
@ -588,7 +589,11 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
|
||||
}
|
||||
}
|
||||
progress2= 0;
|
||||
if(this->currSkill != currSkill) {
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
}
|
||||
this->currSkill= currSkill;
|
||||
|
||||
}
|
||||
|
||||
void Unit::setCurrSkill(SkillClass sc) {
|
||||
@ -675,24 +680,24 @@ void Unit::setVisible(const bool visible) {
|
||||
|
||||
// =============================== Render related ==================================
|
||||
|
||||
Model *Unit::getCurrentModelPtr() const {
|
||||
Model *Unit::getCurrentModelPtr() {
|
||||
if(currSkill == NULL) {
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: currSkill == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation();
|
||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
||||
}
|
||||
|
||||
const Model *Unit::getCurrentModel() const{
|
||||
const Model *Unit::getCurrentModel() {
|
||||
if(currSkill == NULL) {
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: currSkill == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
return currSkill->getAnimation();
|
||||
return currSkill->getAnimation(animProgress,&lastModelIndexForCurrSkillType);
|
||||
}
|
||||
|
||||
Vec3f Unit::getCurrVector() const{
|
||||
@ -1205,6 +1210,7 @@ bool Unit::update() {
|
||||
//checks
|
||||
if(animProgress > 1.f) {
|
||||
animProgress = currSkill->getClass() == scDie? 1.f: 0.f;
|
||||
this->lastModelIndexForCurrSkillType = -1;
|
||||
}
|
||||
|
||||
bool return_value = false;
|
||||
|
@ -283,6 +283,7 @@ private:
|
||||
const UnitType *type;
|
||||
const ResourceType *loadType;
|
||||
const SkillType *currSkill;
|
||||
int lastModelIndexForCurrSkillType;
|
||||
|
||||
bool toBeUndertaken;
|
||||
bool alive;
|
||||
@ -423,8 +424,8 @@ public:
|
||||
bool getVisible() const { return visible; }
|
||||
|
||||
//render related
|
||||
const Model *getCurrentModel() const;
|
||||
Model *getCurrentModelPtr() const;
|
||||
const Model *getCurrentModel();
|
||||
Model *getCurrentModelPtr();
|
||||
Vec3f getCurrVector() const;
|
||||
Vec3f getCurrVectorFlat() const;
|
||||
Vec3f getVectorFlat(const Vec2i &lastPosValue, const Vec2i &curPosValue) const;
|
||||
|
@ -120,12 +120,46 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt,
|
||||
sounds[i]= sound;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// attack-boost
|
||||
if(sn->hasChild("attack-boost") == true) {
|
||||
//printf("$$FOUND ATTACK BOOST FOR [%s]\n",parentLoader.c_str());
|
||||
|
||||
attackBoost.enabled = true;
|
||||
|
||||
const XmlNode *attackBoostNode = sn->getChild("attack-boost");
|
||||
attackBoost.radius = attackBoostNode->getChild("radius")->getAttribute("value")->getIntValue();
|
||||
attackBoost.boostAllUnits = attackBoostNode->getChild("boost-all-units")->getAttribute("value")->getBoolValue();
|
||||
if(attackBoost.boostAllUnits == false) {
|
||||
for(int i = 0; i < attackBoostNode->getChild("boost-all-units")->getChildCount(); ++i) {
|
||||
const XmlNode *boostUnitNode= attackBoostNode->getChild("boost-all-units")->getChild("unit-type", i);
|
||||
attackBoost.boostUnitList.push_back(ft->getUnitType(boostUnitNode->getAttribute("name")->getRestrictedValue()));
|
||||
}
|
||||
}
|
||||
attackBoost.boostUpgrade.load(attackBoostNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Model *SkillType::getAnimation() const {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL));
|
||||
int modelIndex = rand() % animations.size();
|
||||
Model *SkillType::getAnimation(float animProgress, int *lastAnimationIndex) const {
|
||||
int modelIndex = 0;
|
||||
if(animations.size() > 1) {
|
||||
//printf("animProgress = [%f] for skill [%s]\n",animProgress,name.c_str());
|
||||
|
||||
if(lastAnimationIndex) {
|
||||
modelIndex = *lastAnimationIndex;
|
||||
}
|
||||
if(modelIndex < 0 || animProgress > 1.0f) {
|
||||
//int modelIndex = random.randRange(0,animations.size()-1);
|
||||
srand(time(NULL));
|
||||
modelIndex = rand() % animations.size();
|
||||
}
|
||||
}
|
||||
if(lastAnimationIndex) {
|
||||
*lastAnimationIndex = modelIndex;
|
||||
}
|
||||
|
||||
//printf("!!RETURN ANIMATION [%d / %d]\n",modelIndex,animations.size()-1);
|
||||
return animations[modelIndex];
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "factory.h"
|
||||
#include "sound_container.h"
|
||||
#include "particle.h"
|
||||
#include "upgrade_type.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using Shared::Sound::StaticSound;
|
||||
@ -72,8 +73,21 @@ typedef list<UnitParticleSystemType*> UnitParticleSystemTypes;
|
||||
/// A basic action that an unit can perform
|
||||
// =====================================================
|
||||
|
||||
class SkillType {
|
||||
class AttackBoost {
|
||||
public:
|
||||
AttackBoost() {
|
||||
enabled = false;
|
||||
radius = 0;
|
||||
boostAllUnits = false;
|
||||
}
|
||||
bool enabled;
|
||||
int radius;
|
||||
bool boostAllUnits;
|
||||
vector<const UnitType *> boostUnitList;
|
||||
UpgradeTypeBase boostUpgrade;
|
||||
};
|
||||
|
||||
class SkillType {
|
||||
|
||||
protected:
|
||||
SkillClass skillClass;
|
||||
@ -86,6 +100,7 @@ protected:
|
||||
SoundContainer sounds;
|
||||
float soundStartTime;
|
||||
RandomGen random;
|
||||
AttackBoost attackBoost;
|
||||
|
||||
public:
|
||||
UnitParticleSystemTypes unitParticleSystemTypes;
|
||||
@ -104,7 +119,7 @@ public:
|
||||
int getHpCost() const {return hpCost;}
|
||||
int getSpeed() const {return speed;}
|
||||
int getAnimSpeed() const {return animSpeed;}
|
||||
Model *getAnimation() const;
|
||||
Model *getAnimation(float animProgress=0, int *lastAnimationIndex=NULL) const;
|
||||
StaticSound *getSound() const {return sounds.getRandSound();}
|
||||
float getSoundStartTime() const {return soundStartTime;}
|
||||
|
||||
|
@ -37,6 +37,18 @@ namespace Glest{ namespace Game{
|
||||
|
||||
// ==================== get ====================
|
||||
|
||||
void UpgradeTypeBase::load(const XmlNode *upgradeNode) {
|
||||
//values
|
||||
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||
maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
||||
sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue();
|
||||
attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue();
|
||||
attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue();
|
||||
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
||||
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
||||
}
|
||||
|
||||
bool UpgradeType::isAffected(const UnitType *unitType) const{
|
||||
return find(effects.begin(), effects.end(), unitType)!=effects.end();
|
||||
}
|
||||
@ -154,14 +166,15 @@ void UpgradeType::load(const string &dir, const TechTree *techTree,
|
||||
sortedItems.clear();
|
||||
|
||||
//values
|
||||
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||
maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
||||
sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue();
|
||||
attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue();
|
||||
attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue();
|
||||
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
||||
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
||||
// maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||
// maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
||||
// sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue();
|
||||
// attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue();
|
||||
// attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue();
|
||||
// armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||
// moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
||||
// prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
||||
UpgradeTypeBase::load(upgradeNode);
|
||||
}
|
||||
catch(const exception &e){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
||||
|
@ -15,10 +15,12 @@
|
||||
#include "element_type.h"
|
||||
#include "checksum.h"
|
||||
#include "conversion.h"
|
||||
#include "xml_parser.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using Shared::Util::Checksum;
|
||||
using namespace Shared::Util;
|
||||
using namespace Shared::Xml;
|
||||
|
||||
namespace Glest{ namespace Game{
|
||||
|
||||
@ -30,7 +32,7 @@ class UnitType;
|
||||
// class UpgradeTypeBase
|
||||
// ===============================
|
||||
|
||||
class UpgradeTypeBase{
|
||||
class UpgradeTypeBase {
|
||||
protected:
|
||||
int maxHp;
|
||||
int sight;
|
||||
@ -51,6 +53,8 @@ public:
|
||||
int getMoveSpeed() const {return moveSpeed;}
|
||||
int getProdSpeed() const {return prodSpeed;}
|
||||
|
||||
void load(const XmlNode *upgradeNode);
|
||||
|
||||
std::string toString() const {
|
||||
std::string result = "";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user