Done.
Code:if(irec->GetNumPrerequisiteBuilding() > 0) { for(o = 0; o < irec->GetNumPrerequisiteBuilding(); o++) { sint32 b = irec->GetPrerequisiteBuildingIndex(o); if(!(GetEffectiveBuildings() & ((uint64)1 << (uint64)b))) return FALSE; } }

Since Martin Helps me out a lot and there are a few things I'd like to do. AND instead of adding a bunch of threads for others to go through (since my struggle may help guide others) I'll just start one thread so Martin doesn't have to hop around. It could also serve as an addition to Martin's C++ Lecture.
As a heads up, this is a loose list I have of things I may attempt at coding (hoping I don't give Martin a heart attack!). The * means they are done (mostly) and I have notes following them.
They are in a loose priority list.
Code completed
*Increase Bombardment----see Peter Triggs rev 339
*Terrain-specific Cities ------ CanSettleOn
*Barbarian list? BarbarianOnly and SeaPirates- see tombom
NoBarbarian
*immobile ---- See Peter Triggs Rev 339
*Good-Specific Imps ------- IsRestrictedToGood
*CultureOnly --- Imps, buildings, wonders, units,
*CityStyleOnly----same
*GovtOnly----- added
*Building Prerequiste for Units and Wonders
*NeedsCityGood-in radius or if buying; Either good (iron or bronze etc) rev 465?
*NeedsCityGoodAll (needs all goods listed)
*Warning Box for declaring War &&
*Good attrbutes (using building flags for goods to increase food, science or crime)
*GoodFlags ----- CantTrade
*BuildGood tile imp----(PlantGood Slic))
*PillageGood tile imp----(RemoveGood
*NeedsCivGood
*NeedsCivGoodAll (any city must be collecting good)
*Hidden Nationality (probably used in same in code area)
*Settlers Can Join Cities -Rev540
* CantPillage - rev540
Civ specific traits - using wonders and buildings flags for goods to increase food, science or crime)
GoldHunger --UnitUpkeep--see building upkeep and Readiness
Building maintenance times population
PopulationCost for Units
UpgradeUnit ---EventAdvance? Flag?
blitz -----Clearbattleflag slic.cpp
CaptureTileImp when Pillaged (for forts and airbases?)
DeniedToEnemy - Improvement Flag that removes bonus for RR if owner != Unit owner in mvmt?
ExcludesUnit etc ---Switch PreRequisiteBuilding to exclude certain units and buildings to add Guns vs Butter choices.
VanishAdv & ExcludesAdvance & GovtOnly Advance
Kill City ----Event City Capture (Plunder, raze, give to, occupy), && creates Ruins with City Raze
CaptureTile --- Use Pillage code?
New Govt flags - Xenophobia (reduces pop), Feudal (cities
more independent?), Centralized, federal, Rebellions
(creates rebels), secessionist (chance of revolts)
Other?
Units SettleImprovement
Code In Works
ShowOnMap ---- CityData: BuildWonderEvent
-------------------Player::RemoveWonder
-------------------Can't Pillage & Remove Wonder & AI Pillage
can't group ----- --- cantgroup slic in wokers?
HasRoadConnection
-----------function that uses the pathing and sees if the movepoint value is equal to road value thereby says its all roads?
Religion Advance - only have unless switch (SLIC?)
CraterTerrain ---- autopillage and create "dead tile" craters
IsIrrigation ----- riverto build or adjacent to IsIrrigation
More Improvements - science, happy, regard,
minefields/damage, StopMove, Impassable,
BuildGood, NeedsWater for imps, built on river OR
adjacent is farm
rebase air units----- Use Paradrop?
Advances - NotTradeable, CantCaptureAdv, EnableGuerrillas
Mercenary/Lease - (Good/Fast/Cheap Idea)
Conscript/Cheap?
NeedGoodPoint?
Fuelpoints? -- make like PW? use readiness, maintenance etc
Last edited by Ekmek; July 6, 2006 at 15:41.

Done.
Code:if(irec->GetNumPrerequisiteBuilding() > 0) { for(o = 0; o < irec->GetNumPrerequisiteBuilding(); o++) { sint32 b = irec->GetPrerequisiteBuildingIndex(o); if(!(GetEffectiveBuildings() & ((uint64)1 << (uint64)b))) return FALSE; } }
Last edited by Ekmek; May 6, 2005 at 23:45.

Ok trying this NeedsCityGood
HasResource is a function I found in citydata and unit.cpp and unitdata.cpp (the unit files reference m_city_data)
I figure if I put the above code into the CanBuildUnit(building and wonder)
it should compare the two to see if a unit can build. This is assuming that HasResource means what it says, and it looks like that is the same function to find if a city has a resource to trade.
When I tried to compile I got this:Code:if(irec->GetNumNeedsCityGood() > 0) { sint32 s; sint32 resource; bool found = false; for(s = 0; s < irec->GetNumNeedsCityGood(); s++) { if(irec->GetNeedsCityGoodIndex(s) == HasResource(resource) { found = true; break; } } if(!found) return FALSE; }
(edit: I fixed some of my own C2227 errors)Code:F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4815) : error C2039: 'GetNumNeedsCityGood' : is not a member of 'UnitRecord' ..\gs\newdb\UnitRecord.h(351) : see declaration of 'UnitRecord' F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2039: 'GetNumNeedsCityGood' : is not a member of 'UnitRecord' ..\gs\newdb\UnitRecord.h(351) : see declaration of 'UnitRecord' F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4820) : error C2660: 'GetNeedsCityGoodIndex' : function does not take 1 parameters
I thought the error is because I didn't do anything in the cdb but I checked and I did put it in there before. Is there somewhere I can see the definition for a C2660 and C2039 error is?
I checked the UnitRecord.h and its automatically generated so I'm not to change it.
Finally, any tips on the does not take 1 parameters?
(I know I also have to finish the other settler code too)
Last edited by Ekmek; July 4, 2005 at 21:04.

If you've put it in the cdb file but it's not appeared in UnitRecord.h, then the IDE may have failed to regenerate UnitRecord.h. Try cleaning and then rebuilding.Originally posted by E
I checked the UnitRecord.h and its automatically generated so I'm not to change it.
Finally, any tips on the does not take 1 parameters?
Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?

That's a little bit to much for just recompiling the unit.cdb, the best is to open it and while the window of the file is active to use the option of compiling the file in the active window. Ctrl + F7 should do the job.Originally posted by J Bytheway
If you've put it in the cdb file but it's not appeared in UnitRecord.h, then the IDE may have failed to regenerate UnitRecord.h. Try cleaning and then rebuilding.
I guess it returns the database index of that good at i[i]th[/b] position in the NeedsCityGood array. Well and that's definatly something different than a BOOL that is returned by HasResource.Originally posted by J Bytheway
Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?
So E what does represent the parameter of HasResource?
Well that's the answer of a question you have to find on your own E.And it shouldn't be so difficuilt, since you already encountered a function that returns the needed input.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Thanks J and Martin. I'll try the recompile for the cdb and unitrecord stuff. THe HasResource uses M_collectingResources so I'm guessing that I'll have to put that there. I'll give it a shot and hunt around the code a bit more.

At first it is called m_collectingResources, C++ is a case sensitive language.Originally posted by E
THe HasResource uses M_collectingResources so I'm guessing that I'll have to put that there. I'll give it a shot and hunt around the code a bit more.Second what do you want to do with this here? And third so far you didn't answer my question: What is the parameter of HasResource? What do you have to pass to HasRessource? First answer this question and you will get on with your problem.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Based on the following code, the parameter is resource. Which based on the code looks like it stores the resource located near a city. So my code is an attempt to match the Units NeedsCityGood resource/good with that of the good/resource that a city is collectingin its radius.
I'll get back to that I think I'm on to something... As for the UnitRecord stuff I found this in UnitRecord.hCode://this city is collecting more sint32 resource than than it is selling BOOL CityData::HasResource(sint32 resource) const { return m_collectingResources[resource] > m_sellingResources[resource]; }
For some reason it was passing the NeedsCityGood without a Number which I think will make it hard to compare to the HasResource but I'll stil check. In the meantime I'll take the Num out.Code:sint32 GetNumCityStyleOnly() const { return m_numCityStyleOnly;} sint32 GetSettleImprovementIndex() const { return m_SettleImprovement; } const TerrainImprovementRecord *GetSettleImprovement() const; sint32 GetNeedsCityGoodIndex() const { return m_NeedsCityGood; } const ResourceRecord *GetNeedsCityGood() const;
Edit: I changed the code to this (probably wrong but I'm learning still):
so I solved the unitrecord.h problem and the parameters, but I see that the Num removed removes the comparison, I guess I have to change something in Unit.CDB so it knows that RecordResource is a numeric value? I'm going to compare other resource record stuff now. In the mean time the bottom two are new to me...Code:if(rec->GetNeedsCityGood() > 0) { sint32 r; bool found = false; for(r = 0; r < rec->GetNeedsCityGood(); r++) { if(rec->GetNeedsCityGoodIndex() == m_collectingResources) { found = true; break; } } if(!found) return FALSE; }
Code:F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4818) : error C2446: '<' : no conversion from 'const class ResourceRecord *' to 'long' This conversion requires a reinterpret_cast, a C-style cast or function-style cast F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4818) : error C2040: '<' : 'long' differs in levels of indirection from 'const class ResourceRecord *' F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'long' (or there is no acceptable conversion)
Last edited by Ekmek; July 5, 2005 at 18:25.

Not quite, take a look again: What does represent the parameter resource? That's crucial to find out how the code must.Originally posted by E
Based on the following code, the parameter is resource. Which based on the code looks like it stores the resource located near a city.
Code://this city is collecting more sint32 resource than than it is selling BOOL CityData::HasResource(sint32 resource) const { return m_collectingResources[resource] > m_sellingResources[resource]; }
What is the your design idea? Do you want to allow the modders only one good that is needed for an item, or do you want allow multiple item. I guess you made it so that the *.cdb file only allows one good as prerequisite.Originally posted by E
For some reason it was passing the NeedsCityGood without a Number which I think will make it hard to compare to the HasResource but I'll stil check. In the meantime I'll take the Num out.
And by the way it is hard to compare to the HasGood method anyway, if not to say impossible if you exspect to get something meaningfull.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Just to catch your edit E. The HasResource belongs into the if statement, but so far you haven't understood it.
-Martin
Civ2 military advisor: "No complaints, Sir!"

hmmm...it looked straight forward to me, I'll have to dig into my book perhaps terminology is getting to me. Unless I'm miss understanding goods as resources? or are you saying that m_collectingResources doesn't store a good like I thought it does?Originally posted by Martin Gühmann
Not quite, take a look again: What does represent the parameter resource? That's crucial to find out how the code must.
Yeah I just caught that...so I made it multiple...that was the Num problem I think.What is the your design idea? Do you want to allow the modders only one good that is needed for an item, or do you want allow multiple item. I guess you made it so that the *.cdb file only allows one good as prerequisite.
I gues I may have to create new functions then? But I thought the the game used this stuff so you knew what cities could trade stuff so thats stored somehow and then I though just matching similar to the way the receive or have a good to a value it ought to work. Where is my thinking messed up?And by the way it is hard to compare to the HasGood method anyway, if not to say impossible if you exspect to get something meaningfull.
-Martin
and I'm down tothis:
after I put has resource back and updated the unit.cdb with "[]"Code:F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2660: 'GetNeedsCityGoodIndex' : function does not take 0 parameters F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2065: 'resource' : undeclared identifier

Okay, my last guess whould to base it on HasAdvance and develop a code like:
Thats my last hunch, but I do guess what is throwing me off is that HasResource is a BOOL witha ">" instead of just a regular return.Code:if(rec->GetNumNeedsCityGood() > 0) { sint32 r; bool found = false; for(r = 0; r < rec->GetNumNeedsCityGood(); r++) { if(HasResource(rec->GetNeedsCityGoodIndex() >= 0) { found = true; break; { return FALSE; }

It just checks wheather the city is collecting more units of a certain kind of good than it is selling. Maybe you need to reconsider what you wan't to check.Originally posted by E
Thats my last hunch, but I do guess what is throwing me off is that HasResource is a BOOL witha ">" instead of just a regular return.
But currently I am more confused why you pass a bool or a BOOL to the HasResource function, even if it expects a sint32.
-Martin
Civ2 military advisor: "No complaints, Sir!"

I started redigging into citydata.cpp. I'm looking for some array that stores whether a city has a good or not and I found this:Originally posted by Martin Gühmann
It just checks wheather the city is collecting more units of a certain kind of good than it is selling. Maybe you need to reconsider what you wan't to check.![]()
so it adds it to m_collectingResource, but how do I get back to it. I think I need to create a function that GetsCityGood by looking into m_collectingResource. Am I right? I'm unclear on the use of "." any good examples (that I could recognize) on getting to the good stored with a city?Code:sint32 good; if(g_theWorld->GetGood(center_point, good)) { m_collectingResources.AddResource(good);
But currently I am more confused why you pass a bool or a BOOL to the HasResource function, even if it expects a sint32.
-Martin
I though since this is how we checked a citystyle a city may have it would be the same way to check a Unit NeedsCityGood versus the good a city has (if it does have one).
I've dug into the trade stuff to and I cant sem to find how they link a route to a city and to a specific good, is there a specific function that does this, its not readily apparent. my best guess is:
but I don't think i can access m_sourceResource in citydata.cppCode:void TradeRouteData::GetSourceResource(ROUTE_TYPE &type, sint32 &resource) const { type = m_sourceRouteType; resource = m_sourceResource; }
so my next bet is:
Code:CityData::GetResourceTradeRoute(sint32 resource, TradeRoute & route) const { sint32 i; for(i = 0; i < m_tradeSourceList.Num(); i++) { ROUTE_TYPE type; sint32 rr; m_tradeSourceList[i].GetSourceResource(type, rr); if(type != ROUTE_TYPE_RESOURCE) continue; if(rr != resource) continue; route = m_tradeSourceList[i]; return true; } return false; } bool CityData::IsSellingResourceTo(sint32 resource, Unit & destination) const { sint32 i; for(i = 0; i < m_tradeSourceList.Num(); i++) { ROUTE_TYPE type; sint32 rr; m_tradeSourceList[i].GetSourceResource(type, rr); if(type != ROUTE_TYPE_RESOURCE) continue; if(rr != resource) continue; destination.m_id = m_tradeSourceList[i].GetDestination().m_id; return true; } destination.m_id = 0; return false; }
So is m_tradeSourceList.Num() what I should be looking for? or maybe m_tradeSourceList[i].GetSourceResource(type, res)?
Last edited by Ekmek; July 7, 2005 at 15:47.

I don't think we checked the city style this. At first the ckity style check was free of syntax errors. Your compiler should tell you that there are at least a closing parenthesis and a closing brace missing.Originally posted by E
I though since this is how we checked a citystyle a city may have it would be the same way to check a Unit NeedsCityGood versus the good a city has (if it does have one).
And regardless how you parenthesise this line it's still wrong:
if(HasResource(rec->GetNeedsCityGoodIndex()) >= 0) {
if(HasResource(rec->GetNeedsCityGoodIndex() >= 0)) {
In the first place HasResource returns a BOOL. As it is just a typedef of a long the only values the methods return are 0 or 1. After the application of >= 0 you get in every case TRUE or in other words 1.
In the second case the result is wrong as well. Since all the indeces of goods in the database are >= 0 you get always a TRUE or 1 for the function as argument. That means the hasResource method doesn't check whether the city has the good in question given by your list, but always the good with the database index 1.
Now think again how should the code look if you use the condition by the HasResource function. And write down the result here in this thread.
Now take again a look on the HasResource function, espeacilly on the two objetct that are part of the unequality in the return statement. You want to know the information that they store. And take again a look on the CityData class, it should have methods to access these objects.
And if you are looking for arrays then you should take a close look on the Resource class, then you will see that it wraps an array and adds some basic functionality.
-Martin
Civ2 military advisor: "No complaints, Sir!"

I didn't see anything in the resources.h class but did find the HaveGoodOfType. I just updated my svn so I havent put this in a code, and if you check it out I'd appreciate. But after doing a playtest I think resources should go down on my priority and I made a big effort to try and code how upgrade mght work which I'll post next.Code:if(rec->GetNumNeedsCityGood() > 0) { sint32 s; bool found = false; //not needed? for(s = 0; s < rec->GetNumNeedsCityGood(); s++) { if(HasResource > 0) { rec->GetNeedsCityGood(s) == m_collectingResources->HaveGoodOfType() { //from CityData::CityRadiusFunc and SlicContext::HaveGoodOfType found = true; break; } } } if(!found) //not needed? return FALSE;

Okay I made my best atempt and I probably took on more than I should of, but I hope there is a consensus in the community that this should be a standard part of the game. Also I made it for unitdata, but it might go in armydata, not too sure but I didn't put it in city because maq would like to have units and tiles, etc that upgrade. but as it stands now i set up to do cities. I know I could just add and compile it myself but I hope I could get a look over to minimize any syntax errors or anything else before I get into the big stuff.
anyways (I hope it fits) here's what I tried:
Code://---------------------------------------------------------------------------- // // Name : UnitData::GetUpgradeCost // // Description: Checks whether if player has gold to upgrade a unit // // Parameters : // // Globals : g_player: The list of players // g_theUnitDB: The unit database // g_theGovernmentDB: The government database // // Returns : upgradegold; the amount of gold it will cost to upgrade // // Remark(s) : used to see if a player CanUpgrade and to subtract cost // //---------------------------------------------------------------------------- sint32 UnitData::GetUpgradeCost() //from sint32 CityData::GetOvertimeCost() { const GovernmentRecord *grec = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type); //can I use in a sint32? const UnitRecord *rec = g_theUnitDB->Get(type); Player * player = g_player[m_owner]; //from bool CityData::PayForBuyFront() sint32 oldunit = rec->GetShieldCost(); sint32 upgradeunit = rec->upgradeto()->rec->GetShieldCost(); sint32 upgradegold = upgradeunit - oldunit * grec->GetCapitalizationCoefficient(); if ((player->GetGold() < upgradegold)) //from CityData::PayForBuyFront rushbuy function { return false; } if(upgradegold < 0) upgradegold = 0; return upgradegold; } //---------------------------------------------------------------------------- // // Name : UnitData::CanUpgrade // // Description: Checks whether a player can upgrade a unit in a city // // Parameters : type: The unit type for that is checked whether the city can // build it. // // Globals : g_player: The list of players // g_theUnitDB: The unit database // g_theBuildingDB: The building database // g_theWorld: The world properties // // Returns : Whether the player can upgrade the unit specified by type. // // Remark(s) : attempted by E // //---------------------------------------------------------------------------- BOOL UnitData::CanUpgrade (const UnitRecord *rec, sint32 type, const MapPoint &pos) // not sure I need this stuff in parentheses { const UnitRecord *rec = g_theUnitDB->Get(type); const BuildingRecord* irec = g_theBuildingDB->Get(type); MapPoint pos; GetPos(pos); Cell *cell = g_theWorld->GetCell(pos); //Checks if unit position is a city if(!g_theWorld->GetCity(pos).IsValid()) return FALSE; //checks if player can build the unit they want to upgrade to Assert(m_city_data); //not sure what assert does but I guess it calls citydata from the city the unit is in if(rec->GetUpgradeTo() > 0) { sint32 i for(i = 0; i < rec->GetUpgradeTo(); i++) { if(rec->GetUpgradeTo(i) == m_city_data->CanBuildUnit() { if(m_city_data->GetEffectiveBuildings(irec->CanUpgradeUnits)>0) } } return FALSE } //HasGold Player * player = g_player[m_owner]; //from bool CityData::PayForBuyFront() sint32 const upgradegold = GetUpgradeCost(); if ((player->GetGold() < upgradegold)) { return FALSE; } return TRUE; } //---------------------------------------------------------------------------- // // Name : UnitData::PayForUpgrade // // Description: Subtracts upgrade cost from player gold // // Parameters : // // Globals : g_player: The list of players // g_theUnitDB: The unit database // // Returns : subtracts the amount of gold it will cost to upgrade // // Remark(s) : // //---------------------------------------------------------------------------- bool UnitData::PayForUpgrade() { Player * player = g_player[m_owner]; sint32 const upgradegold = GetUpgradeCost(); if ((player->GetGold() < upgradegold)) { return false; } player->SubGold(upgradegold); //from bool CityData::PayForBuyFront() //player->m_gold->AddLostToRushBuy(upgradegold); //not needed //m_paidForBuyFront = true; //not needed?? return true; } } // the following code is mostly incomplete (more so than the above) BOOL Player::UpgradeUnit(sint32 type) { const UnitRecord* rec = const UnitRecord *rec = g_theUnitDB->Get(m_array[i].GetType(), g_player[GetOwner()]->GetUpgradeTo(t) //fromPlyer::CreateUnit sint32 t if(!CanUpgradeUnit(type) { if(rec->upgradeto() > 0 ) {g_player[m_owner]->CreateUnit(const sint32 t, const MapPoint &pos, const Unit hc, BOOL tempUnit, CAUSE_NEW_ARMY cause) { return FALSE; if(g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { //I guess this is multiplayer? g_network.SendAction(new NetAction(NET_ACTION_BUILD, type, m_home_city)); } else if(g_network.IsHost()) { g_network.Block(m_owner); g_network.Enqueue(new NetInfo(NET_INFO_CODE_BUILDING_UNIT, type, (uint32)m_home_city)); g_network.Unblock(m_owner); } ArmyData::Disband() //I still need to figure how to remove the old unit but don't add shields... { PayForUpgrade(); return FALSE; } } // CityWindow this still needsto be coded // this still needs to be coded for unit control anel // how AI handles it. I think BeginTurnEven->UpgradeAll AI Units for free will keep them competive or maybe just take as much gold as it can?

I disagree. This resource thing is easier than the update thing.Originally posted by E
But after doing a playtest I think resources should go down on my priority and I made a big effort to try and code how upgrade mght work which I'll post next.
Again some question that you have now to answer before you code anything or before I review anything:
What does the CityData::HasResource method do?
What type of is its parameter.
What does represent this parameter? What does it mean?
What does it return?
What is the meaning of its return value?
What does the ResourceRecord::GetNeedsCityGood method do?
What type of is its parameter.
What does represent this parameter? What does it mean?
What does it return?
What is the meaning of its return value?
And what is your code supposed to do?
Answer all these questions and then you should be able to use these functions.
(I am sorry E. But I think I must now do the hard way otherwise you won't move a milimeter.)
You shouldn't mess around with this class.Originally posted by E
I didn't see anything in the resources.h class but did find the HaveGoodOfType.
Who cares about whether you update your working copy or not, actual TortoiseSVN can merge your code into the latest revision without any problems and if not you can merge the files manually. You are asked whether this piece of code should be taken from your copy or from their copy.Originally posted by E
I just updated my svn so I havent put this in a code, and if you check it out I'd appreciate.
E you have a compiler to fix all the missing braces, brackets and parentheses. So that's not my task.Originally posted by E
I know I could just add and compile it myself but I hope I could get a look over to minimize any syntax errors or anything else before I get into the big stuff.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Thanks Martin I know most of the answers to the questions and I've basically gone to the breakit and try to fix it method to quoting, on my 6+ attempt to compile the NeedsCityGood code.Originally posted by Martin Gühmann
I disagree. This resource thing is easier than the update thing.
Again some question that you have now to answer before you code anything or before I review anything:
What does the CityData::HasResource method do?
What type of is its parameter.
What does represent this parameter? What does it mean?
What does it return?
What is the meaning of its return value?
What does the ResourceRecord::GetNeedsCityGood method do?
What type of is its parameter.
What does represent this parameter? What does it mean?
What does it return?
What is the meaning of its return value?
And what is your code supposed to do?
Answer all these questions and then you should be able to use these functions.
The compiler kicks it back, i dig into the code for another way to answer, etc etc. the thing I keep bumping into is that most of citydata just looks for a good COUNT, like the HasResource function does.
BUt thanks for the help, the compiler helps out alot though.
I've tried a few things and most recent was this:
but I got this when compilingCode:// Added by E - Compares Unit NeedsGood to the City's resource if(rec->GetNumNeedsCityGood() > 0) { sint32 s; sint32 good; bool found = false; //not needed? for(s = 0; s < rec->GetNumNeedsCityGood(); s++) { if(rec->GetNeedsCityGoodIndex(s) == GetGoodCountInRadius(good)) { found = true; break; } } if(!found) return FALSE; }
And know it has something to with:Code:F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4839) : error C2662: 'GetGoodCountInRadius' : cannot convert 'this' pointer from 'const class CityData' to 'class CityData &' Conversion loses qualifiers
where the GetGoodCountInRadius returns a count, the same problem with HasResource.Code:sint32 CityData::GetGoodCountInRadius(sint32 good) { m_cityRadiusOp = RADIUS_OP_COUNT_GOODS; m_tempGood = good; m_tempGoodCount = 0; MapPoint pos; m_home_city.GetPos(pos); CityRadiusIterator(pos, this); return m_tempGoodCount; } void CityData::AddGoods(SlicObject *obj) { m_tempGoodAdder = obj; m_cityRadiusOp = RADIUS_OP_ADD_GOODS; MapPoint pos; m_home_city.GetPos(pos); CityRadiusIterator(pos, this); }
Early I tried inserting a cityradius iterator to find goods then compare etc but that ended up causing a lot of problems. Since I cant get around the counting of goods thing, my next two approaches are to:
a) try the city iterator approach again
b) creeate a new function that just returns thegood and then call it to compare against
if you are online stop me if you got a better suggestion...
Last edited by Ekmek; July 30, 2005 at 23:50.

The problem is that you don't know all the answers. And the other possible problem might be that you don't know the correct answers. Unfortunately I cannot check whether the answers you know are correct as long as you don't post them. So to write it out explicitly: Post the answers to the questions, so that I can correct you if you're wrong.Originally posted by E
Thanks Martin I know most of the answers to the questionsOtherwise you'll never reach the finish line. Questioning your asumptions is a good debug strategy by the way.
That's something you have always to do as a programmer.
Apart from that the HasResource method should point you into the right direction. That's why I ask the questions what should your code do and what does the HasResource method do.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Well the radius stuff has been working. the 'this' pinter is matching with class CityData. Ive tried a few other things with the iterator and its just not going. The closest I got was where it just said 'good' is not identified.
I'm leaning towarda function that does the iterator and then having an array that stores the good and then compare the good.
am I on the right path? Is there sme other functions I should be looking at that might call what I need?

1) What does the CityData::HasResource method do?
The HasResource only returns a positive value if the city is collecting. It does not identify the resource from what I assume.
2)What type of is its parameter.
its a sint32
3)What does represent this parameter? What does it mean?
Its parameter is 'resource', which is the value of colecting resources. I don't think its stating the resource name only the quantity
4)What does it return?
By looking at the function it returns if the city is collecting more resources than it is selling
5)What is the meaning of its return value?
the return value appears to say that the city is collecting more than its selling
6)What does the ResourceRecord::GetNeedsCityGood method do?
I don't think ResourceRecord::GetNeedsCityGood exists (didnt see it in a search though it would be nice). But I'm assumingyou mean CityData:GetNeedsCityGood. It compares the good listed in the Unit.txt NeedsCityGood to the good that is located in a City'sradius, atleast thats what I want it to do.
7)What type of is its parameter.
Its a sint32. but NeedsCitygOod is in ::CanBuildUnit where it also has a sint32 'type'
8)What does represent this parameter? What does it mean?
the sint32 in NeedsCityGood is to represent the value of the good listed in the unit.txt. ::CanBUildUnit's sint32 type is for the type of unit.
9)What does it return?
The parameter should return the good name.
What is the meaning of its return value?
10) And what is your code supposed to do?
The code should be a bool if the unit can be built or not if the city has a good in its radius (or is receiving it from trade ideally) and if that good matches the one listedin the unit.txt

Well I see why you don't make progress. Question 2 is correct. I can except answer 7 but of course you have to use your compiler to regenerate ResourceRecord.h and ResourceRecord.cpp so that it contains these functions. So your answer is only a guess but a correct one. Answer 5 is correct, answer 4 is the same is answer 5 but I was rather behind the return type of the function.
Fortunately you figured out that it should be GetNeedsCityGoodIndex instead of GetNeedsCityGood, so answer the questions 6 to 10 for this method again.
And don't confuse question 11 and 10 again, you forgot to answer question 10 and renamed question 11 to 10.
But anyway, answer 11 is correct. Of course you should know what you are trying to do. And that is the only question that allows some alternative answers, depending on what you want to do.
But these other questions need a better answer and as I want to make you to use your brain I ask you some more questions:
What is the consequence of answer 11 to the HasResource method. Can you use it?
What is a resource database index?
What does represent it?
How do you use it?
And of course rethink the answers to the other questions. And of course post these answers.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Well E, I am sorry you are right about the existence of the ResourceRecord::GetNeedsCityGood method it doesn't exist and it won't exist. The correct method should be UnitRecord::GetNeedsCityGoodIndex. But You can't expect that I still know every little detail after quite a month.Originally posted by E
6)What does the ResourceRecord::GetNeedsCityGood method do?
I don't think ResourceRecord::GetNeedsCityGood exists (didnt see it in a search though it would be nice). But I'm assumingyou mean CityData:GetNeedsCityGood.Therefore I expect your answers within this day.
Just to make sure that we will arrive the finish line.
This task isn't so difficuilt.
-Martin
Civ2 military advisor: "No complaints, Sir!"

I looked for the NeedsCityGoodIndex, but it still shows the UnitRecord as an array and not index so I guess I have to change the cdb.
I'm still digging through how the good index is called but I'll get the answers as soon as I can

I see you decided just to allow the unit to require one single good. Well that changes of course the code. However is it what you want to make modders to pick one good and not all good of a certain lists or not one good from a certain list.Originally posted by E
I looked for the NeedsCityGoodIndex, but it still shows the UnitRecord as an array and not index so I guess I have to change the cdb.
I'm still digging through how the good index is called but I'll get the answers as soon as I can
-Martin
Civ2 military advisor: "No complaints, Sir!"

Well E, since I came to the conclusion that you need some pressure, here is my question:
Were are the answers.
Well to give you a little you should open the goods.txt and read the comments to each good, to get an idea what could be a resource database index. Well Actual I wanted to tell you to consider common sense of index, but unfortunately there are so many different common snses of it, that I would tell you the solution if I would try to give you the hint to select the correct one.
-Martin
Civ2 military advisor: "No complaints, Sir!"

Originally posted by Martin Gühmann
Well E, since I came to the conclusion that you need some pressure, here is my question:
Were are the answers.
Well to give you a little you should open the goods.txt and read the comments to each good, to get an idea what could be a resource database index. Well Actual I wanted to tell you to consider common sense of index, but unfortunately there are so many different common snses of it, that I would tell you the solution if I would try to give you the hint to select the correct one.
-Martin
thanks Martin. I didnt need the pressuire thoughI was trying to do some research in my C++ book to give you good/better answers. The hard part is that I see resource is a sint32 and I was searching for a sint32 but I seem not able to call the good from the array, atleast from what I see. I did go through the ResourceRecord and UnitRecord. But notice that the index doesn't call the name/type of good, even though I called in my RestrictedToGood code.
The other thing is that the iterator has a "this" pointer that wouldnt match up to what I was calling. It is used to get a good in a radius but its not the same "this" thats called in the CanBuildUnit code. So I had problems knowing how to call the right one. So I'll dig a bit than give you something later tonight.

Ok in digging to try to get good answers for you I figured that I should research betterhow the code already uses HasResource. Looking at I *think* that where as my oriiginal assumption was that hasresource simply returned if you are colecxting a resource, i *think* now that the HasREsource function checks if a city has a good. So it passes a good or "g" and returns true or false if the city has the resource in its radius or from trade.
so I think I have to incorporate code similar to that in governor.cpp and trademanager.cpp
but I don't think its as simple as checking the unitrec after "&&" in order to build. So I'm looking more into your answers, but I hope I'm making progressCode:for(g = 0; g < g_theResourceDB->NumRecords(); g++) { if(city.CD()->IsLocalResource(g)) { if(city.CD()->HasResource(g) == FALSE && city.CD()->GetResourceTradeRoute(g, curDestRoute))

Well you are getting closer to the answer about what is a resource database index. Actual you already told me its function. But of course I want it a little bit more precisely. In your example you have seen that the g is passed to the HasResource function. And you have seen that this g represents a certain type of good.
So g represents a good but of what type is this g? It shouldn't be a problem to guess if you know what type the argument of HasResource is of.
-Martin
Civ2 military advisor: "No complaints, Sir!"
Bookmarks