particles have more switches: day/night visibility , alternating value , radiusBasedStartenergy ( can be disabled now! )

This commit is contained in:
Titus Tscharntke 2011-03-13 23:16:07 +00:00
parent 28f74a15f7
commit c54174061f
9 changed files with 428 additions and 299 deletions

View File

@ -35,6 +35,7 @@ namespace Glest{ namespace Game{
ParticleSystemType::ParticleSystemType() {
teamcolorNoEnergy=false;
teamcolorEnergy=false;
alternations=false;
texture=NULL;
model=NULL;
}
@ -141,7 +142,11 @@ void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &d
const XmlNode *teamcolorEnergyNode= particleSystemNode->getChild("teamcolorEnergy");
teamcolorEnergy= teamcolorEnergyNode->getAttribute("value")->getBoolValue();
}
//alternations
if(particleSystemNode->hasChild("alternations")){
const XmlNode *alternatingNode= particleSystemNode->getChild("alternations");
alternations= alternatingNode->getAttribute("value")->getIntValue();
}
//mode
if(particleSystemNode->hasChild("mode")){
const XmlNode *modeNode= particleSystemNode->getChild("mode");
@ -169,6 +174,7 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){
ats->setModel(model);
ats->setTeamcolorNoEnergy(teamcolorNoEnergy);
ats->setTeamcolorEnergy(teamcolorEnergy);
ats->setAlternations(alternations);
ats->setBlendMode(ParticleSystem::strToBlendMode(mode));
}

View File

@ -63,6 +63,7 @@ protected:
string mode;
bool teamcolorNoEnergy;
bool teamcolorEnergy;
int alternations;
public:
ParticleSystemType();

View File

@ -63,6 +63,33 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin
staticParticleCount=0;
}
//isVisibleAtNight
if(particleSystemNode->hasChild("isVisibleAtNight")){
const XmlNode *isVisibleAtNightNode= particleSystemNode->getChild("isVisibleAtNight");
isVisibleAtNight= isVisibleAtNightNode->getAttribute("value")->getBoolValue();
}
else {
isVisibleAtNight=true;
}
//isVisibleAtDay
if(particleSystemNode->hasChild("isVisibleAtDay")){
const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("isVisibleAtDay");
isVisibleAtDay= isVisibleAtDayNode->getAttribute("value")->getBoolValue();
}
else {
isVisibleAtDay=true;
}
//radiusBasedStartenergy
if(particleSystemNode->hasChild("radiusBasedStartenergy")){
const XmlNode *isVisibleAtDayNode= particleSystemNode->getChild("radiusBasedStartenergy");
radiusBasedStartenergy= isVisibleAtDayNode->getAttribute("value")->getBoolValue();
}
else{
radiusBasedStartenergy= true;
}
//fixed
const XmlNode *fixedNode= particleSystemNode->getChild("fixed");
fixed= fixedNode->getAttribute("value")->getBoolValue();
@ -87,9 +114,14 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
ups->setRelativeDirection(relativeDirection);
ups->setTeamcolorNoEnergy(teamcolorNoEnergy);
ups->setTeamcolorEnergy(teamcolorEnergy);
ups->setAlternations(alternations);
ups->setIsVisibleAtNight(isVisibleAtNight);
ups->setIsVisibleAtDay(isVisibleAtDay);
ups->setStaticParticleCount(staticParticleCount);
ups->setRadius(radius);
ups->setBlendMode(ParticleSystem::strToBlendMode(mode));
ups->setRadiusBasedStartenergy(radiusBasedStartenergy);
//prepare system for given staticParticleCount
if(staticParticleCount>0)
{

View File

@ -51,6 +51,9 @@ protected:
bool relativeDirection;
bool fixed;
int staticParticleCount;
bool isVisibleAtNight;
bool isVisibleAtDay;
bool radiusBasedStartenergy;
public:
void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture);

View File

@ -56,6 +56,7 @@ void TimeFlow::update() {
//day
if(lastTime<dawn && time>=dawn){
soundRenderer.stopAmbient(ambientSounds->getNight());
UnitParticleSystem::isNight=false;
}
if((lastTime<dawn && time>=dawn) || firstTime){
@ -75,6 +76,7 @@ void TimeFlow::update() {
//night
if(lastTime<dusk && time>=dusk){
soundRenderer.stopAmbient(ambientSounds->getDay());
UnitParticleSystem::isNight=true;
}
if(lastTime<dusk && time>=dusk){

View File

@ -1332,6 +1332,19 @@ void UnitUpdater::updateRepair(Unit *unit) {
//repairPos = command->getPos()-Vec2i(1);
}
if(startRepairing == false && repaired == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
// we have a repair command to the ground! We must find first units in visible range of target point.
startRepairing = damagedRepairableUnitOnRange(rct, repairPos, unit->getType()->getSight(), &repaired);
//if(startRepairing) command->setPos(repaired->getCenteredPos());
if(repaired != NULL){
startRepairing = true;
nextToRepaired = repaired != NULL && map->isNextTo(unit->getPos(), repaired);
repairPos=repaired->getCenteredPos();
command->setPos(repairPos);
}
}
//if not repairing
if(startRepairing == true) {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -1836,6 +1849,40 @@ void UnitUpdater::findEnemiesForCell(const AttackSkillType *ast, Cell *cell, con
}
}
bool UnitUpdater::damagedRepairableUnitOnRange(const RepairCommandType* rct, Vec2i repairPos, int range, Unit **unitToRepair){
Vec2f floatRepairPos = Vec2f(repairPos.x, repairPos.y);
Unit* damagedUnit=NULL;
int bestDistanced=-1;
for(int i=repairPos.x-range; i<repairPos.x+range+1; ++i){
for(int j=repairPos.y-range; j<repairPos.y+range+1; ++j){
//cells inside map and in range
#ifdef USE_STREFLOP
if(map->isInside(i, j) && streflop::floor(floatRepairPos.dist(Vec2f((float)i, (float)j))) <= (range+1)){
#else
if(map->isInside(i, j) && floor(floatRepairPos.dist(Vec2f((float)i, (float)j))) <= (range+1)){
#endif
Cell *cell = map->getCell(i,j);
for(int k = 0; k < fieldCount; k++) {
Field f= static_cast<Field>(k);
Unit *possibleUnit = cell->getUnit(f);
if( possibleUnit != NULL &&
possibleUnit->getTeam()==world->getThisTeamIndex() &&
rct->isRepairableUnitType(possibleUnit->getType()) &&
possibleUnit->isDamaged()) {
// possible unit!
*unitToRepair=possibleUnit;
return true;
// TODO choose nearest to repair unit
}
}
}
}
}
return false;
}
//if the unit has any enemy on range
bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
const AttackSkillType *ast){

View File

@ -126,6 +126,7 @@ private:
bool attackableOnRange(const Unit *unit, Unit **enemyPtr, const AttackSkillType *ast);
bool unitOnRange(const Unit *unit, int range, Unit **enemyPtr, const AttackSkillType *ast);
void enemiesAtDistance(const Unit *unit, const Unit *priorityUnit, int distance, vector<Unit*> &enemies);
bool damagedRepairableUnitOnRange(const RepairCommandType* rct, Vec2i repairPos, int range, Unit **unitToRepair);
Unit * findPeerUnitBuilder(Unit *unit);
void SwapActiveCommand(Unit *unitSrc, Unit *unitDest);

View File

@ -131,6 +131,7 @@ protected:
Vec3f factionColor;
bool teamcolorNoEnergy;
bool teamcolorEnergy;
int alternations;
ParticleObserver *particleObserver;
@ -154,7 +155,7 @@ public:
const Particle *getParticle(int i) const {return &particles[i];}
int getAliveParticleCount() const {return aliveParticleCount;}
bool getActive() const {return active;}
bool getVisible() const {return visible;}
virtual bool getVisible() const {return visible;}
//set
void setState(State state);
@ -173,6 +174,7 @@ public:
void setBlendMode(BlendMode blendMode) {this->blendMode= blendMode;}
void setTeamcolorNoEnergy(bool teamcolorNoEnergy) {this->teamcolorNoEnergy= teamcolorNoEnergy;}
void setTeamcolorEnergy(bool teamcolorEnergy) {this->teamcolorEnergy= teamcolorEnergy;}
void setAlternations(int alternations) {this->alternations= alternations;}
virtual void setFactionColor(Vec3f factionColor);
static BlendMode strToBlendMode(const string &str);
@ -219,6 +221,8 @@ public:
// =====================================================
class UnitParticleSystem: public ParticleSystem{
public:
static bool isNight;
private:
float radius;
Vec3f windSpeed;
@ -242,6 +246,10 @@ public:
float sizeNoEnergy;
float gravity;
float rotation;
bool isVisibleAtNight;
bool isVisibleAtDay;
bool radiusBasedStartenergy;
int staticParticleCount;
public:
@ -254,6 +262,7 @@ public:
virtual void updateParticle(Particle *p);
virtual void update();
virtual void render(ParticleRenderer *pr, ModelRenderer *mr);
virtual bool getVisible() const;
//set params
void setRadius(float radius);
@ -269,6 +278,9 @@ public:
void setFixed(bool fixed) {this->fixed= fixed;}
void setPrimitive(Primitive primitive) {this->primitive= primitive;}
void setStaticParticleCount(int staticParticleCount){this->staticParticleCount= staticParticleCount;}
void setIsVisibleAtNight(bool value) {this->isVisibleAtNight= value;}
void setIsVisibleAtDay(bool value) {this->isVisibleAtDay= value;}
void setRadiusBasedStartenergy(bool value) {this->radiusBasedStartenergy= value;}
static Primitive strToPrimitive(const string &str);

File diff suppressed because it is too large Load Diff