Added a bool spawnAtTarget to spawn attack in which you can define whether the unit spawns at the target or at the attacker.

In Addition i changed the command which is given to the spawned unit to an attack command on the target cell.
( I think this makes way more sense than giving a move command to the meeting point)
( This also works if the spawned does not have a attack command. It will move to the enemy then)
This commit is contained in:
titison 2014-07-27 12:54:25 +02:00
parent 6fc59dc5f2
commit 6086a33baf
3 changed files with 21 additions and 5 deletions

View File

@ -834,6 +834,7 @@ AttackSkillType::AttackSkillType() {
splashRadius= 0;
spawnUnit="";
spawnUnitcount=0;
spawnUnitAtTarget=false;
splashParticleSystemType= NULL;
for(int i = 0; i < fieldCount; ++i) {
@ -886,11 +887,16 @@ void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,
if (sn->hasChild("unit")) {
spawnUnit = sn->getChild("unit")->getAttribute("value")->getValue();
spawnUnitcount
= sn->getChild("unit")->getAttribute("amount")->getIntValue();
spawnUnitcount = sn->getChild("unit")->getAttribute("amount")->getIntValue();
if(sn->getChild("unit")->hasAttribute("spawnAtTarget")) {
spawnUnitAtTarget = sn->getChild("unit")->getAttribute("spawnAtTarget")->getBoolValue();
} else {
spawnUnitAtTarget = false;
}
} else {
spawnUnit = "";
spawnUnitcount = 0;
spawnUnitAtTarget = false;
}
//attack fields
const XmlNode *attackFieldsNode= sn->getChild("attack-fields");
@ -1053,6 +1059,8 @@ void AttackSkillType::saveGame(XmlNode *rootNode) {
attackSkillTypeNode->addAttribute("spawnUnit",spawnUnit, mapTagReplacements);
// int spawnUnitcount;
attackSkillTypeNode->addAttribute("spawnUnitcount",intToStr(spawnUnitcount), mapTagReplacements);
// bool spawnUnitAtTarget;
attackSkillTypeNode->addAttribute("spawnUnitAtTarget",intToStr(spawnUnitAtTarget), mapTagReplacements);
// bool projectile;
attackSkillTypeNode->addAttribute("projectile",intToStr(projectile), mapTagReplacements);
// ParticleSystemTypeProjectile* projectileParticleSystemType;

View File

@ -292,6 +292,7 @@ private:
string spawnUnit;
int spawnUnitcount;
bool spawnUnitAtTarget;
bool projectile;
//ParticleSystemTypeProjectile* projectileParticleSystemType;
SoundContainer projSounds;
@ -318,6 +319,7 @@ public:
inline float getAttackStartTime() const {return attackStartTime;}
inline string getSpawnUnit() const {return spawnUnit;}
inline int getSpawnUnitCount() const {return spawnUnitcount;}
inline bool getSpawnUnitAtTarget() const {return spawnUnitAtTarget;}
//get proj
inline bool getProjectile() const {return projectile;}

View File

@ -298,7 +298,13 @@ bool UnitUpdater::updateUnit(Unit *unit) {
Vec2i(0), spawnUnitType, unit->getFaction(),
world->getMap(), CardinalDir::NORTH);
//SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] about to place unit for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,spawned->toString().c_str());
if(!world->placeUnit(unit->getCenteredPos(), 10, spawned)) {
bool placedSpawnUnit=false;
if(act->getAttackSkillType()->getSpawnUnitAtTarget()) {
placedSpawnUnit=world->placeUnit(unit->getTargetPos(), 10, spawned);
} else {
placedSpawnUnit=world->placeUnit(unit->getCenteredPos(), 10, spawned);
}
if(!placedSpawnUnit) {
//SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] COULD NOT PLACE UNIT for unitID [%d]\n",__FILE__,__FUNCTION__,__LINE__,spawned->getId());
// This will also cleanup newPath
@ -309,10 +315,10 @@ bool UnitUpdater::updateUnit(Unit *unit) {
spawned->create();
spawned->born(ct);
world->getStats()->produce(unit->getFactionIndex(),spawned->getType()->getCountUnitProductionInStats());
const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit());
const CommandType *ct= spawned->computeCommandType(unit->getTargetPos(),map->getCell(unit->getTargetPos())->getUnit(unit->getTargetField()));
if(ct != NULL){
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
spawned->giveCommand(new Command(ct, unit->getMeetingPos()));
spawned->giveCommand(new Command(ct, unit->getTargetPos()));
}
scriptManager->onUnitCreated(spawned);