Skip to content

Commit

Permalink
Add "modified" checks for HXM writes; testing required
Browse files Browse the repository at this point in the history
  • Loading branch information
SiriusTR committed Sep 17, 2019
1 parent 3a35973 commit 4d6ed14
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/ObjectTool.AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ if (nId < 0 || nId >= MAX_ROBOT_ID_D2)

CRobotInfo robotInfo = *robotManager.RobotInfo (nId);
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);
robotInfo.Info ().kamikaze = BtnCtrl (IDC_OBJ_AI_KAMIKAZE)->GetCheck ();
robotInfo.Info ().companion = BtnCtrl (IDC_OBJ_AI_COMPANION)->GetCheck ();
robotInfo.Info ().thief = BtnCtrl (IDC_OBJ_AI_THIEF)->GetCheck ();
Expand Down
1 change: 1 addition & 0 deletions src/ObjectTool.Combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ if (0 <= (index = CBWeapon2 ()->GetCurSel ()))

int nSkill = SlCtrl (IDC_OBJ_SKILL_SLIDER)->GetPos ();
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);
robotInfo.Info ().combat [nSkill].fieldOfView = m_data [1].GetValue ();
robotInfo.Info ().combat [nSkill].firingWait [0] = m_data [2].GetValue ();
robotInfo.Info ().combat [nSkill].firingWait [1] = m_data [3].GetValue ();
Expand Down
1 change: 1 addition & 0 deletions src/ObjectTool.Death.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ if ((nId < 0) || (nId >= MAX_ROBOT_ID_D2))
nId = 0;
CRobotInfo robotInfo = *robotManager.RobotInfo (nId);
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);

robotInfo.Info ().scoreValue = m_data [0].GetValue ();
robotInfo.Info ().deathRoll = m_data [1].GetValue ();
Expand Down
1 change: 1 addition & 0 deletions src/ObjectTool.Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if ((nId < 0) || (nId >= MAX_ROBOT_ID_D2))
nId = 0;
CRobotInfo robotInfo = *robotManager.RobotInfo (nId);
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);

robotInfo.SetStrength (m_data [0].GetValue ());
robotInfo.Info ().mass = m_data [1].GetValue ();
Expand Down
1 change: 1 addition & 0 deletions src/ObjectTool.Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ if (nId < 0 || nId >= MAX_ROBOT_ID_D2)
nId = 0;
CRobotInfo robotInfo = *robotManager.RobotInfo (nId);
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);

int index;

Expand Down
1 change: 1 addition & 0 deletions src/ObjectTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ if ((nId < 0) || (nId >= MAX_ROBOT_ID_D2))

CRobotInfo robotInfo = *robotManager.RobotInfo (nId);
robotInfo.Info ().bCustom |= 1;
robotInfo.SetModified (true);
Current ()->UpdateRobot ();
#if 0
undoManager.Begin (__FUNCTION__, udRobots);
Expand Down
10 changes: 10 additions & 0 deletions src/RobotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ return (m_hxmExtraDataSize > 0);

//------------------------------------------------------------------------------

bool CRobotManager::HasModifiedRobots ()
{
for (int i = 0; i < (int) m_nRobotTypes; i++)
if (RobotInfo (i)->IsModified ())
return true;
return false;
}

//------------------------------------------------------------------------------

void CRobotManager::ClearHXMData ()
{
for (int i = 0; i < (int) m_nRobotTypes; i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/RobotManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class CRobotManager {

bool HasCustomRobots (void);

bool HasModifiedRobots ();

void LoadResource (int nRobot);

int ReadHAM (CFileManager* fp, int type = NORMAL_HAM);
Expand Down
6 changes: 2 additions & 4 deletions src/dlcDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ else {
else
bSucceeded &= WriteExternalCustomFile (CUSTOM_FILETYPE_DTX);

if (robotManager.HasCustomRobots ())
if (robotManager.HasModifiedRobots ())
bSucceeded &= WriteExternalCustomFile (CUSTOM_FILETYPE_HXM);
}

Expand Down Expand Up @@ -508,10 +508,8 @@ switch (nType) {
case CUSTOM_FILETYPE_HXM:
if (DLE.IsD1File ())
break;
// We don't currently track modified robots, so we'll just always prompt for overwrite (unless the
// custom robots have been removed in which case we won't ask as the question would be confusing)
if (DoesSubFileExist (m_szFile, szSubFileName))
bShouldModify = !robotManager.HasCustomRobots () || (QueryMsg (szOverwriteHxmQuery) == IDYES);
bShouldModify = robotManager.HasModifiedRobots () && (QueryMsg (szOverwriteHxmQuery) == IDYES);
else
bShouldModify = robotManager.HasCustomRobots () && (QueryMsg (szHxmQuery) == IDYES);
break;
Expand Down
10 changes: 9 additions & 1 deletion src/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ typedef struct tRobotInfo {
class CRobotInfo : public CGameItem {
private:
tRobotInfo m_info;
bool m_bModified;

public:
void Read (CFileManager* fp, int version = 0, bool bFlag = false);

void Write (CFileManager* fp, int version = 0, bool bFlag = false);

virtual void Clear (void) { memset (&m_info, 0, sizeof (m_info)); }
virtual void Clear (void) {
memset (&m_info, 0, sizeof (m_info));
m_bModified = false;
}

virtual CGameItem* Clone (void);

Expand All @@ -149,6 +153,10 @@ class CRobotInfo : public CGameItem {
inline int GetStrength (void) { return (m_info.strength > 0) ? FixLog (m_info.strength) - 12 : 0; }

inline void SetStrength (int strength) { m_info.strength = (strength > 0) ? FixExp (strength + 12) : 0; }

inline bool IsModified () { return m_bModified; }

inline void SetModified (bool bModified) { m_bModified = bModified; }
};

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 4d6ed14

Please sign in to comment.