2010-03-19 19:58:46 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o 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_FACTION_H_
|
|
|
|
|
#define _GLEST_GAME_FACTION_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
#include "upgrade.h"
|
|
|
|
|
#include "texture.h"
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
#include "game_constants.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
|
#include "leak_dumper.h"
|
2010-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
|
|
using std::map;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
using Shared::Graphics::Texture2D;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
class Unit;
|
|
|
|
|
class TechTree;
|
|
|
|
|
class FactionType;
|
|
|
|
|
class ProducibleType;
|
|
|
|
|
class RequirableType;
|
|
|
|
|
class CommandType;
|
|
|
|
|
class UnitType;
|
|
|
|
|
class Game;
|
|
|
|
|
class ScriptManager;
|
|
|
|
|
class World;
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class Faction
|
|
|
|
|
//
|
|
|
|
|
/// Each of the game players
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-10-20 00:26:49 +02:00
|
|
|
|
class FactionPathSuccessCache {
|
|
|
|
|
public:
|
|
|
|
|
// The unit Size for the path findings
|
|
|
|
|
int unitSize;
|
|
|
|
|
// a List of paths with their # success counts
|
|
|
|
|
vector<std::pair<vector<Vec2i>, int> > pathQueue;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Faction {
|
2010-03-19 19:58:46 +01:00
|
|
|
|
private:
|
|
|
|
|
typedef vector<Resource> Resources;
|
|
|
|
|
typedef vector<Resource> Store;
|
|
|
|
|
typedef vector<Faction*> Allies;
|
|
|
|
|
typedef vector<Unit*> Units;
|
|
|
|
|
typedef map<int, Unit*> UnitMap;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
UpgradeManager upgradeManager;
|
|
|
|
|
|
|
|
|
|
Resources resources;
|
|
|
|
|
Store store;
|
|
|
|
|
Allies allies;
|
|
|
|
|
Units units;
|
|
|
|
|
UnitMap unitMap;
|
|
|
|
|
World *world;
|
|
|
|
|
ScriptManager *scriptManager;
|
|
|
|
|
|
|
|
|
|
ControlType control;
|
|
|
|
|
|
|
|
|
|
Texture2D *texture;
|
|
|
|
|
const FactionType *factionType;
|
|
|
|
|
|
|
|
|
|
int index;
|
|
|
|
|
int teamIndex;
|
|
|
|
|
int startLocationIndex;
|
|
|
|
|
|
|
|
|
|
bool thisFaction;
|
|
|
|
|
|
2010-10-20 00:26:49 +02:00
|
|
|
|
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
|
|
|
|
|
2010-03-19 19:58:46 +01:00
|
|
|
|
public:
|
2010-08-04 18:56:24 +02:00
|
|
|
|
Faction();
|
|
|
|
|
~Faction();
|
|
|
|
|
|
2010-03-19 19:58:46 +01:00
|
|
|
|
void init(
|
|
|
|
|
const FactionType *factionType, ControlType control, TechTree *techTree, Game *game,
|
|
|
|
|
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
|
|
|
|
void end();
|
|
|
|
|
|
|
|
|
|
//get
|
|
|
|
|
const Resource *getResource(const ResourceType *rt) const;
|
|
|
|
|
const Resource *getResource(int i) const {return &resources[i];}
|
|
|
|
|
int getStoreAmount(const ResourceType *rt) const;
|
|
|
|
|
const FactionType *getType() const {return factionType;}
|
|
|
|
|
int getIndex() const {return index;}
|
|
|
|
|
int getTeam() const {return teamIndex;}
|
2010-09-14 21:10:37 +02:00
|
|
|
|
bool getCpuControl(bool enableServerControlledAI, bool isNetworkGame, NetworkRole role) const;
|
2010-03-19 19:58:46 +01:00
|
|
|
|
bool getCpuControl() const;
|
|
|
|
|
bool getCpuEasyControl() const {return control==ctCpuEasy;}
|
|
|
|
|
bool getCpuUltraControl() const {return control==ctCpuUltra;}
|
|
|
|
|
bool getCpuMegaControl() const {return control==ctCpuMega;}
|
|
|
|
|
ControlType getControlType() const {return control;}
|
|
|
|
|
Unit *getUnit(int i) const {return units[i];}
|
|
|
|
|
int getUnitCount() const {return units.size();}
|
|
|
|
|
const UpgradeManager *getUpgradeManager() const {return &upgradeManager;}
|
|
|
|
|
const Texture2D *getTexture() const {return texture;}
|
|
|
|
|
int getStartLocationIndex() const {return startLocationIndex;}
|
2010-05-20 22:19:34 +02:00
|
|
|
|
bool getThisFaction() const {return thisFaction;}
|
2010-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
|
|
//upgrades
|
|
|
|
|
void startUpgrade(const UpgradeType *ut);
|
|
|
|
|
void cancelUpgrade(const UpgradeType *ut);
|
|
|
|
|
void finishUpgrade(const UpgradeType *ut);
|
|
|
|
|
|
|
|
|
|
//cost application
|
|
|
|
|
bool applyCosts(const ProducibleType *p);
|
|
|
|
|
void applyDiscount(const ProducibleType *p, int discount);
|
|
|
|
|
void applyStaticCosts(const ProducibleType *p);
|
|
|
|
|
void applyStaticProduction(const ProducibleType *p);
|
|
|
|
|
void deApplyCosts(const ProducibleType *p);
|
|
|
|
|
void deApplyStaticCosts(const ProducibleType *p);
|
|
|
|
|
void deApplyStaticConsumption(const ProducibleType *p);
|
|
|
|
|
void applyCostsOnInterval();
|
|
|
|
|
bool checkCosts(const ProducibleType *pt);
|
|
|
|
|
|
|
|
|
|
//reqs
|
|
|
|
|
bool reqsOk(const RequirableType *rt) const;
|
|
|
|
|
bool reqsOk(const CommandType *ct) const;
|
2010-08-22 23:09:35 +02:00
|
|
|
|
int getCountForMaxUnitCount(const UnitType *unitType) const;
|
|
|
|
|
|
2010-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
|
|
//diplomacy
|
|
|
|
|
bool isAlly(const Faction *faction);
|
|
|
|
|
|
|
|
|
|
//other
|
2010-09-10 10:51:32 +02:00
|
|
|
|
Unit *findUnit(int id) const;
|
2010-03-19 19:58:46 +01:00
|
|
|
|
void addUnit(Unit *unit);
|
|
|
|
|
void removeUnit(Unit *unit);
|
|
|
|
|
void addStore(const UnitType *unitType);
|
|
|
|
|
void removeStore(const UnitType *unitType);
|
|
|
|
|
|
|
|
|
|
//resources
|
|
|
|
|
void incResourceAmount(const ResourceType *rt, int amount);
|
|
|
|
|
void setResourceBalance(const ResourceType *rt, int balance);
|
|
|
|
|
|
2010-10-19 01:09:43 +02:00
|
|
|
|
void setControlType(ControlType value) { control = value; }
|
|
|
|
|
|
2010-10-20 00:26:49 +02:00
|
|
|
|
std::vector<Vec2i> findCachedPath(const Vec2i &target, Unit *unit);
|
|
|
|
|
void addCachedPath(const Vec2i &target, Unit *unit);
|
|
|
|
|
|
2010-05-18 05:53:57 +02:00
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
2010-03-19 19:58:46 +01:00
|
|
|
|
private:
|
|
|
|
|
void limitResourcesToStore();
|
|
|
|
|
void resetResourceAmount(const ResourceType *rt);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|