j_mie6
Deity
I am working on a crusade feature for my next mod and I was doing some testing (without Civ4) and created this code:
(please excuse the messiness! couldn't use the actual types!)
Am I right in thinking that this should have deleted Crusade1 and therefore the lCrusades for loop sould only display Crusade2?
if you read through the code should should get an idea of whats meant to happen... the console gives me back this:
so definatly not working correctly!
any ideas from C++ programmers that actually know what they are meant to be doing?
Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
class Crusade;
vector<Crusade*> lCrusades;
class Crusade
{
/* Variables */
/*CvCity**/ int pCity;
/*CvPlayer**/ int pTarget;
vector</*CvPlayer**/string> aParticipants;
/*PromotionTypes*/const static int pCrusader = /*GC->getInfoTypeForString("PROMOTION_CRUSADER")*/ 1;
/* Methods */
public:
Crusade (/*CvCity**/int , /*CvPlayer**/int , vector</*CvPlayer**/string>);
~Crusade ();
/*CvPlayer**/int getTarget() {return pTarget;};
/*CvCity**/int getCity() {return pCity;};
vector</*CvPlayer**/string> getCrusaders() {return aParticipants;};
static bool isPlayerTarget(/*CvPlayer**/int);
static void destroyCrusade(Crusade crusade);
};
Crusade::Crusade (/*CvCity**/int City, /*CvPlayer**/ int Target, vector</*CvPlayer**/string> Crusaders)
{
pCity = City;
pTarget = Target;
for (int x = 0; x< Crusaders.size(); x++)
{
aParticipants.push_back(Crusaders[x]);
}
//aParticipants = Crusaders;
lCrusades.push_back(this);
}
Crusade::~Crusade ()
{
cout << "Crusade destroyed!" << endl;
for (int x=0; x<aParticipants.size(); x++)
{
/*CvPlayer**/string pPlayer = aParticipants[x];
cout << pPlayer;
/*for (int y=0; x<pPlayer->getNumUnits(); y++)
{
CvUnit* pUnit = pPlayer->getUnit(y);
if(pUnit->isHasPromotion(pCrusader)
{
pUnit->setHasPromotion(pCrusader, false);
}
}*/
}
//send code to python to remove target graphics?
/*
call removeCrusaderTarget(pTarget), where this function is used by python to check for code in CvMainInterface.py, line 2804
TBC!
*/
for (int y=0; y<lCrusades.size(); y++)
{
if (lCrusades[y] == this)
{
lCrusades.erase(lCrusades.begin()+y-1);
}
}
aParticipants.clear();
}
void Crusade::destroyCrusade(Crusade crusade)
{
Crusade * pCrusade;
pCrusade = &crusade;
delete pCrusade;
}
int main() //this would obviously not be there in the real code!
{
vector<string> vCrusaders; vCrusaders.push_back("England"); vCrusaders.push_back("France");
Crusade Crusade1 (1, 1, vCrusaders);
vCrusaders.clear(); vCrusaders.push_back("Spain"); vCrusaders.push_back("Italy");
Crusade Crusade2 (2, 2, vCrusaders);
for (int i=0; i<lCrusades.size(); i++)
{
Crusade* pCrusade = lCrusades[i];
cout << pCrusade->getTarget() << endl << "i = " << i << endl;
for (int j=0; j<pCrusade->getCrusaders().size(); j++)
{
cout << pCrusade->getCrusaders()[j] << endl;
}
}
Crusade::destroyCrusade(Crusade1);
cout << "lCrusades.size() = " << lCrusades.size() << endl;
for (int i=0; i<lCrusades.size(); i++)
{
Crusade* pCrusade = lCrusades[i];
cout << pCrusade->getTarget() << endl;
for (int j=0; j<pCrusade->getCrusaders().size(); j++)
{
cout << pCrusade->getCrusaders()[j] << endl;
}
}
cin.get();
return 0;
}
/*
Crusade::isPlayerTarget(CvPlayer* pPlayer)
{
for(int x=0; x<lCrusades.size(); x++)
{
if (lCrusades[x]->getTarget() == pPlayer)
{
return true;
}
}
}
*/
(please excuse the messiness! couldn't use the actual types!)
Am I right in thinking that this should have deleted Crusade1 and therefore the lCrusades for loop sould only display Crusade2?
if you read through the code should should get an idea of whats meant to happen... the console gives me back this:
Code:
1
i = 0
England
France
2
i = 1
Spain
Italy
Crusade destroyed!
EnglandFranceCrusade destroyed!
lCrusades.size() = 2
1
England
France
2
Spain
Italy
so definatly not working correctly!
any ideas from C++ programmers that actually know what they are meant to be doing?