MuwuMs changes ( spawn attack and more )

This commit is contained in:
Titus Tscharntke 2011-02-06 18:33:49 +00:00
parent c58e893047
commit e856d5e4f0
8 changed files with 153 additions and 13 deletions

View File

@ -1203,6 +1203,38 @@ bool Unit::computeEp() {
return false;
}
bool Unit::computeHp() {
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);
}
if(!isBeingBuilt()){
//cost hp
if(currSkill->getHpCost() > 0) {
bool decHpResult = decHp(currSkill->getHpCost());
if(decHpResult) {
Unit::game->getWorld()->getStats()->die(getFactionIndex());
game->getScriptManager()->onUnitDied(this);
}
}
// If we have negative costs then add life
else {
checkItemInVault(&this->hp,this->hp);
hp += -currSkill->getHpCost();
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
hp = type->getTotalMaxHp(&totalUpgrade);
}
addItemToVault(&this->hp,this->hp);
}
}
return true;
}
bool Unit::repair(){
@ -1404,7 +1436,7 @@ bool Unit::morph(const MorphCommandType *mct){
Field morphUnitField=fLand;
if(morphUnitType->getField(fAir)) morphUnitField=fAir;
if(morphUnitType->getField(fLand)) morphUnitField=fLand;
if(map->isFreeCellsOrHasUnit(pos, morphUnitType->getSize(), morphUnitField, this)){
if(map->isFreeCellsOrHasUnit(pos, morphUnitType->getSize(), morphUnitField, this,morphUnitType)){
map->clearUnitCells(this, pos);
faction->deApplyStaticCosts(type);

View File

@ -426,6 +426,7 @@ public:
const CommandType *computeCommandType(const Vec2i &pos, const Unit *targetUnit= NULL) const;
string getDesc() const;
bool computeEp();
bool computeHp();
bool repair();
bool decHp(int i);
int update2();

View File

@ -94,7 +94,8 @@ string StopCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str+= lang.get("ReactionSpeed")+": "+ intToStr(stopSkillType->getSpeed())+"\n";
if(stopSkillType->getEpCost()!=0)
str+= lang.get("EpCost")+": "+intToStr(stopSkillType->getEpCost())+"\n";
if(stopSkillType->getHpCost()!=0)
str+= lang.get("HpCost")+": "+intToStr(stopSkillType->getHpCost())+"\n";
return str;
}
@ -146,6 +147,9 @@ string MoveCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str+="\n";
if(moveSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(moveSkillType->getEpCost())+"\n";
}
if(moveSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(moveSkillType->getHpCost())+"\n";
}
return str;
@ -189,6 +193,9 @@ string AttackCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str= name+"\n";
if(attackSkillType->getEpCost()!=0){
str+= lang.get("EpCost") + ": " + intToStr(attackSkillType->getEpCost()) + "\n";
}
if(attackSkillType->getHpCost()!=0){
str+= lang.get("HpCost") + ": " + intToStr(attackSkillType->getHpCost()) + "\n";
}
//attack strength
@ -276,6 +283,9 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const
str= name+"\n";
if(attackSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(attackSkillType->getEpCost())+"\n";
}
if(attackSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(attackSkillType->getHpCost())+"\n";
}
//attack strength
@ -397,6 +407,9 @@ string BuildCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str+= lang.get("BuildSpeed")+": "+ intToStr(buildSkillType->getSpeed())+"\n";
if(buildSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(buildSkillType->getEpCost())+"\n";
}
if(buildSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(buildSkillType->getHpCost())+"\n";
}
return str;
@ -464,6 +477,9 @@ string HarvestCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
if(harvestSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(harvestSkillType->getEpCost())+"\n";
}
if(harvestSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(harvestSkillType->getHpCost())+"\n";
}
str+=lang.get("Resources")+":\n";
for(int i=0; i<getHarvestedResourceCount(); ++i){
str+= getHarvestedResource(i)->getName()+"\n";
@ -531,7 +547,9 @@ string RepairCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
if(repairSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(repairSkillType->getEpCost())+"\n";
}
if(repairSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(repairSkillType->getHpCost())+"\n";
}
str+="\n"+lang.get("CanRepair")+":\n";
for(int i=0; i<repairableUnits.size(); ++i){
str+= (static_cast<const UnitType*>(repairableUnits[i]))->getName()+"\n";
@ -604,7 +622,9 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
if(produceSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(produceSkillType->getEpCost())+"\n";
}
if(produceSkillType->getHpCost()!=0){
str+= lang.get("hpCost")+": "+intToStr(produceSkillType->getHpCost())+"\n";
}
str+= "\n" + getProducedUnit()->getReqDesc();
return str;
@ -658,7 +678,8 @@ string UpgradeCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
str+= lang.get("UpgradeSpeed")+": "+ intToStr(upgradeSkillType->getSpeed())+"\n";
if(upgradeSkillType->getEpCost()!=0)
str+= lang.get("EpCost")+": "+intToStr(upgradeSkillType->getEpCost())+"\n";
if(upgradeSkillType->getHpCost()!=0)
str+= lang.get("HpCost")+": "+intToStr(upgradeSkillType->getHpCost())+"\n";
str+= "\n"+getProducedUpgrade()->getReqDesc();
return str;
@ -720,6 +741,9 @@ string MorphCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
//mpcost
if(morphSkillType->getEpCost()!=0){
str+= lang.get("EpCost")+": "+intToStr(morphSkillType->getEpCost())+"\n";
}
if(morphSkillType->getHpCost()!=0){
str+= lang.get("HpCost")+": "+intToStr(morphSkillType->getHpCost())+"\n";
}
//discount

View File

@ -47,6 +47,11 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, c
//ep cost
mpCost= sn->getChild("ep-cost")->getAttribute("value")->getIntValue();
if (sn->hasChild("hp-cost")) {
hpCost = sn->getChild("hp-cost")->getAttribute("value")->getIntValue();
} else {
hpCost = 0;
}
//speed
speed= sn->getChild("speed")->getAttribute("value")->getIntValue();
@ -196,6 +201,14 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree
attackType= tt->getAttackType(attackTypeName);
attackStartTime= sn->getChild("attack-start-time")->getAttribute("value")->getFloatValue();
if (sn->hasChild("unit")) {
spawnUnit = sn->getChild("unit")->getAttribute("value")->getValue();
spawnUnitcount
= sn->getChild("unit")->getAttribute("amount")->getIntValue();
} else {
spawnUnit = "";
spawnUnitcount = 0;
}
//attack fields
const XmlNode *attackFieldsNode= sn->getChild("attack-fields");
for(int i=0; i<attackFieldsNode->getChildCount(); ++i){

View File

@ -79,6 +79,7 @@ protected:
SkillClass skillClass;
string name;
int mpCost;
int hpCost;
int speed;
int animSpeed;
Model *animation;
@ -96,6 +97,7 @@ public:
const string &getName() const {return name;}
SkillClass getClass() const {return skillClass;}
int getEpCost() const {return mpCost;}
int getHpCost() const {return hpCost;}
int getSpeed() const {return speed;}
int getAnimSpeed() const {return animSpeed;}
Model *getAnimation() const {return animation;}
@ -144,6 +146,8 @@ private:
bool attackFields[fieldCount];
float attackStartTime;
string spawnUnit;
int spawnUnitcount;
bool projectile;
ParticleSystemTypeProjectile* projectileParticleSystemType;
SoundContainer projSounds;
@ -166,6 +170,8 @@ public:
const AttackType *getAttackType() const {return attackType;}
bool getAttackField(Field field) const {return attackFields[field];}
float getAttackStartTime() const {return attackStartTime;}
string getSpawnUnit() const {return spawnUnit;}
int getSpawnUnitCount() const {return spawnUnitcount;}
//get proj
bool getProjectile() const {return projectile;}

View File

@ -431,15 +431,32 @@ bool Map::isFreeCells(const Vec2i & pos, int size, Field field) const {
return true;
}
bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const {
for(int i=pos.x; i<pos.x+size; ++i) {
for(int j=pos.y; j<pos.y+size; ++j) {
if(isFreeCellOrHasUnit(Vec2i(i,j), field, unit) == false) {
return false;
bool Map::isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field,
const Unit *unit, const UnitType *munit) const {
for (int i = 1; i <= munit->getSize(); ++i) {
for (int j = 1; j <= munit->getSize(); ++j) {
if (munit->hasCellMap() == true) {
// special calculation for units using cellmaps
if (munit->getCellMapCell(i - 1, j - 1, unit->getModelFacing()) == true) {
if (isFreeCellOrHasUnit(
Vec2i(pos.x + i - 1, pos.y + j - 1), field, unit) == false) {
return false;
}
else {
}
}
else {
}
}
else {
if (isFreeCellOrHasUnit(Vec2i(pos.x + i - 1, pos.y + j - 1),
field, unit) == false) {
return false;
}
}
}
}
return true;
return true;
}
bool Map::isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const {

View File

@ -212,7 +212,7 @@ public:
bool isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) const;
bool isAproxFreeCell(const Vec2i &pos, Field field, int teamIndex) const;
bool isFreeCells(const Vec2i &pos, int size, Field field) const;
bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const;
bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit, const UnitType *munit) const;
bool isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const;
bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);

View File

@ -148,7 +148,53 @@ void UnitUpdater::updateUnit(Unit *unit) {
unit->setCurrSkill(scStop);
unit->cancelCommand();
}
if(unit->getCurrSkill()->getClass() != scAttack){
unit->computeHp();
}
else{
Command *command= unit->getCurrCommand();
const AttackCommandType *act= static_cast<const AttackCommandType*>(command->getCommandType());
if(act->getAttackSkillType()->getSpawnUnit() != ""){
for (int y=0; y < act->getAttackSkillType()->getSpawnUnitCount(); ++y) {
Unit *spawned;
UnitPathInterface *newpath = NULL;
switch(this->game->getGameSettings()->getPathFinderType()) {
case pfBasic:
newpath = new UnitPathBasic();
break;
case pfRoutePlanner:
newpath = new UnitPath();
break;
default:
throw runtime_error("detected unsupported pathfinder type!");
}
const FactionType *ft= unit->getFaction()->getType();
spawned= new Unit(world->getNextUnitId(unit->getFaction()), newpath, Vec2i(0),ft->getUnitType(act->getAttackSkillType()->getSpawnUnit()), 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)) {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] COULD NOT PLACE UNIT for unitID [%d]\n",__FILE__,__FUNCTION__,__LINE__,spawned->getId());
delete spawned;
}
else{
spawned->create();
spawned->born();
world->getStats()->produce(unit->getFactionIndex());
const CommandType *ct= spawned->computeCommandType(command->getPos(),command->getUnit());
if(ct!=NULL){
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
spawned->giveCommand(new Command(ct, unit->getMeetingPos()));
}
scriptManager->onUnitCreated(spawned);
//if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
}
}
}
}
//move unit in cells
if(unit->getCurrSkill()->getClass() == scMove) {
world->moveUnitCells(unit);
@ -1501,7 +1547,7 @@ void UnitUpdater::updateMorph(Unit *unit){
if(unit->getCurrSkill()->getClass()!=scMorph){
//if not morphing, check space
if(map->isFreeCellsOrHasUnit(unit->getPos(), mct->getMorphUnit()->getSize(), unit->getCurrField(), unit)){
if(map->isFreeCellsOrHasUnit(unit->getPos(), mct->getMorphUnit()->getSize(), unit->getCurrField(), unit, mct->getMorphUnit())){
unit->setCurrSkill(mct->getMorphSkillType());
}
else{
@ -1628,6 +1674,7 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
}
scriptManager->onUnitDied(attacked);
}
attacker->computeHp();
}
void UnitUpdater::startAttackParticleSystem(Unit *unit){