aboutsummaryrefslogtreecommitdiff
path: root/engines/dm
diff options
context:
space:
mode:
authorStrangerke2016-09-07 21:28:53 +0200
committerStrangerke2016-09-07 21:43:18 +0200
commit7bda512dde965e50269d7eba45562db4c8fdd562 (patch)
tree60e93256679e929bf3055ba5462e4f60f719bafc /engines/dm
parent53a8bda124691c42ecf06d9d907902fe6e8e75cf (diff)
downloadscummvm-rg350-7bda512dde965e50269d7eba45562db4c8fdd562.tar.gz
scummvm-rg350-7bda512dde965e50269d7eba45562db4c8fdd562.tar.bz2
scummvm-rg350-7bda512dde965e50269d7eba45562db4c8fdd562.zip
DM: Start refactoring Timeline
Diffstat (limited to 'engines/dm')
-rw-r--r--engines/dm/menus.cpp2
-rw-r--r--engines/dm/timeline.cpp162
-rw-r--r--engines/dm/timeline.h6
3 files changed, 86 insertions, 84 deletions
diff --git a/engines/dm/menus.cpp b/engines/dm/menus.cpp
index b2f159f857..2b331c9912 100644
--- a/engines/dm/menus.cpp
+++ b/engines/dm/menus.cpp
@@ -930,7 +930,7 @@ bool MenuMan::didClickTriggerAction(int16 actionListIndex) {
// Fix original bug - When disabled ticks is equal to zero, increasing the defense leads
// to a permanent increment.
if (_actionDisabledTicks[actionIndex])
- curChampion->_actionDefense += _actionDefense[actionIndex];
+ curChampion->_actionDefense += _vm->_timeline->_actionDefense[actionIndex];
setFlag(curChampion->_attributes, k0x0100_ChampionAttributeStatistics);
retVal = isActionPerformed(championIndex, actionIndex);
diff --git a/engines/dm/timeline.cpp b/engines/dm/timeline.cpp
index b4c70bbc88..0f722077fa 100644
--- a/engines/dm/timeline.cpp
+++ b/engines/dm/timeline.cpp
@@ -40,51 +40,57 @@
namespace DM {
-signed char _actionDefense[44] = { // @ G0495_ac_Graphic560_ActionDefense
- 0, /* N */
- 36, /* BLOCK */
- 0, /* CHOP */
- 0, /* X */
- -4, /* BLOW HORN */
- -10, /* FLIP */
- -10, /* PUNCH */
- -5, /* KICK */
- 4, /* WAR CRY */
- -20, /* STAB */
- -15, /* CLIMB DOWN */
- -10, /* FREEZE LIFE */
- 16, /* HIT */
- 5, /* SWING */
- -15, /* STAB */
- -17, /* THRUST */
- -5, /* JAB */
- 29, /* PARRY */
- 10, /* HACK */
- -10, /* BERZERK */
- -7, /* FIREBALL */
- -7, /* DISPELL */
- -7, /* CONFUSE */
- -7, /* LIGHTNING */
- -7, /* DISRUPT */
- -5, /* MELEE */
- -15, /* X */
- -9, /* INVOKE */
- 4, /* SLASH */
- 0, /* CLEAVE */
- 0, /* BASH */
- 5, /* STUN */
- -15, /* SHOOT */
- -7, /* SPELLSHIELD */
- -7, /* FIRESHIELD */
- 8, /* FLUXCAGE */
- -20, /* HEAL */
- -5, /* CALM */
- 0, /* LIGHT */
- -15, /* WINDOW */
- -7, /* SPIT */
- -4, /* BRANDISH */
- 0, /* THROW */
- 8}; /* FUSE */
+void Timeline::initConstants() {
+ static signed char actionDefense[44] = { // @ G0495_ac_Graphic560_ActionDefense
+ 0, /* N */
+ 36, /* BLOCK */
+ 0, /* CHOP */
+ 0, /* X */
+ -4, /* BLOW HORN */
+ -10, /* FLIP */
+ -10, /* PUNCH */
+ -5, /* KICK */
+ 4, /* WAR CRY */
+ -20, /* STAB */
+ -15, /* CLIMB DOWN */
+ -10, /* FREEZE LIFE */
+ 16, /* HIT */
+ 5, /* SWING */
+ -15, /* STAB */
+ -17, /* THRUST */
+ -5, /* JAB */
+ 29, /* PARRY */
+ 10, /* HACK */
+ -10, /* BERZERK */
+ -7, /* FIREBALL */
+ -7, /* DISPELL */
+ -7, /* CONFUSE */
+ -7, /* LIGHTNING */
+ -7, /* DISRUPT */
+ -5, /* MELEE */
+ -15, /* X */
+ -9, /* INVOKE */
+ 4, /* SLASH */
+ 0, /* CLEAVE */
+ 0, /* BASH */
+ 5, /* STUN */
+ -15, /* SHOOT */
+ -7, /* SPELLSHIELD */
+ -7, /* FIRESHIELD */
+ 8, /* FLUXCAGE */
+ -20, /* HEAL */
+ -5, /* CALM */
+ 0, /* LIGHT */
+ -15, /* WINDOW */
+ -7, /* SPIT */
+ -4, /* BRANDISH */
+ 0, /* THROW */
+ 8 /* FUSE */
+ };
+
+ for (int i = 0; i < 44; i++)
+ _actionDefense[i] = actionDefense[i];
+}
Timeline::Timeline(DMEngine* vm) : _vm(vm) {
_eventMaxCount = 0;
@@ -92,6 +98,8 @@ Timeline::Timeline(DMEngine* vm) : _vm(vm) {
_eventCount = 0;
_timeline = nullptr;
_firstUnusedEventIndex = 0;
+
+ initConstants();
}
Timeline::~Timeline() {
@@ -111,45 +119,37 @@ void Timeline::initTimeline() {
}
void Timeline::deleteEvent(uint16 eventIndex) {
- uint16 L0586_ui_TimelineIndex;
- uint16 L0587_ui_EventCount;
-
-
_events[eventIndex]._type = k0_TMEventTypeNone;
- if (eventIndex < _firstUnusedEventIndex) {
+ if (eventIndex < _firstUnusedEventIndex)
_firstUnusedEventIndex = eventIndex;
- }
+
_eventCount--;
- if ((L0587_ui_EventCount = _eventCount) == 0) {
+
+ uint16 eventCount = _eventCount;
+ if (eventCount == 0)
return;
- }
- L0586_ui_TimelineIndex = getIndex(eventIndex);
- if (L0586_ui_TimelineIndex == L0587_ui_EventCount) {
+
+ uint16 timelineIndex = getIndex(eventIndex);
+ if (timelineIndex == eventCount)
return;
- }
- _timeline[L0586_ui_TimelineIndex] = _timeline[L0587_ui_EventCount];
- fixChronology(L0586_ui_TimelineIndex);
+
+ _timeline[timelineIndex] = _timeline[eventCount];
+ fixChronology(timelineIndex);
}
void Timeline::fixChronology(uint16 timelineIndex) {
- uint16 L0581_ui_TimelineIndex;
- uint16 L0582_ui_EventIndex;
- uint16 L0583_ui_EventCount;
- TimelineEvent* L0584_ps_Event;
- bool L0585_B_ChronologyFixed;
-
-
- if ((L0583_ui_EventCount = _eventCount) == 1) {
+ uint16 eventCount = _eventCount;
+ if (eventCount == 1)
return;
- }
- L0584_ps_Event = &_events[L0582_ui_EventIndex = _timeline[timelineIndex]];
- L0585_B_ChronologyFixed = false;
+ uint16 L0582_ui_EventIndex = _timeline[timelineIndex];
+ TimelineEvent *timelineEvent = &_events[L0582_ui_EventIndex];
+ bool L0585_B_ChronologyFixed = false;
while (timelineIndex > 0) { /* Check if the event should be moved earlier in the timeline */
- L0581_ui_TimelineIndex = (timelineIndex - 1) >> 1;
- if (isEventABeforeB(L0584_ps_Event, &_events[_timeline[L0581_ui_TimelineIndex]])) {
- _timeline[timelineIndex] = _timeline[L0581_ui_TimelineIndex];
- timelineIndex = L0581_ui_TimelineIndex;
+ uint16 altTimelineIndex = (timelineIndex - 1) >> 1;
+ if (isEventABeforeB(timelineEvent, &_events[_timeline[altTimelineIndex]])) {
+ _timeline[timelineIndex] = _timeline[altTimelineIndex];
+ timelineIndex = altTimelineIndex;
L0585_B_ChronologyFixed = true;
} else {
break;
@@ -157,15 +157,15 @@ void Timeline::fixChronology(uint16 timelineIndex) {
}
if (L0585_B_ChronologyFixed)
goto T0236011;
- L0583_ui_EventCount = ((L0583_ui_EventCount - 1) - 1) >> 1;
- while (timelineIndex <= L0583_ui_EventCount) { /* Check if the event should be moved later in the timeline */
- L0581_ui_TimelineIndex = (timelineIndex << 1) + 1;
- if (((L0581_ui_TimelineIndex + 1) < _eventCount) && (isEventABeforeB(&_events[_timeline[L0581_ui_TimelineIndex + 1]], &_events[_timeline[L0581_ui_TimelineIndex]]))) {
- L0581_ui_TimelineIndex++;
+ eventCount = ((eventCount - 1) - 1) >> 1;
+ while (timelineIndex <= eventCount) { /* Check if the event should be moved later in the timeline */
+ uint16 altTimelineIndex = (timelineIndex << 1) + 1;
+ if (((altTimelineIndex + 1) < _eventCount) && (isEventABeforeB(&_events[_timeline[altTimelineIndex + 1]], &_events[_timeline[altTimelineIndex]]))) {
+ altTimelineIndex++;
}
- if (isEventABeforeB(&_events[_timeline[L0581_ui_TimelineIndex]], L0584_ps_Event)) {
- _timeline[timelineIndex] = _timeline[L0581_ui_TimelineIndex];
- timelineIndex = L0581_ui_TimelineIndex;
+ if (isEventABeforeB(&_events[_timeline[altTimelineIndex]], timelineEvent)) {
+ _timeline[timelineIndex] = _timeline[altTimelineIndex];
+ timelineIndex = altTimelineIndex;
} else {
break;
}
diff --git a/engines/dm/timeline.h b/engines/dm/timeline.h
index 1c0f51a8c7..3f87ae24ed 100644
--- a/engines/dm/timeline.h
+++ b/engines/dm/timeline.h
@@ -95,8 +95,6 @@ k82_TMEventTypeMagicMap_C82 = 82, // @ C82_EVENT_MAGIC_MAP
k83_TMEventTypeMagicMap_C83 = 83 // @ C83_EVENT_MAGIC_MAP
};
-extern signed char _actionDefense[44]; // @ G0495_ac_Graphic560_ActionDefense
-
class TimelineEvent {
public:
int32 _mapTime;
@@ -191,6 +189,10 @@ public:
void saveTimelinePart(Common::OutSaveFile *file);
void loadEventsPart(Common::InSaveFile* file);
void loadTimelinePart(Common::InSaveFile* file);
+
+ signed char _actionDefense[44]; // @ G0495_ac_Graphic560_ActionDefense
+
+ void initConstants();
};
}