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 > Increasing Bombardment Range
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 (4): [ 1   2   3   4   ]
< 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:22
  Old Post 01-10-2004 04:17 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Increasing Bombardment Range Support Apolyton, buy Call to Power 2

I found this in: ctp2_code\gs\gameobj\unitdata.cpp

code:
sint32 UnitData::CanBombard(CellUnitList &defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); double r = rec->GetBombardRange() + 0.5; double rsq = r * r; MapPoint dpos; defender.GetPos(dpos); if(GetDistance(dpos, m_pos, (sint32)r) > rsq) return FALSE; if (rec->GetCanBombardLand()) if (defender.IsAtLeastOneMoveLand()) return TRUE; if (rec->GetCanBombardWater()) if (defender.IsAtLeastOneMoveWater() || defender.IsAtLeastOneMoveShallowWater()) return TRUE; if (rec->GetCanBombardAir()) if (defender.IsAtLeastOneMoveAir()) return TRUE; if (rec->GetCanBombardSpace()) if (defender.IsAtLeastOneMoveSpace()) return TRUE; if (rec->GetCanBombardMountain()) if (defender.IsAtLeastOneMoveMountain()) return TRUE; return FALSE; } sint32 UnitData::CanCounterBombard(CellUnitList &defender) const { if (g_theUnitDB->Get(m_type)->GetCanCounterBombard()) { return CanBombard(defender); } else { return FALSE; } } sint32 UnitData::CanActivelyDefend(CellUnitList &attacker) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); if(rec->GetActiveDefenseRange() <= 0) return 0; BOOL movesMatch = FALSE; if(attacker.IsAtLeastOneMoveLand() && rec->GetDefendLand()) movesMatch = 0; if(attacker.IsAtLeastOneMoveWater() && rec->GetDefendWater()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveAir() && rec->GetDefendAir()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveSpace() && rec->GetDefendSpace()) movesMatch = TRUE; if(attacker.IsAtLeastOneMoveMountain() && rec->GetDefendMountain()) movesMatch = TRUE; if(movesMatch) { if(rec->GetActiveDefenseOnlyWhenCarryingEnablers()) { sint32 numEnablers = 0; sint32 i; for(i = 0; i < m_cargo_list->Num(); i++) { if(m_cargo_list->Access(i).GetDBRec()->GetEnableCarrierDefenses()) numEnablers++; } return numEnablers; } return 1; } return 0; } double UnitData::GetAttack(const UnitRecord *rec, const Unit defender) const { MapPoint dpos; double attack, baseattack; const UnitRecord *defrec = defender.GetDBRec(); defender.GetPos(dpos); attack = baseattack = rec->GetAttack(); if(!(rec->GetCanAttack() & defender.GetDBRec()->GetMovementType())) { return 0; } if(defrec->GetWoodenShip()) { attack += baseattack * rec->GetAttackWoodenShipBonus(); } if(g_theWorld->GetCell(dpos)->GetCity().m_id != (0)) { attack += baseattack * rec->GetAttackCityBonus(); } if(defrec->GetIsSubmarine()) { attack += baseattack * rec->GetAttackBonusSubmarine(); } return attack; } void UnitData::Bombard(const UnitRecord *rec, Unit defender, BOOL isCounterBombardment) { double prob; sint32 f = (sint32)(rec->GetFirepower() / g_theUnitDB->Get(defender.GetType())->GetArmor()); sint32 n; bool canBombard = rec->GetBombRounds(n); Assert(canBombard); if(!canBombard) n = 0; double hp = defender.GetHP(); sint32 p; sint32 i; g_slicEngine->RunCounterBombardmentTriggers(defender, Unit(m_id)); double defenseStrength = defender.GetDefense(Unit(m_id)); double attack = rec->GetZBRangeAttack(); prob = attack / (attack + defenseStrength); p = sint32(prob * 100); double dmr = 1.0/defender.GetHPModifier(); if (IsVeteran()) p += sint32(double(p) * g_theConstDB->GetVetCoef()); for (i=0; iNext(100) < p) { hp -= f * dmr; } } defender.SetHP(hp); if(isCounterBombardment) { g_slicEngine->RunCounterBombardmentTriggers(Unit(m_id), defender); } else { g_slicEngine->RunBombardmentTriggers(Unit(m_id), defender); } } void UnitData::BombardOneRound(const UnitRecord *rec, Unit &defender, double dbonus, double dmr) { sint32 p = rec->GetProbOfBombHit(); sint32 f = rec->GetZBRangeAttack(); double hp = defender.GetHP(); if (IsVeteran()) p += sint32(double(p) * g_theConstDB->GetVetCoef()); p = int (p *(1.0 + dbonus)); if (g_rand->Next(100) < p) { hp -= f * dmr; } defender.SetHP(hp); } BOOL UnitData::CanBombardType(const Unit & defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); if (rec->GetCanBombardLand() || rec->GetDefendLand()) { if (defender.GetMovementTypeLand()) { return TRUE; } } if (rec->GetCanBombardWater() || rec->GetDefendWater()) { if (defender.GetMovementTypeSea() || defender.GetMovementTypeShallowWater()) { return TRUE; } } if (rec->GetCanBombardAir() || rec->GetDefendAir()) { if (defender.GetMovementTypeAir()) { return TRUE; } } if (rec->GetCanBombardSpace() || rec->GetDefendSpace()) { if (defender.GetMovementTypeSpace()){ return TRUE; } } if (rec->GetCanBombardMountain() || rec->GetDefendMountain()) { if (defender.GetMovementTypeMountain()) { return TRUE; } } return FALSE; } BOOL UnitData::Bombard(CellUnitList &defender, BOOL isCounterBombardment) { const UnitRecord *rec = g_theUnitDB->Get(m_type); sint32 i, j, r; Assert(0 < defender.Num()); r = g_rand->Next(defender.Num()); for (i=r, j=0; j < defender.Num(); i = ((i + 1) % defender.Num()), j++) { if(!(defender[i].GetVisibility() & (1 << m_owner)) && !g_theWorld->GetCity(defender[i].RetPos()).IsValid()) continue; if (CanBombardType(defender[i]) || rec->GetSingleUse()) { Bombard(rec, defender[i], isCounterBombardment); return TRUE; } } return FALSE; }




I'm not a coder but I'm trying to learn, but I cant see where in this code that it only makes bombardment one-square away. Can anyone see where it says that or what the problem is?

Last edited by E on 02-10-2004 at 02:24

Peter Triggs is offline Peter Triggs
Prince
Gone Fishin, Canada
Jan 2000
time: 05:22
  Old Post 01-10-2004 05:26
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Support Apolyton

I think this is it:

code:
ORDER_RESULT ArmyData::Bombard(const MapPoint &orderPoint) { MapPoint point = orderPoint; static CellUnitList defender; defender.Clear(); g_theWorld->GetArmy(point, defender); sint32 i; BOOL isSpaceBombard = FALSE; if(point == m_pos) { return ORDER_RESULT_ILLEGAL; } else { if(!point.IsNextTo(m_pos)) { return ORDER_RESULT_ILLEGAL; } }


When they moved from Civ:CTP to CTP2 they put in a "fire and forget" feature which lets you select a
target and let your army move towards it on its own in order to carry out it's given order. If you want to
re-instate bombarding from a distance you'll have to keep an eye on this.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 01-10-2004 18:28 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Tired of ads?

If you remove that line which checks if the point is adjacent, it still won't help much. You can remove that and add ranged bombard. However, then a unit ordered to do ranged bombardment will still want to move adjacent to its target and attack then, which is why its also neccessary to eliminate that feauture to reinstate ranged bombardment.

Flinx is offline Flinx
Prince
Toronto, ON CANADA
Nov 2001
time: 00:22
  Old Post 01-10-2004 22:22 Visit Flinx's homepage!
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy GURPS/ Alpha Centauri

I was looking in Units.txt and Orders.txt last night and there is a flag which looks like it limits the range of actions. The values are all set to 0 or 1 e.g. reform city is 0 and bombard is 1 so this might be where the limit comes from.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 01:14 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

quote:
Originally posted by Peter Triggs
I think this is it:

code:
ORDER_RESULT ArmyData::Bombard(const MapPoint &orderPoint) { MapPoint point = orderPoint; static CellUnitList defender; defender.Clear(); g_theWorld->GetArmy(point, defender); sint32 i; BOOL isSpaceBombard = FALSE; if(point == m_pos) { return ORDER_RESULT_ILLEGAL; } else { if(!point.IsNextTo(m_pos)) { return ORDER_RESULT_ILLEGAL; } }


When they moved from Civ:CTP to CTP2 they put in a "fire and forget" feature which lets you select a
target and let your army move towards it on its own in order to carry out it's given order. If you want to
re-instate bombarding from a distance you'll have to keep an eye on this.


Ok this is where my skills are obviously weak. I'm thinking I need to make the defender's point less than or equal to bombard range value from attacker's point in order to return a true statement and if point is greater tha bombard range than it should return false.

but i don't see code that identifies where the attacker is. Where did this code come from? And I don't see where the code links to bombard effects, firepower (?) and chance of success.


But which file is this in? I'm thinking I can get the data from the nuke and target order to see how to put bombard range in.

Last edited by E on 02-10-2004 at 02:14

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 02:10 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Help yourself to an AD-FREE life

quote:
Originally posted by E
Ok this is where my skills are obviously weak. I'm thinking I need to make the defender's point less than or equal to bombard range value from attacker's point in order to return a true statement and if point is greater tha bombard range than it should return false.

but i don't see code that identifies where the attacker is. Where did this code come from? And I don't see where the code links to bombard effects, firepower (?) and chance of success.

But which file is this in? I'm thinking I can get the data from the nuke and target order to see how to put bombard range in.


I'll try to walk you through it.

First thing to note is that you should use [code][/code] tags to surround code to preserve the indenting when you post it here at 'Poly.

code:
ORDER_RESULT ArmyData::Bombard(const MapPoint &orderPoint)


This first line says that this code is defining a Bombard method for the class ArmyData. Thus, you can find this code in ArmyData.cpp (that, together with ArmyData.h define the ArmyData class). Each instance of this class represents data about a single army, and also carries these methods to perform actions related to the army (like bombarding),

This function takes just one argument, orderPoint, which is of type MapPoint. This represents the position on the map being bombarded.

code:
{ MapPoint point = orderPoint;

The code immediately defines a local variable called point and copies the position being bombarded into it.
code:
static CellUnitList defender; defender.Clear(); g_theWorld->GetArmy(point, defender);

Now the code fetches any army which might exist at this location.
code:
sint32 i; BOOL isSpaceBombard = FALSE;

the isSpaceBombard variable is probably a leftover from CTP space bombers.
code:
if(point == m_pos) { return ORDER_RESULT_ILLEGAL;

The first check here tests whether the army is trying to bombard itself - the variable m_pos is a member variable of the ArmyData class which stores the location of this army, you can see it defined in ArmyData.h. If the location of this army is the same as the location being bombarded, then give up and say the order is illegal.
code:
} else { if(!point.IsNextTo(m_pos)) { return ORDER_RESULT_ILLEGAL; } }

Otherwise, this next check uses the IsNextTo method of MapPoint to test whether the point being bombarded is next to the position of this army. If it isn't, the order is declared illegal.

And so forth...

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 02:15 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Lose 30 kilos (of popups)

Interestingly, the code you have pasted from unitdata.cpp does appear to allow for longer ranged bombarding...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 02:17 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

code:
sint32 UnitData::CanBombard(CellUnitList &defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); double r = rec->GetBombardRange() + 0.5; double rsq = r * r; MapPoint dpos; defender.GetPos(dpos); if(GetDistance(dpos, m_pos, (sint32)r) > rsq) return FALSE; if (rec->GetCanBombardLand()) if (defender.IsAtLeastOneMoveLand()) return TRUE;


I see that (defender.IsAtLeastOneMoveLand())

also restricts it to one movement of land. I'm thinking I should change this to GetbombardRnage in order to have a value. Or I probably need to edit this function to something like "IsWithinRange" anybody see where GetBombardRange is?

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

Thanks J,

I guess my next post crossed with yours. And I think you saw the same thingI did where it appears to do long range bombard.

Again, THank you very much for your walkthrough, it helped more than the C book I'm flipping through

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 02:22 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Remove this text

Can't remember when I saw that previously, but even the bombardrange unit flag was checked for in the code. It's the IsNextTo function call that overrides ranged bombard orders, IIRC.

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

Solver,

I think you might have ran into it during your (aborted) aircombat code...


off to find "IsNextTo"

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 02:31 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

Yes, that it was probably. I was researching the possibility of ranged bombardment assignment, and did notice that the bombardment code is pretty much screwed up. It seemed stupid how it does check for bombard range, yet orders are illegal for bombardment of non-adjacent targets.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 02:32 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Enter the AD-FREE zone

Hmm, do we have the source code online somewhere on a CVS? I currently have no access to the source, so I can't verify my memories...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 02:39 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Support Apolyton, pre-order Civilization IV

from \ctp2_code\gs\world\mappoint.cpp

code:
BOOL MapPoint::IsNextTo(const MapPoint &neighbor) const { static MapPoint tmp; if(GetNeighborPosition(NORTH,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(NORTHWEST,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(NORTHEAST,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(SOUTH,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(SOUTHWEST,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(SOUTHEAST,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(WEST,tmp)) if (neighbor == tmp) return TRUE; if(GetNeighborPosition(EAST,tmp)) if (neighbor == tmp) return TRUE; return FALSE; } struct ScreenPoint { ScreenPoint(const MapPoint &mp) { x = 2 * mp.x + mp.y; y = mp.y; if (x >= 2 * g_mp_size.x) x -= 2 * g_mp_size.x; } sint32 x, y; }; static sint32 WrapDelta(sint32 delta, sint32 size) { if (delta > 0) { if (2*delta > size) delta -= size; } else { if (-2*delta > size) delta += size; } return delta; }



I'm thinking if I add a math function that involves less than or equal bombard range, I can make a WithinRange function that will restore bombard range...

Last edited by E on 02-10-2004 at 02:54

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 02:41 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

quote:
Originally posted by Solver
Hmm, do we have the source code online somewhere on a CVS? I currently have no access to the source, so I can't verify my memories...


I dont think its on a CVS, I just downloaded it and went through it agin. If you need specific files I can post them.

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 02:46 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Enter the AD-FREE zone

I can't remember for sure... would you post armydata.cpp? I think there was something of interest in it...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 02:50 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Help yourself to an AD-FREE life

zip:
mapdata.cpp
armydata.cpp
unitdata.cpp

Attachment: bombard .zip
This has been downloaded 1 time(s).

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 02:53 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Inflate your Upload Space

quote:
Originally posted by E
I see that (defender.IsAtLeastOneMoveLand())

also restricts it to one movement of land. I'm thinking I should change this to GetbombardRnage in order to have a value. Or I probably need to edit this function to something like "IsWithinRange" anybody see where GetBombardRange is?


That check is simply to ensure that the unit in question can move at all, because units which cannot move cannot bombard - it does not affect the range at all.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 02:55 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton, buy Civilization 2

Ok, thanks J,


I'm thinking if I add a math function to the getNeighborposn that involves less than or equal bombard range, I can make a WithinRange function that will restore bombard range...

but I'm a littlle wary of making a whole new code and not able to test it

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 02:56 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Suffering from ads?

quote:
Originally posted by E
Again, THank you very much for your walkthrough, it helped more than the C book I'm flipping through


Well, if your C book does not cover C++, then it will be rather less than what you want to understand this code properly.

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 02:58 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Support Apolyton buy from Amazon

quote:
Originally posted by Solver
Can't remember when I saw that previously, but even the bombardrange unit flag was checked for in the code. It's the IsNextTo function call that overrides ranged bombard orders, IIRC.


I presume the orders will be passed through the ArmyData code before they ever reach the UnitData code, so a test there will be sufficient to prevent ranged bombarding.

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 03:02 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Suffering from ads?

quote:
Originally posted by E
I'm thinking if I add a math function to the getNeighborposn that involves less than or equal bombard range, I can make a WithinRange function that will restore bombard range...

but I'm a littlle wary of making a whole new code and not able to test it


There is alreay a GetDistance function - it's used in the code you posted at the top of the thread - in fact that code is essentially exactly what you need, except that in ArmyData you have the complication that the units in the army might have differing BombardRange values, and some might not be able to bombard at all, and I'm sure there are other subtleties which don't come to mind right now...

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 03:05 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Enter the AD-FREE zone

ArmyData:BombardCity seems of interest as it has the (unused apparently) possibilities of damaging citizens/buildings during city bombardment.

The code I was referring to, though, is after all what is in the first post, specifically:

code:
sint32 UnitData::CanBombard(CellUnitList &defender) const { const UnitRecord *rec = g_theUnitDB->Get(m_type); double r = rec->GetBombardRange() + 0.5; double rsq = r * r; MapPoint dpos; defender.GetPos(dpos); if(GetDistance(dpos, m_pos, (sint32)r) > rsq) return FALSE;


So, it does check for whether the target is in the distance. I'm not sure if GetDistance > rsq will not return FALSE in some cases where it should actually return TRUE... but point is, all the code for ranged bombard is still there. I haven't found, however, where it tells the unit to move to its target before bombarding if there's a distance between them - disabling that is a must.

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 03:07 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#24 Report this post to a moderator
Increase the size of your Attachments

if I replace it with a function that says something like
if GetDistance =< BombardRange
return true

if getdistance > bombard range return false.

but

code:
const UnitRecord *rec = g_theUnitDB->Get(m_type); double r = rec->GetBombardRange() + 0.5; double rsq = r * r; MapPoint dpos; defender.GetPos(dpos); if(GetDistance(dpos, m_pos, (sint32)r) > rsq) return FALSE;


but this looks like it already does that...

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 03:08 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#25 Report this post to a moderator
Full PM-box? Change here!

LOl, I think solver and I saw the same thing. except I only have an inkling of knowing what the hell I'm doing...

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 03:15 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#26 Report this post to a moderator
Support Apolyton buy from Amazon

Well, I did run into that problem. The code gives squared distance there. And one should never let me anywhere near geometrical applications of coding or algebra .

Problem: suppose a cannon with a bombard range of 2. A target standing two tiles ahead. Range=2, r=2.5, rsq=6.25. Since the target is in range, GetDistance should return something less than 6.25. However, the exact way that GetDistance works is something I don't understand really, and I can't check with the code right now.

Why is it using a squared distance anyway, and adds 0.5 to the bombard range? Can't there be a linear function for getting distance that treats all adjacent squares as distance=1, the ones adjacent to those as distance=2, and so on?

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 03:21 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#27 Report this post to a moderator
Got spare money?

code:
sint32 UnitData::GetDistance(UnitData* unit1, UnitData* unit2, sint32 wrapRange) { MapPoint u2pos = unit2->m_pos; return GetDistance(unit1, u2pos, wrapRange); } sint32 UnitData::GetDistance(Installation &inst, UnitData* unit2, sint32 wrapRange) { MapPoint iPos; inst.GetPos(iPos); return GetDistance(unit2, iPos, wrapRange); } sint32 UnitData::GetDistance(const UnitData* unit, const MapPoint &pos, sint32 wrapRange) { MapPoint uPos; unit->GetPos(uPos); return GetDistance(uPos, pos, wrapRange); } sint32 UnitData::GetDistance(const MapPoint &uPos, const MapPoint &pos, sint32 wrapRange) { return MapPoint::GetSquaredDistance(uPos, pos);

Solver is offline Solver
Apolyton Duke Of Something
Latvia, Riga
Sep 2000
time: 07:22
  Old Post 02-10-2004 03:23 Visit Solver<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#28 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

Yup, it's the MapPoint:GetSquaredDistance function that actually does the funky calculation, then.

I'm going for some bedtime reading now, hope that someone will provide insight on that function .

E is offline E
King
July 24,2005 Ctp2 Tiles in sig!
May 1999
time: 21:22
  Old Post 02-10-2004 03:35 Visit E's homepage!
Edit/Delete Message Reply w/Quote
#29 Report this post to a moderator
Full PM-box? Change here!

code:
sint32 MapPoint::GetSquaredDistance(const MapPoint &from, const MapPoint &to) { ScreenPoint src(from); ScreenPoint dst(to); sint32 dx = dst.x - src.x; sint32 dy = dst.y - src.y; if (g_theWorld->IsYwrap()) dy = WrapDelta(dy, g_mp_size.y); if (g_theWorld->IsXwrap()) dx = WrapDelta(dx, 2 * g_mp_size.x); sint32 retval = (dx * dx + dy * dy) / 2; Assert(retval <= OldSquaredDistance(from, to)); return retval;


Why do we need to get squared distance for anything then?

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:22
  Old Post 02-10-2004 03:37 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#30 Report this post to a moderator
Remove this text

MapPoint::GetSquaredDistance does exactly what it says (modulo some tweaks to account for the isometric tile set and wrapping, of course...). The reason it adds 0.5 is so that diagonally adjacent squares (which have a squaredistance of 2) fit inside distance 1 (which has rsq=(1+0.5)^2=2.25). This is exactly the same function as is used for city radii, so that gives a visual demonstration of what the various distances include. IMHO it's better than the "number of squares to move" definition. Incidentally, there is no linear function that returns that number (at least, not linear in the mathematical sense...). Of course, it would fit in the game as a whole better if unit movement was more expensive diagonally too.

 
Pages (4): [ 1   2   3   4   ]
< Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:22.
Apolyton Time is 00:22.
    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.0664 seconds (93.14% PHP - 6.86% 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