Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Call To Power II > CtP2-Source Code Project > E's Source Code attempts
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
CivGroups
CTP2 Source Code Project (59): Not a Member - Join

bottom of page
  
Author
Thread   
Pages (3): [ 1   2   3   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 29-04-2005 09:08 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
E's Source Code attempts Support Apolyton, buy GURPS/ Alpha Centauri

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
quote:

*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 and if buying



Code In Works
quote:

NeedsGoodInCityRadius
Warning Box for declaring War &&
Hidden Nationality (probably used in same in code area)
---diplomacy log
--------see Player::RegisterAttack(PLAYER_INDEX against)
-------Player::ThisMeansWAR
--------unitflag display player color [0]
------void UnitActor::GetIDAndType
-------Scroll-bar for action buttons, allow for slic buttons

GoldHunger --UnitUpkeep--see building upkeep and Readiness

UpgradeUnit ---EventAdvance? Flag?

ShowOnMap ---- CityData: BuildWonderEvent
-------------------Player::RemoveWonder
-------------------Can't Pillage & Remove Wonder & AI Pillage

blitz -----Clearbattleflag slic.cpp
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?
CantPillage
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

Religion Advance - only have unless switch (SLIC?)

Kill City ----Event City Capture (Plunder, raze, give to, occupy), && creates Ruins with City Raze

GoodFlags ----- CantTrade, DiploTrade, AppearAdv,
NeedGoodToBuild, NeedCivGood, NeedTradedGood?
--------------- get iterator from show on map?
IncreaseScience, Crimet etc when buying, CanbePillaged
BuildGood tile imp----(PlantGood Slic))
PillageGood tile imp----(RemoveGood)


CraterTerrain ---- autopillage and create "dead tile" craters

Units SettleImprovement

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
CaptureTile --- Use Pillage code?

rebase air units----- Use Paradrop?

Advances - NotTradeable, CantCaptureAdv, EnableGuerrillas

New Govt flags - Xenophobia (reduces pop), Feudal (cities
more independent?), Centralized, federal, Rebellions
(creates rebels), secessionist (chance of revolts)
Other?

Mercenary/Lease - (Good/Fast/Cheap Idea)
Conscript/Cheap?

NeedGoodPoint?
Fuelpoints? -- make like PW? use readiness, maintenance etc

Last edited by E on 28-08-2005 at 05:19

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 29-04-2005 09:09 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

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 E on 07-05-2005 at 08:45

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 05-07-2005 05:52 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Browse Apolyton AD-FREE

Ok trying this NeedsCityGood
quote:

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.



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; }


When I tried to compile I got this:


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


(edit: I fixed some of my own C2227 errors)

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 E on 05-07-2005 at 06:04

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:18
  Old Post 05-07-2005 15:37 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Inflate your Upload Space

quote:
Originally posted by E
I checked the UnitRecord.h and its automatically generated so I'm not to change it.


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.

quote:
Finally, any tips on the does not take 1 parameters?


Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 06-07-2005 01:08 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Lose 30 kilos (of popups)

quote:
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.


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.

quote:
Originally posted by J Bytheway
Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?


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.

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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 06-07-2005 01:22 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Enter the AD-FREE zone

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.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 06-07-2005 01:42 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Support Apolyton, buy Alpha Centauri

quote:
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.


At first it is called m_collectingResources, C++ is a case sensitive language. 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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 06-07-2005 03:13 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Avatar Enlargement: We've got the solution

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.

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]; }


I'll get back to that I think I'm on to something... As for the UnitRecord stuff I found this in UnitRecord.h
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;


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.

Edit: I changed the code to this (probably wrong but I'm learning still):
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; }


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:
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 E on 06-07-2005 at 03:25

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 06-07-2005 03:27 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

quote:
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]; }


Not quite, take a look again: What does represent the parameter resource? That's crucial to find out how the code must.

quote:
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.


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.

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

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 06-07-2005 03:31 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Avatar Enlargement: We've got the solution

Just to catch your edit E. The HasResource belongs into the if statement, but so far you haven't understood it.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 06-07-2005 03:37 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Increase Your PM Length

quote:
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.


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?


quote:

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.


Yeah I just caught that...so I made it multiple...that was the Num problem I think.

quote:

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


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 I'm down tothis:

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


after I put has resource back and updated the unit.cdb with "[]"

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 06-07-2005 04:19 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Tired of ads?

Okay, my last guess whould to base it on HasAdvance and develop a code like:

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; }


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.

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 06-07-2005 20:43 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Support Apolyton, buy Call to Power 2

quote:
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.


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.

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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 08-07-2005 00:30 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Avatar Enlargement: We've got the solution

quote:
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.


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:

code:
sint32 good; if(g_theWorld->GetGood(center_point, good)) { m_collectingResources.AddResource(good);


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?


quote:

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:
code:
void TradeRouteData::GetSourceResource(ROUTE_TYPE &type, sint32 &resource) const { type = m_sourceRouteType; resource = m_sourceResource; }


but I don't think i can access m_sourceResource in citydata.cpp

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 E on 08-07-2005 at 00:47

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 08-07-2005 16:30 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations

quote:
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).


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.

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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 30-07-2005 21:54 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Get a bigger avatar today!

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;


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.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 30-07-2005 22:00 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
UPGRADE UNITS Full PM-box? Change here!

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:isband() //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?

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 31-07-2005 02:56 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Browse Apolyton AD-FREE

quote:
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.


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.

(I am sorry E. But I think I must now do the hard way otherwise you won't move a milimeter. )

quote:
Originally posted by E
I didn't see anything in the resources.h class but did find the HaveGoodOfType.


You shouldn't mess around with this class.

quote:
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.


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.

quote:
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.


E you have a compiler to fix all the missing braces, brackets and parentheses. So that's not my task.

-Martin

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 31-07-2005 08:43 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton, buy Call to Power 2

quote:
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.


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.

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:

code:
// 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; }


but I got this when compiling
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


And know it has something to with:
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); }

where the GetGoodCountInRadius returns a count, the same problem with HasResource.

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 E on 31-07-2005 at 08:50

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 31-07-2005 21:36 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Support Apolyton buy from Amazon

quote:
Originally posted by E
Thanks Martin I know most of the answers to the questions


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. Otherwise 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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 31-07-2005 21:37 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Avatar Enlargement: We've got the solution

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?

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 31-07-2005 21:46 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Lose 30 kilos (of popups)

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

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 31-07-2005 22:18 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Lose 30 kilos (of popups)

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

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 01-08-2005 21:50 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#24 Report this post to a moderator
Get a bigger avatar today!

quote:
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.


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. 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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 02-08-2005 00:55 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#25 Report this post to a moderator
Tired of ads?

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 Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 02-08-2005 01:05 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#26 Report this post to a moderator
Support Apolyton or Terrorists Win

quote:
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


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.

-Martin

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 03-08-2005 02:07 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#27 Report this post to a moderator
Full PM-box? Change here!

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

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 03-08-2005 03:09 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#28 Report this post to a moderator
Browse Apolyton AD-FREE

quote:
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 though I 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.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:18
  Old Post 03-08-2005 09:29 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#29 Report this post to a moderator
Increase Your PM Length

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

code:
for(g = 0; g < g_theResourceDB->NumRecords(); g++) { if(city.CD()->IsLocalResource(g)) { if(city.CD()->HasResource(g) == FALSE && city.CD()->GetResourceTradeRoute(g, curDestRoute))


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 progress

Martin Gühmann is offline Martin Gühmann
Emperor
Berlin, Germany
Mar 2001
time: 06:18
Post  Old Post 03-08-2005 19:25 Visit Martin Gühmann's homepage!
Edit/Delete Message Reply w/Quote
#30 Report this post to a moderator
Get a bigger avatar today!

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

 
Pages (3): [ 1   2   3   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:18.
Apolyton Time is 00:18.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0838 seconds (93.18% PHP - 6.82% MySQL) with 36 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net