- added loads of debug potential. We can now output most objects as a string for logging purposes.
- when we get the command type id not found error we now dump the whole world to a textfile - Pressing the | hotkey at any time during a game dumps the whole world to a textfile
This commit is contained in:
parent
258cd1fea1
commit
b69d808a0b
|
@ -398,7 +398,9 @@ Command* Commander::buildCommand(const NetworkCommand* networkCommand) const{
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for network command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.",
|
sprintf(szBuf,"In [%s::%s Line: %d] Can not find command type for network command = [%s]\n%s\n in unit = %d [%s][%s].\nGame out of synch.",
|
||||||
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str());
|
__FILE__,__FUNCTION__,__LINE__,networkCommand->toString().c_str(),unit->getType()->getCommandTypeListDesc().c_str(),unit->getId(), unit->getFullName().c_str(),unit->getDesc().c_str());
|
||||||
|
|
||||||
throw runtime_error(szBuf);
|
std::string worldLog = world->DumpWorldToLog();
|
||||||
|
std::string sError = "worldLog = " + worldLog + " " + string(szBuf);
|
||||||
|
throw runtime_error(sError);
|
||||||
}
|
}
|
||||||
|
|
||||||
CardinalDir facing;
|
CardinalDir facing;
|
||||||
|
|
|
@ -66,8 +66,8 @@ public:
|
||||||
assertDirValid(v);
|
assertDirValid(v);
|
||||||
value = static_cast<Enum>(v);
|
value = static_cast<Enum>(v);
|
||||||
}
|
}
|
||||||
operator Enum() { return value; }
|
operator Enum() const { return value; }
|
||||||
//int asInt() { return (int)value; }
|
int asInt() const { return (int)value; }
|
||||||
|
|
||||||
static void assertDirValid(int v) { assert(v >= 0 && v < 4); }
|
static void assertDirValid(int v) { assert(v >= 0 && v < 4); }
|
||||||
void operator++() {
|
void operator++() {
|
||||||
|
|
|
@ -342,6 +342,10 @@ void Gui::hotKey(char key){
|
||||||
else if(key=='?') {
|
else if(key=='?') {
|
||||||
this->showDebugUI = !this->showDebugUI;
|
this->showDebugUI = !this->showDebugUI;
|
||||||
}
|
}
|
||||||
|
else if(key=='|') {
|
||||||
|
std::string worldLog = world->DumpWorldToLog();
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str());
|
||||||
|
}
|
||||||
else if(key=='R'){
|
else if(key=='R'){
|
||||||
// Here the user triggers a unit rotation while placing a unit
|
// Here the user triggers a unit rotation while placing a unit
|
||||||
if(allowRotateUnits == true && isPlacingBuilding()) {
|
if(allowRotateUnits == true && isPlacingBuilding()) {
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#include "command_type.h"
|
#include "command_type.h"
|
||||||
#include "leak_dumper.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "conversion.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
@ -63,4 +64,10 @@ void Command::setUnit(Unit *unit){
|
||||||
this->unitRef= unit;
|
this->unitRef= unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Command::toString() const {
|
||||||
|
std::string result;
|
||||||
|
result = "commandType = " + commandType->toString() + " pos = " + pos.getString() + " facing = " + intToStr(facing.asInt());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
|
@ -55,6 +55,8 @@ public:
|
||||||
void setCommandType(const CommandType *commandType);
|
void setCommandType(const CommandType *commandType);
|
||||||
void setPos(const Vec2i &pos);
|
void setPos(const Vec2i &pos);
|
||||||
void setUnit(Unit *unit);
|
void setUnit(Unit *unit);
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -478,4 +478,40 @@ void Faction::resetResourceAmount(const ResourceType *rt){
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Faction::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result = "FactionIndex = " + intToStr(this->index) + "\n";
|
||||||
|
result += "teamIndex = " + intToStr(this->teamIndex) + "\n";
|
||||||
|
result += "startLocationIndex = " + intToStr(this->startLocationIndex) + "\n";
|
||||||
|
result += "thisFaction = " + intToStr(this->thisFaction) + "\n";
|
||||||
|
result += "control = " + intToStr(this->control) + "\n";
|
||||||
|
|
||||||
|
result += this->factionType->toString() + "\n";
|
||||||
|
|
||||||
|
result += this->upgradeManager.toString() + "\n";
|
||||||
|
|
||||||
|
result += "ResourceCount = " + intToStr(resources.size()) + "\n";
|
||||||
|
for(int idx = 0; idx < resources.size(); idx ++) {
|
||||||
|
result += "index = " + intToStr(idx) + " " + resources[idx].getDescription() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "StoreCount = " + intToStr(store.size()) + "\n";
|
||||||
|
for(int idx = 0; idx < store.size(); idx ++) {
|
||||||
|
result += "index = " + intToStr(idx) + " " + store[idx].getDescription() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "Allies = " + intToStr(allies.size()) + "\n";
|
||||||
|
for(int idx = 0; idx < allies.size(); idx ++) {
|
||||||
|
result += "index = " + intToStr(idx) + " name: " + allies[idx]->factionType->getName() + " factionindex = " + intToStr(allies[idx]->index) + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "Units = " + intToStr(units.size()) + "\n";
|
||||||
|
for(int idx = 0; idx < units.size(); idx ++) {
|
||||||
|
result += units[idx]->toString() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -133,6 +133,8 @@ public:
|
||||||
void incResourceAmount(const ResourceType *rt, int amount);
|
void incResourceAmount(const ResourceType *rt, int amount);
|
||||||
void setResourceBalance(const ResourceType *rt, int balance);
|
void setResourceBalance(const ResourceType *rt, int balance);
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void limitResourcesToStore();
|
void limitResourcesToStore();
|
||||||
void resetResourceAmount(const ResourceType *rt);
|
void resetResourceAmount(const ResourceType *rt);
|
||||||
|
|
|
@ -73,6 +73,17 @@ Vec2i UnitPath::pop(){
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string UnitPath::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result = "unit path blockCount = " + intToStr(blockCount) + " pathQueue size = " + intToStr(pathQueue.size());
|
||||||
|
for(int idx = 0; idx < pathQueue.size(); idx++) {
|
||||||
|
result += " index = " + intToStr(idx) + " " + pathQueue[idx].getString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class UnitReference
|
// class UnitReference
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -128,6 +139,7 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map
|
||||||
this->faction=faction;
|
this->faction=faction;
|
||||||
this->map= map;
|
this->map= map;
|
||||||
level= NULL;
|
level= NULL;
|
||||||
|
loadType= NULL;
|
||||||
|
|
||||||
setModelFacing(placeFacing);
|
setModelFacing(placeFacing);
|
||||||
|
|
||||||
|
@ -1241,4 +1253,80 @@ void Unit::logSynchData(string source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Unit::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
/*
|
||||||
|
result += "id = " + intToStr(this->id);
|
||||||
|
result += " name [" + this->getFullName() + "]";
|
||||||
|
result += " desc: " + this->getDesc();
|
||||||
|
*/
|
||||||
|
result += "id = " + intToStr(this->id);
|
||||||
|
if(this->type != NULL) {
|
||||||
|
result += " name [" + this->type->getName() + "]";
|
||||||
|
}
|
||||||
|
result += " hp = " + intToStr(this->hp);
|
||||||
|
result += " ep = " + intToStr(this->ep);
|
||||||
|
result += " loadCount = " + intToStr(this->loadCount);
|
||||||
|
result += " deadCount = " + intToStr(this->deadCount);
|
||||||
|
result += " progress = " + floatToStr(this->progress);
|
||||||
|
result += " lastAnimProgress = " + floatToStr(this->lastAnimProgress);
|
||||||
|
result += " animProgress = " + floatToStr(this->animProgress);
|
||||||
|
result += " highlight = " + floatToStr(this->highlight);
|
||||||
|
result += " progress2 = " + intToStr(this->progress2);
|
||||||
|
result += " kills = " + intToStr(this->kills);
|
||||||
|
|
||||||
|
if(this->targetRef.getUnit() != NULL) {
|
||||||
|
result += " targetRef = " + this->targetRef.getUnit()->toString();
|
||||||
|
}
|
||||||
|
result += " currField = " + intToStr(this->currField);
|
||||||
|
result += " targetField = " + intToStr(this->targetField);
|
||||||
|
if(level != NULL) {
|
||||||
|
result += " level = " + level->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " pos = " + pos.getString();
|
||||||
|
result += " lastPos = " + lastPos.getString();
|
||||||
|
result += " targetPos = " + targetPos.getString();
|
||||||
|
result += " targetVec = " + targetVec.getString();
|
||||||
|
result += " meetingPos = " + meetingPos.getString();
|
||||||
|
|
||||||
|
result += " lastRotation = " + floatToStr(this->lastRotation);
|
||||||
|
result += " targetRotation = " + floatToStr(this->targetRotation);
|
||||||
|
result += " rotation = " + floatToStr(this->rotation);
|
||||||
|
|
||||||
|
if(loadType != NULL) {
|
||||||
|
result += " loadType = " + loadType->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currSkill != NULL) {
|
||||||
|
result += " currSkill = " + currSkill->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " toBeUndertaken = " + intToStr(this->toBeUndertaken);
|
||||||
|
result += " alive = " + intToStr(this->alive);
|
||||||
|
result += " showUnitParticles = " + intToStr(this->showUnitParticles);
|
||||||
|
|
||||||
|
result += " totalUpgrade = " + totalUpgrade.toString();
|
||||||
|
|
||||||
|
result += " " + unitPath.toString() + "\n";
|
||||||
|
|
||||||
|
result += "Command count = " + intToStr(commands.size()) + "\n";
|
||||||
|
|
||||||
|
int cmdIdx = 0;
|
||||||
|
for(Commands::const_iterator iterList = commands.begin(); iterList != commands.end(); ++iterList) {
|
||||||
|
result += " index = " + intToStr(cmdIdx) + " ";
|
||||||
|
const Command *cmd = *iterList;
|
||||||
|
if(cmd != NULL) {
|
||||||
|
result += cmd->toString() + "\n";
|
||||||
|
}
|
||||||
|
cmdIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "allowRotateUnits = " + intToStr(allowRotateUnits) + "\n";
|
||||||
|
result += "modelFacing = " + intToStr(modelFacing.asInt()) + "\n";
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -114,6 +114,8 @@ public:
|
||||||
void incBlockCount();
|
void incBlockCount();
|
||||||
void push(const Vec2i &path);
|
void push(const Vec2i &path);
|
||||||
Vec2i pop();
|
Vec2i pop();
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
|
@ -311,6 +313,8 @@ public:
|
||||||
|
|
||||||
bool isMeetingPointSettable() const;
|
bool isMeetingPointSettable() const;
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float computeHeight(const Vec2i &pos) const;
|
float computeHeight(const Vec2i &pos) const;
|
||||||
void updateTarget();
|
void updateTarget();
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#include "upgrade.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "unit.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "upgrade_type.h"
|
||||||
|
#include "conversion.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Upgrade
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
Upgrade::Upgrade(const UpgradeType *type, int factionIndex){
|
||||||
|
state= usUpgrading;
|
||||||
|
this->factionIndex= factionIndex;
|
||||||
|
this->type= type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============== get ==============
|
||||||
|
|
||||||
|
UpgradeState Upgrade::getState() const{
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Upgrade::getFactionIndex() const{
|
||||||
|
return factionIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UpgradeType * Upgrade::getType() const{
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============== set ==============
|
||||||
|
|
||||||
|
void Upgrade::setState(UpgradeState state){
|
||||||
|
this->state= state;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Upgrade::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result += " state = " + intToStr(state) + " factionIndex = " + intToStr(factionIndex);
|
||||||
|
if(type != NULL) {
|
||||||
|
result += " type = " + type->getReqDesc();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class UpgradeManager
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
UpgradeManager::~UpgradeManager(){
|
||||||
|
deleteValues(upgrades.begin(), upgrades.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeManager::startUpgrade(const UpgradeType *upgradeType, int factionIndex){
|
||||||
|
upgrades.push_back(new Upgrade(upgradeType, factionIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeManager::cancelUpgrade(const UpgradeType *upgradeType){
|
||||||
|
Upgrades::iterator it;
|
||||||
|
|
||||||
|
for(it=upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getType()==upgradeType){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(it!=upgrades.end()){
|
||||||
|
upgrades.erase(it);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw runtime_error("Error canceling upgrade, upgrade not found in upgrade manager");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeManager::finishUpgrade(const UpgradeType *upgradeType){
|
||||||
|
Upgrades::iterator it;
|
||||||
|
|
||||||
|
for(it=upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getType()==upgradeType){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(it!=upgrades.end()){
|
||||||
|
(*it)->setState(usUpgraded);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw runtime_error("Error finishing upgrade, upgrade not found in upgrade manager");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpgradeManager::isUpgradingOrUpgraded(const UpgradeType *upgradeType) const{
|
||||||
|
Upgrades::const_iterator it;
|
||||||
|
|
||||||
|
for(it= upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getType()==upgradeType){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpgradeManager::isUpgraded(const UpgradeType *upgradeType) const{
|
||||||
|
for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getType()==upgradeType && (*it)->getState()==usUpgraded){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UpgradeManager::isUpgrading(const UpgradeType *upgradeType) const{
|
||||||
|
for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getType()==upgradeType && (*it)->getState()==usUpgrading){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeManager::computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUpgrade) const{
|
||||||
|
totalUpgrade->reset();
|
||||||
|
for(Upgrades::const_iterator it= upgrades.begin(); it!=upgrades.end(); it++){
|
||||||
|
if((*it)->getFactionIndex()==unit->getFactionIndex()
|
||||||
|
&& (*it)->getType()->isAffected(unit->getType())
|
||||||
|
&& (*it)->getState()==usUpgraded)
|
||||||
|
totalUpgrade->sum((*it)->getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string UpgradeManager::toString() const {
|
||||||
|
std::string result = "UpgradeCount: " + intToStr(this->getUpgradeCount());
|
||||||
|
for(int idx = 0; idx < upgrades.size(); idx++) {
|
||||||
|
result += " index = " + intToStr(idx) + " " + upgrades[idx]->toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}// end namespace
|
|
@ -0,0 +1,92 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _GLEST_GAME_UPGRADE_H_
|
||||||
|
#define _GLEST_GAME_UPGRADE_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
class Unit;
|
||||||
|
class UpgradeType;
|
||||||
|
|
||||||
|
enum UpgradeState{
|
||||||
|
usUpgrading,
|
||||||
|
usUpgraded,
|
||||||
|
|
||||||
|
upgradeStateCount
|
||||||
|
};
|
||||||
|
|
||||||
|
class UpgradeManager;
|
||||||
|
class TotalUpgrade;
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class Upgrade
|
||||||
|
//
|
||||||
|
/// A bonus to an UnitType
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class Upgrade{
|
||||||
|
private:
|
||||||
|
UpgradeState state;
|
||||||
|
int factionIndex;
|
||||||
|
const UpgradeType *type;
|
||||||
|
|
||||||
|
friend class UpgradeManager;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Upgrade(const UpgradeType *upgradeType, int factionIndex);
|
||||||
|
|
||||||
|
private:
|
||||||
|
//get
|
||||||
|
UpgradeState getState() const;
|
||||||
|
int getFactionIndex() const;
|
||||||
|
const UpgradeType * getType() const;
|
||||||
|
|
||||||
|
//set
|
||||||
|
void setState(UpgradeState state);
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// class UpgradeManager
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
class UpgradeManager{
|
||||||
|
private:
|
||||||
|
typedef vector<Upgrade*> Upgrades;
|
||||||
|
Upgrades upgrades;
|
||||||
|
public:
|
||||||
|
~UpgradeManager();
|
||||||
|
|
||||||
|
int getUpgradeCount() const {return upgrades.size();}
|
||||||
|
|
||||||
|
void startUpgrade(const UpgradeType *upgradeType, int factionIndex);
|
||||||
|
void cancelUpgrade(const UpgradeType *upgradeType);
|
||||||
|
void finishUpgrade(const UpgradeType *upgradeType);
|
||||||
|
|
||||||
|
bool isUpgraded(const UpgradeType *upgradeType) const;
|
||||||
|
bool isUpgrading(const UpgradeType *upgradeType) const;
|
||||||
|
bool isUpgradingOrUpgraded(const UpgradeType *upgradeType) const;
|
||||||
|
void computeTotalUpgrade(const Unit *unit, TotalUpgrade *totalUpgrade) const;
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -18,6 +18,7 @@
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
|
#include "conversion.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
@ -168,4 +169,22 @@ int FactionType::getStartingResourceAmount(const ResourceType *resourceType) con
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string FactionType::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result = "Faction Name: " + name + "\n";
|
||||||
|
|
||||||
|
result += "Unit Type List count = " + intToStr(this->getUnitTypeCount()) + "\n";
|
||||||
|
for(int i=0; i<unitTypes.size();i++) {
|
||||||
|
result += unitTypes[i].toString() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
result += "Upgrade Type List count = " + intToStr(this->getUpgradeTypeCount()) + "\n";
|
||||||
|
for(int i=0; i<upgradeTypes.size();i++) {
|
||||||
|
result += "index: " + intToStr(i) + " " + upgradeTypes[i].getReqDesc() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _GLEST_GAME_FACTIONTYPE_H_
|
||||||
|
#define _GLEST_GAME_FACTIONTYPE_H_
|
||||||
|
|
||||||
|
#include "unit_type.h"
|
||||||
|
#include "upgrade_type.h"
|
||||||
|
#include "sound.h"
|
||||||
|
|
||||||
|
using Shared::Sound::StrSound;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class FactionType
|
||||||
|
//
|
||||||
|
/// Each of the possible factions the user can select
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class FactionType{
|
||||||
|
private:
|
||||||
|
typedef pair<const UnitType*, int> PairPUnitTypeInt;
|
||||||
|
typedef vector<UnitType> UnitTypes;
|
||||||
|
typedef vector<UpgradeType> UpgradeTypes;
|
||||||
|
typedef vector<PairPUnitTypeInt> StartingUnits;
|
||||||
|
typedef vector<Resource> Resources;
|
||||||
|
|
||||||
|
private:
|
||||||
|
string name;
|
||||||
|
UnitTypes unitTypes;
|
||||||
|
UpgradeTypes upgradeTypes;
|
||||||
|
StartingUnits startingUnits;
|
||||||
|
Resources startingResources;
|
||||||
|
StrSound *music;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//init
|
||||||
|
FactionType();
|
||||||
|
void load(const string &dir, const TechTree *techTree, Checksum* checksum);
|
||||||
|
~FactionType();
|
||||||
|
|
||||||
|
//get
|
||||||
|
int getUnitTypeCount() const {return unitTypes.size();}
|
||||||
|
int getUpgradeTypeCount() const {return upgradeTypes.size();}
|
||||||
|
string getName() const {return name;}
|
||||||
|
const UnitType *getUnitType(int i) const {return &unitTypes[i];}
|
||||||
|
const UpgradeType *getUpgradeType(int i) const {return &upgradeTypes[i];}
|
||||||
|
StrSound *getMusic() const {return music;}
|
||||||
|
int getStartingUnitCount() const {return startingUnits.size();}
|
||||||
|
const UnitType *getStartingUnit(int i) const {return startingUnits[i].first;}
|
||||||
|
int getStartingUnitAmount(int i) const {return startingUnits[i].second;}
|
||||||
|
|
||||||
|
const UnitType *getUnitType(const string &name) const;
|
||||||
|
const UpgradeType *getUpgradeType(const string &name) const;
|
||||||
|
int getStartingResourceAmount(const ResourceType *resourceType) const;
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -604,4 +604,69 @@ string UnitType::getCommandTypeListDesc() const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string UnitType::toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result = "Unit Name: [" + name + "] id = " + intToStr(id);
|
||||||
|
result += " maxHp = " + intToStr(maxHp);
|
||||||
|
result += " hpRegeneration = " + intToStr(hpRegeneration);
|
||||||
|
result += " maxEp = " + intToStr(maxEp);
|
||||||
|
result += " epRegeneration = " + intToStr(epRegeneration);
|
||||||
|
|
||||||
|
for(int i = 0; i < fieldCount; i++) {
|
||||||
|
result += " fields index = " + intToStr(i) + " value = " + intToStr(fields[i]);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < pCount; i++) {
|
||||||
|
result += " properties index = " + intToStr(i) + " value = " + intToStr(properties[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " armor = " + intToStr(armor);
|
||||||
|
|
||||||
|
if(armorType != NULL) {
|
||||||
|
result += " armorType Name: [" + armorType->getName() + " id = " + intToStr(armorType->getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " light = " + intToStr(light);
|
||||||
|
result += " lightColor = " + lightColor.getString();
|
||||||
|
result += " multiSelect = " + intToStr(multiSelect);
|
||||||
|
result += " sight = " + intToStr(sight);
|
||||||
|
result += " size = " + intToStr(size);
|
||||||
|
result += " height = " + intToStr(height);
|
||||||
|
result += " rotatedBuildPos = " + floatToStr(rotatedBuildPos);
|
||||||
|
result += " rotationAllowed = " + intToStr(rotationAllowed);
|
||||||
|
|
||||||
|
if(cellMap != NULL) {
|
||||||
|
result += " cellMap:";
|
||||||
|
for(int i = 0; i < size; ++i) {
|
||||||
|
for(int j = 0; j < size; ++j){
|
||||||
|
result += " i = " + intToStr(i) + " j = " + intToStr(j) + " value = " + intToStr(cellMap[i*size+j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " skillTypes:";
|
||||||
|
for(int i = 0; i < skillTypes.size(); ++i) {
|
||||||
|
result += " i = " + intToStr(i) + " " + skillTypes[i]->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " commandTypes:";
|
||||||
|
for(int i = 0; i < commandTypes.size(); ++i) {
|
||||||
|
result += " i = " + intToStr(i) + " " + commandTypes[i]->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " storedResources:";
|
||||||
|
for(int i = 0; i < storedResources.size(); ++i) {
|
||||||
|
result += " i = " + intToStr(i) + " " + storedResources[i].getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " levels:";
|
||||||
|
for(int i = 0; i < levels.size(); ++i) {
|
||||||
|
result += " i = " + intToStr(i) + " " + levels[i].getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
result += " meetingPoint = " + intToStr(meetingPoint);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -189,6 +189,8 @@ public:
|
||||||
float getRotatedBuildPos() { return rotatedBuildPos; }
|
float getRotatedBuildPos() { return rotatedBuildPos; }
|
||||||
void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
|
void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void computeFirstStOfClass();
|
void computeFirstStOfClass();
|
||||||
void computeFirstCtOfClass();
|
void computeFirstCtOfClass();
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#ifndef _GLEST_GAME_UPGRADETYPE_H_
|
||||||
|
#define _GLEST_GAME_UPGRADETYPE_H_
|
||||||
|
|
||||||
|
#include "element_type.h"
|
||||||
|
#include "checksum.h"
|
||||||
|
#include "conversion.h"
|
||||||
|
|
||||||
|
using Shared::Util::Checksum;
|
||||||
|
using namespace Shared::Util;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
class TechTree;
|
||||||
|
class FactionType;
|
||||||
|
class UnitType;
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// class UpgradeTypeBase
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
class UpgradeTypeBase{
|
||||||
|
protected:
|
||||||
|
int maxHp;
|
||||||
|
int sight;
|
||||||
|
int maxEp;
|
||||||
|
int armor;
|
||||||
|
int attackStrength;
|
||||||
|
int attackRange;
|
||||||
|
int moveSpeed;
|
||||||
|
int prodSpeed;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int getMaxHp() const {return maxHp;}
|
||||||
|
int getSight() const {return sight;}
|
||||||
|
int getMaxEp() const {return maxEp;}
|
||||||
|
int getArmor() const {return armor;}
|
||||||
|
int getAttackStrength() const {return attackStrength;}
|
||||||
|
int getAttackRange() const {return attackRange;}
|
||||||
|
int getMoveSpeed() const {return moveSpeed;}
|
||||||
|
int getProdSpeed() const {return prodSpeed;}
|
||||||
|
|
||||||
|
std::string toString() const {
|
||||||
|
std::string result = "";
|
||||||
|
|
||||||
|
result += "maxHp = " + intToStr(maxHp);
|
||||||
|
result += " sight = " + intToStr(sight);
|
||||||
|
result += " maxEp = " + intToStr(maxEp);
|
||||||
|
result += " armor = " + intToStr(armor);
|
||||||
|
result += " attackStrength = " + intToStr(attackStrength);
|
||||||
|
result += " attackRange = " + intToStr(attackRange);
|
||||||
|
result += " moveSpeed = " + intToStr(moveSpeed);
|
||||||
|
result += " prodSpeed = " + intToStr(prodSpeed);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// class UpgradeType
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
class UpgradeType: public UpgradeTypeBase, public ProducibleType{
|
||||||
|
private:
|
||||||
|
vector<const UnitType*> effects;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void preLoad(const string &dir);
|
||||||
|
void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum);
|
||||||
|
|
||||||
|
//get all
|
||||||
|
int getEffectCount() const {return effects.size();}
|
||||||
|
const UnitType * getEffect(int i) const {return effects[i];}
|
||||||
|
bool isAffected(const UnitType *unitType) const;
|
||||||
|
|
||||||
|
//other methods
|
||||||
|
virtual string getReqDesc() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// class TotalUpgrade
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
class TotalUpgrade: public UpgradeTypeBase{
|
||||||
|
public:
|
||||||
|
TotalUpgrade();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
void sum(const UpgradeType *ut);
|
||||||
|
void incLevel(const UnitType *ut);
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -800,4 +800,41 @@ void World::computeFow(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string World::DumpWorldToLog() const {
|
||||||
|
string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log");
|
||||||
|
if(getGameReadWritePath() != "") {
|
||||||
|
debugWorldLogFile = getGameReadWritePath() + debugWorldLogFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream logFile;
|
||||||
|
logFile.open(debugWorldLogFile.c_str(), ios_base::out | ios_base::trunc);
|
||||||
|
|
||||||
|
logFile << "World debug information:" << std::endl;
|
||||||
|
logFile << "========================" << std::endl;
|
||||||
|
|
||||||
|
//factions (and their related info)
|
||||||
|
for(int i = 0; i < getFactionCount(); ++i) {
|
||||||
|
logFile << "Faction detail for index: " << i << std::endl;
|
||||||
|
logFile << "--------------------------" << std::endl;
|
||||||
|
logFile << getFaction(i)->toString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//undertake the dead
|
||||||
|
logFile << "Undertake stats:" << std::endl;
|
||||||
|
for(int i = 0; i < getFactionCount(); ++i){
|
||||||
|
logFile << "Faction: " << getFaction(i)->getType()->getName() << std::endl;
|
||||||
|
int unitCount = getFaction(i)->getUnitCount();
|
||||||
|
for(int j= unitCount - 1; j >= 0; j--){
|
||||||
|
Unit *unit= getFaction(i)->getUnit(j);
|
||||||
|
if(unit->getToBeUndertaken()) {
|
||||||
|
logFile << "Undertake unit index = " << j << unit->getFullName() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logFile.close();
|
||||||
|
|
||||||
|
return debugWorldLogFile;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -153,6 +153,7 @@ public:
|
||||||
Game * getGame() { return game; }
|
Game * getGame() { return game; }
|
||||||
|
|
||||||
void setFogOfWar(bool value);
|
void setFogOfWar(bool value);
|
||||||
|
std::string DumpWorldToLog() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue