- fixed a network read problem where there is more data needed before reading large command lists can be processed.
- added more error checking
This commit is contained in:
parent
3ece5b62f7
commit
cdb820a8e8
|
@ -26,7 +26,7 @@ using namespace Shared::Platform;
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
const string mailString= "contact_game@glest.org";
|
const string mailString= "contact_game@glest.org";
|
||||||
const string glestVersionString= "v3.3.5-beta4";
|
const string glestVersionString= "v3.3.5-beta5";
|
||||||
|
|
||||||
string getCrashDumpFileName(){
|
string getCrashDumpFileName(){
|
||||||
return "glest" + glestVersionString + ".dmp";
|
return "glest" + glestVersionString + ".dmp";
|
||||||
|
|
|
@ -553,7 +553,7 @@ void MenuStateConnectedGame::update()
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(hasFactions == true) {
|
if(hasFactions == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] errorOnMissingData = %d\n",__FILE__,__FUNCTION__,__LINE__,errorOnMissingData);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] errorOnMissingData = %d\n",__FILE__,__FUNCTION__,__LINE__,errorOnMissingData);
|
||||||
|
|
||||||
for(int i=0; i<gameSettings->getFactionCount(); ++i){
|
for(int i=0; i<gameSettings->getFactionCount(); ++i){
|
||||||
int slot=gameSettings->getStartLocationIndex(i);
|
int slot=gameSettings->getStartLocationIndex(i);
|
||||||
|
|
|
@ -252,7 +252,7 @@ bool NetworkMessageCommandList::addCommand(const NetworkCommand* networkCommand)
|
||||||
|
|
||||||
bool NetworkMessageCommandList::receive(Socket* socket) {
|
bool NetworkMessageCommandList::receive(Socket* socket) {
|
||||||
// _peek_ type, commandCount & frame num first.
|
// _peek_ type, commandCount & frame num first.
|
||||||
for(int peekAttempt = 1; peekAttempt < 5; peekAttempt++) {
|
for(int peekAttempt = 1; peekAttempt < 15; peekAttempt++) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
||||||
|
|
||||||
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == true) {
|
if (NetworkMessage::peek(socket, &data, commandListHeaderSize) == true) {
|
||||||
|
@ -273,6 +273,20 @@ bool NetworkMessageCommandList::receive(Socket* socket) {
|
||||||
|
|
||||||
// read header + data.commandCount commands.
|
// read header + data.commandCount commands.
|
||||||
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
int totalMsgSize = commandListHeaderSize + (sizeof(NetworkCommand) * data.header.commandCount);
|
||||||
|
|
||||||
|
// _peek_ type, commandCount & frame num first.
|
||||||
|
for(int peekAttempt = 1; peekAttempt < 15; peekAttempt++) {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] peekAttempt = %d\n",__FILE__,__FUNCTION__,__LINE__,peekAttempt);
|
||||||
|
|
||||||
|
if (NetworkMessage::peek(socket, &data, totalMsgSize) == true) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sleep(1); // sleep 1 ms to wait for socket data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (socket->getDataToRead() < totalMsgSize) {
|
if (socket->getDataToRead() < totalMsgSize) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR / WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n",
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ERROR / WARNING!!! Insufficient data to read entire command list [need %d bytes, only %d available].\n",
|
||||||
__FILE__,__FUNCTION__,__LINE__, totalMsgSize, socket->getDataToRead());
|
__FILE__,__FUNCTION__,__LINE__, totalMsgSize, socket->getDataToRead());
|
||||||
|
|
|
@ -248,14 +248,32 @@ int Unit::getTeam() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Unit::getCenteredPos() const {
|
Vec2i Unit::getCenteredPos() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return pos + Vec2i(type->getSize()/2, type->getSize()/2);
|
return pos + Vec2i(type->getSize()/2, type->getSize()/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2f Unit::getFloatCenteredPos() const {
|
Vec2f Unit::getFloatCenteredPos() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return Vec2f(pos.x-0.5f+type->getSize()/2.f, pos.y-0.5f+type->getSize()/2.f);
|
return Vec2f(pos.x-0.5f+type->getSize()/2.f, pos.y-0.5f+type->getSize()/2.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2i Unit::getCellPos() const {
|
Vec2i Unit::getCellPos() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(type->hasCellMap()) {
|
if(type->hasCellMap()) {
|
||||||
|
|
||||||
//find nearest pos to center that is free
|
//find nearest pos to center that is free
|
||||||
|
@ -300,10 +318,22 @@ int Unit::getProductionPercent() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
float Unit::getHpRatio() const {
|
float Unit::getHpRatio() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return clamp(static_cast<float>(hp)/type->getTotalMaxHp(&totalUpgrade), 0.f, 1.f);
|
return clamp(static_cast<float>(hp)/type->getTotalMaxHp(&totalUpgrade), 0.f, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Unit::getEpRatio() const {
|
float Unit::getEpRatio() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(type->getMaxHp()==0){
|
if(type->getMaxHp()==0){
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
@ -313,6 +343,12 @@ float Unit::getEpRatio() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
const Level *Unit::getNextLevel() const{
|
const Level *Unit::getNextLevel() const{
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(level==NULL && type->getLevelCount()>0){
|
if(level==NULL && type->getLevelCount()>0){
|
||||||
return type->getLevel(0);
|
return type->getLevel(0);
|
||||||
}
|
}
|
||||||
|
@ -345,6 +381,12 @@ bool Unit::isOperative() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::isBeingBuilt() const{
|
bool Unit::isBeingBuilt() const{
|
||||||
|
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->getClass()==scBeBuilt;
|
return currSkill->getClass()==scBeBuilt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,14 +399,32 @@ bool Unit::isPutrefacting() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::isAlly(const Unit *unit) const {
|
bool Unit::isAlly(const Unit *unit) const {
|
||||||
|
if(unit == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: unit == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return faction->isAlly(unit->getFaction());
|
return faction->isAlly(unit->getFaction());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::isDamaged() const {
|
bool Unit::isDamaged() const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return hp < type->getTotalMaxHp(&totalUpgrade);
|
return hp < type->getTotalMaxHp(&totalUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::isInteresting(InterestingUnitType iut) const {
|
bool Unit::isInteresting(InterestingUnitType iut) const {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
switch(iut){
|
switch(iut){
|
||||||
case iutIdleHarvester:
|
case iutIdleHarvester:
|
||||||
if(type->hasCommandClass(ccHarvest)){
|
if(type->hasCommandClass(ccHarvest)){
|
||||||
|
@ -393,6 +453,17 @@ bool Unit::isInteresting(InterestingUnitType iut) const{
|
||||||
// ====================================== set ======================================
|
// ====================================== set ======================================
|
||||||
|
|
||||||
void Unit::setCurrSkill(const SkillType *currSkill){
|
void Unit::setCurrSkill(const SkillType *currSkill){
|
||||||
|
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(this->currSkill == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: this->currSkill == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(currSkill->getClass()!=this->currSkill->getClass()){
|
if(currSkill->getClass()!=this->currSkill->getClass()){
|
||||||
animProgress= 0;
|
animProgress= 0;
|
||||||
lastAnimProgress= 0;
|
lastAnimProgress= 0;
|
||||||
|
@ -419,11 +490,23 @@ void Unit::setCurrSkill(const SkillType *currSkill){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setCurrSkill(SkillClass sc){
|
void Unit::setCurrSkill(SkillClass sc){
|
||||||
|
if(getType() == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: getType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
setCurrSkill(getType()->getFirstStOfClass(sc));
|
setCurrSkill(getType()->getFirstStOfClass(sc));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setTarget(const Unit *unit){
|
void Unit::setTarget(const Unit *unit){
|
||||||
|
|
||||||
|
if(unit == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: unit == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//find a free pos in cellmap
|
//find a free pos in cellmap
|
||||||
setTargetPos(unit->getCellPos());
|
setTargetPos(unit->getCellPos());
|
||||||
|
|
||||||
|
@ -473,10 +556,22 @@ void Unit::setVisible(const bool visible){
|
||||||
// =============================== Render related ==================================
|
// =============================== Render related ==================================
|
||||||
|
|
||||||
const Model *Unit::getCurrentModel() const{
|
const Model *Unit::getCurrentModel() const{
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3f Unit::getCurrVector() const{
|
Vec3f Unit::getCurrVector() const{
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
return getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
|
return getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,9 +746,16 @@ void Unit::create(bool startingUnit){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::born(){
|
void Unit::born(){
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
faction->addStore(type);
|
faction->addStore(type);
|
||||||
faction->applyStaticProduction(type);
|
faction->applyStaticProduction(type);
|
||||||
setCurrSkill(scStop);
|
setCurrSkill(scStop);
|
||||||
|
|
||||||
hp= type->getMaxHp();
|
hp= type->getMaxHp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -715,6 +817,12 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target
|
||||||
const CommandType *commandType= NULL;
|
const CommandType *commandType= NULL;
|
||||||
SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(pos));
|
SurfaceCell *sc= map->getSurfaceCell(Map::toSurfCoords(pos));
|
||||||
|
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(targetUnit!=NULL){
|
if(targetUnit!=NULL){
|
||||||
//attack enemies
|
//attack enemies
|
||||||
if(!isAlly(targetUnit)){
|
if(!isAlly(targetUnit)){
|
||||||
|
@ -750,6 +858,12 @@ bool Unit::update(){
|
||||||
highlight-= 1.f/(highlightTime*GameConstants::updateFps);
|
highlight-= 1.f/(highlightTime*GameConstants::updateFps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
//speed
|
//speed
|
||||||
int speed= currSkill->getTotalSpeed(&totalUpgrade);
|
int speed= currSkill->getTotalSpeed(&totalUpgrade);
|
||||||
|
|
||||||
|
@ -833,6 +947,12 @@ bool Unit::update(){
|
||||||
void Unit::tick() {
|
void Unit::tick() {
|
||||||
|
|
||||||
if(isAlive()) {
|
if(isAlive()) {
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//regenerate hp
|
//regenerate hp
|
||||||
hp+= type->getHpRegeneration();
|
hp+= type->getHpRegeneration();
|
||||||
if(hp>type->getTotalMaxHp(&totalUpgrade)){
|
if(hp>type->getTotalMaxHp(&totalUpgrade)){
|
||||||
|
@ -857,6 +977,12 @@ int Unit::update2(){
|
||||||
|
|
||||||
bool Unit::computeEp(){
|
bool Unit::computeEp(){
|
||||||
|
|
||||||
|
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 not enough ep
|
//if not enough ep
|
||||||
if(ep-currSkill->getEpCost() < 0){
|
if(ep-currSkill->getEpCost() < 0){
|
||||||
return true;
|
return true;
|
||||||
|
@ -864,6 +990,13 @@ bool Unit::computeEp(){
|
||||||
|
|
||||||
//decrease ep
|
//decrease ep
|
||||||
ep-= currSkill->getEpCost();
|
ep-= currSkill->getEpCost();
|
||||||
|
|
||||||
|
if(getType() == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: getType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(ep>getType()->getTotalMaxEp(&totalUpgrade)){
|
if(ep>getType()->getTotalMaxEp(&totalUpgrade)){
|
||||||
ep= getType()->getTotalMaxEp(&totalUpgrade);
|
ep= getType()->getTotalMaxEp(&totalUpgrade);
|
||||||
}
|
}
|
||||||
|
@ -873,6 +1006,12 @@ bool Unit::computeEp(){
|
||||||
|
|
||||||
bool Unit::repair(){
|
bool Unit::repair(){
|
||||||
|
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//increase hp
|
//increase hp
|
||||||
hp+= getType()->getMaxHp()/type->getProductionTime() + 1;
|
hp+= getType()->getMaxHp()/type->getProductionTime() + 1;
|
||||||
if(hp>(getType()->getTotalMaxHp(&totalUpgrade))){
|
if(hp>(getType()->getTotalMaxHp(&totalUpgrade))){
|
||||||
|
@ -895,6 +1034,12 @@ bool Unit::decHp(int i){
|
||||||
|
|
||||||
hp-=i;
|
hp-=i;
|
||||||
|
|
||||||
|
if(type == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//startDamageParticles
|
//startDamageParticles
|
||||||
if(hp<type->getMaxHp()/2 ){
|
if(hp<type->getMaxHp()/2 ){
|
||||||
startDamageParticles();
|
startDamageParticles();
|
||||||
|
@ -992,6 +1137,12 @@ string Unit::getDesc() const{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::applyUpgrade(const UpgradeType *upgradeType){
|
void Unit::applyUpgrade(const UpgradeType *upgradeType){
|
||||||
|
if(upgradeType == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: upgradeType == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
if(upgradeType->isAffected(type)){
|
if(upgradeType->isAffected(type)){
|
||||||
totalUpgrade.sum(upgradeType);
|
totalUpgrade.sum(upgradeType);
|
||||||
hp+= upgradeType->getMaxHp();
|
hp+= upgradeType->getMaxHp();
|
||||||
|
@ -1015,8 +1166,21 @@ void Unit::incKills(){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::morph(const MorphCommandType *mct){
|
bool Unit::morph(const MorphCommandType *mct){
|
||||||
|
|
||||||
|
if(mct == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: mct == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
const UnitType *morphUnitType= mct->getMorphUnit();
|
const UnitType *morphUnitType= mct->getMorphUnit();
|
||||||
|
|
||||||
|
if(morphUnitType == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: morphUnitType == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
Field morphUnitField=fLand;
|
Field morphUnitField=fLand;
|
||||||
if(morphUnitType->getField(fAir)) morphUnitField=fAir;
|
if(morphUnitType->getField(fAir)) morphUnitField=fAir;
|
||||||
if(morphUnitType->getField(fLand)) morphUnitField=fLand;
|
if(morphUnitType->getField(fLand)) morphUnitField=fLand;
|
||||||
|
@ -1086,8 +1250,8 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(command == NULL) {
|
if(command == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command == NULL\n",__FILE__,__FUNCTION__,__LINE__);
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
//if not operative or has not command type => fail
|
//if not operative or has not command type => fail
|
||||||
|
@ -1106,8 +1270,8 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
|
|
||||||
//check produced
|
//check produced
|
||||||
if(command->getCommandType() == NULL) {
|
if(command->getCommandType() == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command->getCommandType() == NULL\n",__FILE__,__FUNCTION__,__LINE__);
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command->getCommandType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,8 +1292,8 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
const UnitType *builtUnit= command->getUnitType();
|
const UnitType *builtUnit= command->getUnitType();
|
||||||
|
|
||||||
if(builtUnit == NULL) {
|
if(builtUnit == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: builtUnit == NULL\n",__FILE__,__FUNCTION__,__LINE__);
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: builtUnit == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,8 +1310,8 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
||||||
|
|
||||||
if(uct == NULL) {
|
if(uct == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: uct == NULL\n",__FILE__,__FUNCTION__,__LINE__);
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: uct == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,6 +1327,17 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
|
|
||||||
void Unit::applyCommand(Command *command){
|
void Unit::applyCommand(Command *command){
|
||||||
|
|
||||||
|
if(command == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
else if(command->getCommandType() == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command->getCommandType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//check produced
|
//check produced
|
||||||
const ProducibleType *produced= command->getCommandType()->getProduced();
|
const ProducibleType *produced= command->getCommandType()->getProduced();
|
||||||
if(produced!=NULL){
|
if(produced!=NULL){
|
||||||
|
@ -1177,12 +1352,30 @@ void Unit::applyCommand(Command *command){
|
||||||
//upgrade command specific
|
//upgrade command specific
|
||||||
else if(command->getCommandType()->getClass()==ccUpgrade){
|
else if(command->getCommandType()->getClass()==ccUpgrade){
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
||||||
|
|
||||||
|
if(uct == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: uct == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
faction->startUpgrade(uct->getProducedUpgrade());
|
faction->startUpgrade(uct->getProducedUpgrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResult Unit::undoCommand(Command *command){
|
CommandResult Unit::undoCommand(Command *command){
|
||||||
|
|
||||||
|
if(command == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
else if(command->getCommandType() == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: command->getCommandType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
//return cost
|
//return cost
|
||||||
const ProducibleType *produced= command->getCommandType()->getProduced();
|
const ProducibleType *produced= command->getCommandType()->getProduced();
|
||||||
if(produced!=NULL){
|
if(produced!=NULL){
|
||||||
|
@ -1199,6 +1392,13 @@ CommandResult Unit::undoCommand(Command *command){
|
||||||
//upgrade command cancel from list
|
//upgrade command cancel from list
|
||||||
if(command->getCommandType()->getClass() == ccUpgrade){
|
if(command->getCommandType()->getClass() == ccUpgrade){
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(command->getCommandType());
|
||||||
|
|
||||||
|
if(uct == NULL) {
|
||||||
|
char szBuf[4096]="";
|
||||||
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: uct == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
|
||||||
faction->cancelUpgrade(uct->getProducedUpgrade());
|
faction->cancelUpgrade(uct->getProducedUpgrade());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue