Allrighty, fixed some things
Now.. all that's left:
../Source/Game/Production.cpp: In member function `const bool
Production::Proceed(std::vector<TurnEvent*, std::allocator<TurnEvent*> >&)':
../Source/Game/Production.cpp:47: no matching function for call to `Production
::Building(__gnu_cxx::__normal_iterator<BuildInPro gress*,
std::vector<BuildInProgress, std::allocator<BuildInProgress> > >&)'
../Source/Game/Production.h:118: candidates are: void
Production::Building(BuildInProgress*)
../Source/Game/Production.cpp: In member function `void
Production::Building(BuildInProgress*)':
../Source/Game/Production.cpp:125: warning: assignment to `int' from `double'
../Source/Game/Production.cpp:125: warning: argument to `int' from `double'
../Source/Game/Production.cpp: In member function `void
Production::UpdateAllow2Build(int)':
../Source/Game/Production.cpp:158: no matching function for call to `Production
::CanBuild(__gnu_cxx::__normal_iterator<Technology *, std::vector<Technology,
std::allocator<Technology> > >&)'
../Source/Game/Production.cpp:136: candidates are: const bool
Production::CanBuild(Technology*)
Code:
#include "stdafx.h"
#include "Planets.h"
#include "Colony.h"
#include "Technology.h"
#include "PlayGame.h"
#include "Production.h"
#include "Fleet.h"
#include "SolarSystem.h"
#include "Vessel.h"
#include "itoa.h"
const double Facility::GetEffisciency( void )
{
double ans = effisciency;
return ans;
}
const bool Production::Proceed( vector<TurnEvent*> &event )
{
for( vector<Facility>::iterator it = facilities.begin() ; it != facilities.end() ; ++it )
{
vector<Technology>::iterator pos = find_if( tt.begin() , tt.end() , bind2nd( mem_fun_ref( &Technology::IsNamed ) , it->name.c_str() ) );
if( (pos->mask & 0x04) == 0x04 )
it->SetOutput( pos->prodQty * it->GetEffisciency() * it->nr );
if( (pos->mask & 0x10) == 0x10 )
{
if( pos->name == "Natural Resources" )
it->SetOutput( pos->prodQty * planet.GetOre() );
else if( pos->name == "Soil Composition" )
it->SetOutput( pos->prodQty * planet.GetSoil() );
else if( pos->name == "Planet Energy Rsc." )
it->SetOutput( pos->prodQty * planet.GetEnergy() );
else if( pos->name == "Sunrays Factor" )
it->SetOutput( pos->prodQty * planet.GetSunFactor() );
}
}
int n = 0;
bool ans = !buildStack.empty();
for( vector<BuildInProgress>::iterator pos = buildStack.begin() ; pos != buildStack.end() ; ++pos )
{
Building( pos );
if( pos->IsBuilt() )
{
ans = true;
vector<Facility>::iterator at = find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::IsNamed ) , pos->name.c_str() ) );
if( at != facilities.end() )
at->nr += 1;
else
{
vector<Technology>::iterator ins = find_if( tt.begin() , tt.end() , bind2nd( mem_fun_ref( &Technology::IsNamed ) , pos->name.c_str() ) );
if( (ins->mask & 0x08) == 0x08 )
{
SolarSystem &ss = planet.ss;
Fleet *f = 0;
for( multimap<string,Fleet*>::iterator it = PlayGame::fleets.lower_bound( species ) ; it != PlayGame::fleets.upper_bound( species ) ; ++it )
if( it->second->GetPosition() == ss.GetPosition() )
{
f = it->second;
break;
}
if( !f )
{
bool ok = false;
int i = 0;
string fleetName;
while( !ok )
{
char tmp[10];
fleetName = species + itoa( ++i , tmp , 10 );
for( multimap<string,Fleet *>::iterator it = PlayGame::fleets.lower_bound( species ) ; it != PlayGame::fleets.upper_bound( species ) ; ++it )
if( it->second->name == fleetName )
break;
ok = (it == PlayGame::fleets.upper_bound( species ));
}
f = new Fleet( species , fleetName );
f->Setup( ss.GetPosition() , &planet );
f->Setup();
}
f->push_back( new Vessel( ins->prodName , species ) );
}
else
{
facilities.push_back( Facility( *ins , planet.GetEffisciency( species ) ) );
facilities.back().nr = 1;
}
}
event.push_back( this );
n += 1;
}
}
if( n > 0 && ans )
{
while( (pos = find_if( buildStack.begin() , buildStack.end() , mem_fun_ref( &BuildInProgress::IsBuilt ) )) != buildStack.end() )
buildStack.erase( pos );
UpdateAllow2Build();
}
return ans;
}
void Production::Building( BuildInProgress *bip )
{
for( vector<pair<string,int> >::iterator it = bip->buildRequisite.begin() ; it != bip->buildRequisite.end() ; ++it )
{
vector<Facility>::iterator pos = facilities.begin();
while( it->second )
{
if( (pos = find_if( pos , facilities.end() , bind2nd( mem_fun_ref( &Facility::DoesProduce ) , it->first.c_str() ) )) != facilities.end() )
if( pos->GetOutput() >= it->second )
{
pos->AddOutput( -it->second );
it->second = 0;
}
else
{
it->second -= pos->GetOutput();
pos->SetOutput( 0 );
}
else
break;
++pos;
}
}
}
const bool Production::CanBuild( Technology *t )
{
if( !t->request.empty() )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::IsNamed ) , t->request.c_str() ) ) == facilities.end() )
return false;
for( vector<pair<string,int> >::iterator it = t->inputList.begin() ; it != t->inputList.end() ; ++it )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::DoesProduce ) , it->first.c_str() ) ) == facilities.end() )
return false;
for( it = t->buildRequisite.begin() ; it != t->buildRequisite.end() ; ++it )
if( find_if( facilities.begin() , facilities.end() , bind2nd( mem_fun_ref( &Facility::DoesProduce ) , it->first.c_str() ) ) == facilities.end() )
return false;
return true;
}
void Production::UpdateAllow2Build( const int maxTechLevel )
{
availFacilities.clear();
for( vector<Technology>::iterator pos = tt.begin() ; pos != tt.end() ; ++pos )
{
if( pos->techLevel && pos->techLevel <= maxTechLevel )
if( CanBuild( pos ) )
availFacilities.push_back( pos->name );
}
}
Also the header file for it:
Code:
#if !defined( __PRODUCTION_H__ )
#define __PRODUCTION_H__
class Planets;
#include "Technology.h"
#include "PlayGame.h"
class Facility {
private:
int outputQty;
public:
string name , prodName;
vector<pair<string , int> > inputList;
int nr;
double effisciency;
Facility( Technology &tech , const double aEff = 0.0 )
: name( tech.name ) , effisciency( aEff ) , inputList( tech.inputList )
, outputQty( tech.prodQty ) , nr( tech.nr )
, prodName( tech.prodName )
{}
~Facility( void ) {}
inline Facility &operator=( const Facility &f )
{
name = f.name;
inputList = f.inputList;
effisciency = f.effisciency;
prodName = f.prodName;
outputQty = f.outputQty;
nr = f.nr;
return *this;
}
const bool IsNamed( const char *aName ) const { return name == aName; }
const bool DoesProduce( const char *aName ) const { return prodName == aName; }
const double GetOutput( void ) const { return outputQty * nr * effisciency; }
void SetOutput( const double aQty ) { outputQty = (int)aQty; }
void AddOutput( const double aQty ) { outputQty += (int)aQty; }
const double GetEffisciency( void );
};
class BuildInProgress {
public:
string name;
double progress;
vector<pair<string,int> > buildRequisite;
BuildInProgress( Technology &tech )
: name( tech.name ) , progress( 0.0 ) , buildRequisite( tech.buildRequisite )
{}
~BuildInProgress( void ) {}
const bool IsNamed( const char *aName ) const { return name == aName; }
inline BuildInProgress &operator=( const BuildInProgress &f )
{
name = f.name;
buildRequisite = f.buildRequisite;
progress = f.progress;
return *this;
}
const bool IsBuilt( void )
{
int ans = 0;
for( vector<pair<string,int> >::iterator it = buildRequisite.begin() ; it != buildRequisite.end() ; ++it )
ans += it->second;
return ans == 0;
}
};
class Production : public TurnEvent {
protected:
vector<Facility> facilities;
vector<string> availFacilities;
vector<BuildInProgress> buildStack;
TechnologyTree &tt;
Planets &planet;
public:
const string species;
Production( Planets &aPlanet , const string aSpecies )
: species( aSpecies ) , tt( PlayGame::Get( aSpecies ) ) , planet( aPlanet )
{
}
~Production( void )
{
facilities.clear();
availFacilities.clear();
}
const bool CanBuild( Technology *t );
void UpdateAllow2Build( const int maxTechLevel = 1 );
const bool Proceed( vector<TurnEvent*> &event );
void Building( BuildInProgress *bip );
};
#endif
Any clue how to fix the remaining errors.. i figured out what was happening but.. still haven't figured out all the errors.
Thanks