 |
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
|
|  |
 |
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
|
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
|
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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?
|
|
|  |
 |
|  |
 |
|
E
|
 |
July 24,2005 Ctp2 Tiles in sig!
May 1999 time: 21:18
|
|
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
|
|
|  |
 |
|  |
 |
|  |
All times are GMT. The time now is 05:18. Apolyton Time is 00:18. |
top of page
|
|
|
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
|
|
|
|
|
|