Fix for the "CONT" that won't go away

Fix points calculation in BaseAPsToShootOrStab
Tweaks to inventory, soldier, and merc profile structs
Fix for divide by 0 in CalcBestShot


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1199 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Overhaul
2007-08-14 07:48:45 +00:00
parent 6b6700ce96
commit c9fb501033
7 changed files with 69 additions and 39 deletions
+19 -19
View File
@@ -2889,28 +2889,28 @@ void HandleMouseOverSoldierFaceForContMove( SOLDIERTYPE *pSoldier, BOOLEAN fOn )
return;
}
if ( fOn )
if ( fOn && CheckForMercContMove( pSoldier ) )
{
// Check if we are waiting to continue move...
if ( CheckForMercContMove( pSoldier ) )
//if ( CheckForMercContMove( pSoldier ) )
//{
// Display 'cont' on face....
// Get face
pFace = &gFacesData[ pSoldier->iFaceIndex ];
pFace->fDisplayTextOver = FACE_DRAW_TEXT_OVER;
wcscpy( pFace->zDisplayText, TacticalStr[ CONTINUE_OVER_FACE_STR ] );
sGridNo = pSoldier->sFinalDestination;
if ( pSoldier->bGoodContPath )
{
// Display 'cont' on face....
// Get face
pFace = &gFacesData[ pSoldier->iFaceIndex ];
pFace->fDisplayTextOver = FACE_DRAW_TEXT_OVER;
wcscpy( pFace->zDisplayText, TacticalStr[ CONTINUE_OVER_FACE_STR ] );
sGridNo = pSoldier->sFinalDestination;
if ( pSoldier->bGoodContPath )
{
sGridNo = pSoldier->sContPathLocation;
}
// While our mouse is here, draw a path!
PlotPath( pSoldier, sGridNo, NO_COPYROUTE, PLOT, TEMPORARY, (UINT16)pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints );
sGridNo = pSoldier->sContPathLocation;
}
// While our mouse is here, draw a path!
PlotPath( pSoldier, sGridNo, NO_COPYROUTE, PLOT, TEMPORARY, (UINT16)pSoldier->usUIMovementMode, NOT_STEALTH, FORWARD, pSoldier->bActionPoints );
//}
}
else
{
@@ -6063,4 +6063,4 @@ void HandleTacticalEffectsOfEquipmentChange( SOLDIERTYPE *pSoldier, UINT32 uiInv
}
}
}
}
}
+1 -1
View File
@@ -2605,7 +2605,7 @@ void BtnDoorMenuCallback(GUI_BUTTON *btn,INT32 reason)
}
else
{
// OK, set cancle code!
// OK, set cancel code!
gOpenDoorMenu.fMenuHandled = 2;
}
}
+2 -2
View File
@@ -1203,7 +1203,7 @@ UINT8 BaseAPsToShootOrStab( INT8 bAPs, INT8 bAimSkill, OBJECTTYPE * pObj )
// Their info is an array of item status, not weapon info, and they don't repeat
// fire anyway.
rof = Weapon[ pObj->usItem ].ubShotsPer4Turns;
if (Item[ pObj->usItem ].ubPerPocket == 0)
if (Item[ pObj->usItem ].ubPerPocket <= 1)
{
rof += GetRateOfFireBonus(pObj);
}
@@ -1217,7 +1217,7 @@ UINT8 BaseAPsToShootOrStab( INT8 bAPs, INT8 bAimSkill, OBJECTTYPE * pObj )
// Snap: Refactored the formula to reduce the number of integer divisions
Top = 8 * bAPs;
if (Item[ pObj->usItem ].ubPerPocket == 0)
if (Item[ pObj->usItem ].ubPerPocket <= 1)
{
Top *= ( 100 - GetPercentAPReduction(pObj) );
}
+38 -11
View File
@@ -231,6 +231,7 @@ BATTLESNDS_STRUCT gBattleSndsData[] =
// New inventory handling code.
// ----------------------------------------
#if 0
Inventory::Inventory() {
OBJECTTYPE filler;
memset( &filler, 0, sizeof( OBJECTTYPE ) );
@@ -244,9 +245,13 @@ Inventory::Inventory() {
clear();
Assert (inv.size() == slotCnt);
};
#endif
Inventory::Inventory(int slotCount) {
slotCnt = slotCount;
Inventory::Inventory(int slotCount ) :
inv(slotCount),
slotCnt( slotCount) {
#if 0
slotCnt = slotCount;
inv.reserve(slotCnt);
for (int idx=0; idx < slotCnt; ++idx) {
//OBJECTTYPE *filler = new OBJECTTYPE; // Use MEMALLOC?
@@ -256,14 +261,19 @@ Inventory::Inventory(int slotCount) {
inv.push_back(*filler);
}
clear();
#endif
initialize();
Assert (inv.size() == slotCnt);
};
Inventory::Inventory(const Inventory& src) {
inv.reserve(slotCnt);
Assert (src.inv.size() == slotCnt);
// 0verhaul: I do not think the reservation is necessary or advisable.
//inv.reserve(slotCnt);
//Assert (src.inv.size() == slotCnt);
inv = src.inv;
// 0verhaul: Must copy the new slot count or a class created with a different count assigned to this one
// will fail the assertion(s).
slotCnt = src.slotCnt;
Assert (inv.size() == slotCnt);
}
@@ -281,9 +291,12 @@ Inventory& Inventory::operator=(const Inventory& src)
(inv.size() != slotCnt)) {
int i = 0; // Set BP here if following asserts throw
}
Assert (src.inv.size() == slotCnt);
Assert (src.inv.size() == src.slotCnt);
Assert (inv.size() == slotCnt);
if (this != &src) {
slotCnt = src.slotCnt;
inv = src.inv;
#if 0
if (inv.size() == 0) {
inv.reserve(slotCnt);
for (int idx=0; idx < slotCnt; ++idx) {
@@ -295,6 +308,7 @@ Inventory& Inventory::operator=(const Inventory& src)
inv[idx] = src.inv[idx];
}
}
#endif
}
return *this;
}
@@ -316,7 +330,7 @@ OBJECTTYPE& Inventory::operator [] (int idx) {
return inv[idx];
};
void Inventory::clear() {
void Inventory::initialize() {
Assert (inv.size() == slotCnt);
for (int idx=0; idx < slotCnt; ++idx) {
memset(&inv[idx], 0, sizeof(OBJECTTYPE));
@@ -325,13 +339,19 @@ void Inventory::clear() {
// ----------------------------------------
SOLDIERTYPE::SOLDIERTYPE() {
SOLDIERTYPE::SOLDIERTYPE() :
inv(),
bNewItemCount(inv.size()),
bNewItemCycleCount(inv.size())
{
#if 0
bNewItemCount.reserve(inv.size());
bNewItemCycleCount.reserve(inv.size());
for (int idx=0; idx < (int)inv.size(); ++idx) {
bNewItemCount.push_back(0);
bNewItemCycleCount.push_back(0);
}
#endif
initialize();
Assert(bNewItemCount.size() == inv.size());
@@ -375,7 +395,7 @@ SOLDIERTYPE::~SOLDIERTYPE() {
// Note that the constructor does this automatically.
void SOLDIERTYPE::initialize() {
memset( this, 0, SIZEOF_SOLDIERTYPE_POD);
inv.clear();
inv.initialize();
for (int idx=0; idx < (int)inv.size(); ++idx) {
bNewItemCount[idx] = 0;
bNewItemCycleCount[idx] = 0;
@@ -519,7 +539,12 @@ void SOLDIERTYPE::CopyNewInventoryToOld() {
// ----------------------------------------
MERCPROFILESTRUCT::MERCPROFILESTRUCT() {
MERCPROFILESTRUCT::MERCPROFILESTRUCT() :
inv(NUM_INV_SLOTS),
bInvStatus(inv.size()),
bInvNumber(inv.size())
{
#if 0
inv.reserve(NUM_INV_SLOTS);
bInvStatus.reserve(NUM_INV_SLOTS);
bInvNumber.reserve(NUM_INV_SLOTS);
@@ -528,6 +553,7 @@ MERCPROFILESTRUCT::MERCPROFILESTRUCT() {
bInvStatus.push_back(0);
bInvNumber.push_back(0);
}
#endif
initialize();
Assert(inv.size() == NUM_INV_SLOTS);
@@ -585,11 +611,12 @@ void MERCPROFILESTRUCT::initialize() {
// Use this instead of the old method of calling memset!
// Note that the constructor does this automatically.
void MERCPROFILESTRUCT::clearInventory() {
for (int idx=0; idx < (int)inv.size(); ++idx) {
for (vector<int>::size_type idx=0; idx < inv.size(); ++idx) {
inv[idx] = 0;
bInvStatus[idx] = 0;
bInvNumber[idx] = 0;
}
Assert(inv.size() == NUM_INV_SLOTS);
Assert(bInvStatus.size() == NUM_INV_SLOTS);
Assert(bInvStatus.size() == NUM_INV_SLOTS);
+5 -4
View File
@@ -378,8 +378,9 @@ class Inventory {
public:
// Constructors
// Create an inventory with a fixed maximum number of slots
Inventory(); // Uses NUM_INV_SLOTS for slotCount
Inventory(int slotCount);
//Inventory(); // Uses NUM_INV_SLOTS for slotCount
// Just make NUM_INV_SLOTS the default. That way there's one routine to control them all
Inventory(int slotCount = NUM_INV_SLOTS);
// Copy Constructor
Inventory(const Inventory&);
@@ -393,8 +394,8 @@ public:
// Index operator
OBJECTTYPE& operator [] (int idx);
// Removes all items from the inventory
void clear();
// Resets all items in the inventory to empty
void initialize();
// How any slots are there in this inventory?
int size() const;
+1 -1
View File
@@ -95,7 +95,7 @@ SOLDIERCREATE_STRUCT::~SOLDIERCREATE_STRUCT() {
// Note that the constructor does this automatically.
void SOLDIERCREATE_STRUCT::initialize() {
memset( this, 0, SIZEOF_SOLDIERCREATE_STRUCT_POD);
Inv.clear();
Inv.initialize();
}
+3 -1
View File
@@ -251,7 +251,8 @@ void CalcBestShot(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestShot, BOOLEAN shootUns
if (pOpponent->sGridNo == pSoldier->sLastTarget)
{
// raw AP cost calculation included cost of changing target!
ubRawAPCost -= AP_CHANGE_TARGET;
// Not unless we really needed to change targets!
//ubRawAPCost -= AP_CHANGE_TARGET;
}
iBestHitRate = 0; // reset best hit rate to minimum
@@ -309,6 +310,7 @@ void CalcBestShot(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestShot, BOOLEAN shootUns
{
ubAimTime = AP_MIN_AIM_ATTACK;
ubChanceToHit = (UINT8) AICalcChanceToHitGun(pSoldier,pOpponent->sGridNo,ubAimTime, AIM_SHOT_TORSO);
Assert( ubRawAPCost > 0);
iHitRate = (pSoldier->bActionPoints * ubChanceToHit) / (ubRawAPCost + ubAimTime);
iBestHitRate = iHitRate;