2016-06-30 17:59:35 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
*/
/*
* Based on the Reverse Engineering work of Christophe Fontanel ,
* maintainer of the Dungeon Master Encyclopaedia ( http : //dmweb.free.fr/)
*/
2016-09-03 08:38:43 +00:00
# include "dm/timeline.h"
# include "dm/dungeonman.h"
# include "dm/champion.h"
# include "dm/inventory.h"
# include "dm/group.h"
# include "dm/projexpl.h"
# include "dm/movesens.h"
# include "dm/text.h"
# include "dm/eventman.h"
# include "dm/objectman.h"
# include "dm/sounds.h"
2016-06-30 17:59:35 +00:00
namespace DM {
2016-09-07 19:28:53 +00:00
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 ] ;
}
2016-07-12 06:18:25 +00:00
2016-09-08 04:47:56 +00:00
Timeline : : Timeline ( DMEngine * vm ) : _vm ( vm ) {
2016-08-25 20:38:03 +00:00
_eventMaxCount = 0 ;
_events = nullptr ;
_eventCount = 0 ;
_timeline = nullptr ;
_firstUnusedEventIndex = 0 ;
2016-09-07 19:28:53 +00:00
initConstants ( ) ;
2016-06-30 17:59:35 +00:00
}
Timeline : : ~ Timeline ( ) {
2016-08-25 20:38:03 +00:00
delete [ ] _events ;
delete [ ] _timeline ;
2016-06-30 17:59:35 +00:00
}
2016-08-25 20:38:03 +00:00
void Timeline : : initTimeline ( ) {
_events = new TimelineEvent [ _eventMaxCount ] ;
_timeline = new uint16 [ _eventMaxCount ] ;
2016-09-19 19:45:14 +00:00
if ( _vm - > _gameMode ! = kDMModeLoadSavedGame ) {
2016-08-25 20:38:03 +00:00
for ( int16 i = 0 ; i < _eventMaxCount ; + + i )
2016-09-20 19:51:42 +00:00
_events [ i ] . _type = kDMEventTypeNone ;
2016-08-25 20:38:03 +00:00
_eventCount = 0 ;
_firstUnusedEventIndex = 0 ;
2016-06-30 17:59:35 +00:00
}
}
2016-08-25 20:38:03 +00:00
void Timeline : : deleteEvent ( uint16 eventIndex ) {
2016-09-20 19:51:42 +00:00
_events [ eventIndex ] . _type = kDMEventTypeNone ;
2016-09-07 19:28:53 +00:00
if ( eventIndex < _firstUnusedEventIndex )
2016-08-25 20:38:03 +00:00
_firstUnusedEventIndex = eventIndex ;
2016-09-07 19:28:53 +00:00
2016-08-25 20:38:03 +00:00
_eventCount - - ;
2016-09-10 19:50:57 +00:00
2016-09-07 19:28:53 +00:00
uint16 eventCount = _eventCount ;
if ( eventCount = = 0 )
2016-07-06 22:46:51 +00:00
return ;
2016-09-07 19:28:53 +00:00
uint16 timelineIndex = getIndex ( eventIndex ) ;
if ( timelineIndex = = eventCount )
2016-07-06 22:46:51 +00:00
return ;
2016-09-07 19:28:53 +00:00
_timeline [ timelineIndex ] = _timeline [ eventCount ] ;
fixChronology ( timelineIndex ) ;
2016-07-06 22:46:51 +00:00
}
2016-08-25 20:38:03 +00:00
void Timeline : : fixChronology ( uint16 timelineIndex ) {
2016-09-07 19:28:53 +00:00
uint16 eventCount = _eventCount ;
if ( eventCount = = 1 )
2016-07-06 22:46:51 +00:00
return ;
2016-09-07 19:46:08 +00:00
uint16 eventIndex = _timeline [ timelineIndex ] ;
TimelineEvent * timelineEvent = & _events [ eventIndex ] ;
bool chronologyFixed = false ;
2016-07-06 22:46:51 +00:00
while ( timelineIndex > 0 ) { /* Check if the event should be moved earlier in the timeline */
2016-09-07 19:28:53 +00:00
uint16 altTimelineIndex = ( timelineIndex - 1 ) > > 1 ;
if ( isEventABeforeB ( timelineEvent , & _events [ _timeline [ altTimelineIndex ] ] ) ) {
_timeline [ timelineIndex ] = _timeline [ altTimelineIndex ] ;
timelineIndex = altTimelineIndex ;
2016-09-07 19:46:08 +00:00
chronologyFixed = true ;
} else
2016-07-06 22:46:51 +00:00
break ;
}
2016-09-07 19:46:08 +00:00
if ( ! chronologyFixed ) {
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 + + ;
2016-09-10 19:50:57 +00:00
2016-09-07 19:46:08 +00:00
if ( isEventABeforeB ( & _events [ _timeline [ altTimelineIndex ] ] , timelineEvent ) ) {
_timeline [ timelineIndex ] = _timeline [ altTimelineIndex ] ;
timelineIndex = altTimelineIndex ;
} else
break ;
2016-07-06 22:46:51 +00:00
}
}
2016-09-07 19:46:08 +00:00
_timeline [ timelineIndex ] = eventIndex ;
2016-07-06 22:46:51 +00:00
}
2016-09-07 20:19:10 +00:00
bool Timeline : : isEventABeforeB ( TimelineEvent * eventA , TimelineEvent * eventB ) {
2016-09-11 07:46:35 +00:00
bool simultaneousFl = ( _vm - > filterTime ( eventA - > _mapTime ) = = _vm - > filterTime ( eventB - > _mapTime ) ) ;
2016-07-06 22:46:51 +00:00
2016-09-11 07:46:35 +00:00
return ( _vm - > filterTime ( eventA - > _mapTime ) < _vm - > filterTime ( eventB - > _mapTime ) ) | |
2016-09-07 20:19:10 +00:00
( simultaneousFl & & ( eventA - > getTypePriority ( ) > eventB - > getTypePriority ( ) ) ) | |
( simultaneousFl & & ( eventA - > getTypePriority ( ) = = eventB - > getTypePriority ( ) ) & & ( eventA < = eventB ) ) ;
2016-07-06 22:46:51 +00:00
}
2016-08-25 20:38:03 +00:00
uint16 Timeline : : getIndex ( uint16 eventIndex ) {
2016-09-07 20:19:10 +00:00
uint16 timelineIndex ;
uint16 * timelineEntry = _timeline ;
2016-07-06 22:46:51 +00:00
2016-09-07 20:19:10 +00:00
for ( timelineIndex = 0 ; timelineIndex < _eventMaxCount ; timelineIndex + + ) {
if ( * timelineEntry + + = = eventIndex )
2016-07-06 22:46:51 +00:00
break ;
}
2016-09-07 20:19:10 +00:00
if ( timelineIndex > = _eventMaxCount ) /* BUG0_00 Useless code. The function is always called with event indices that are in the timeline */
timelineIndex = 0 ; /* BUG0_01 Coding error without consequence. Wrong return value. If the specified event index is not found in the timeline the function returns 0 which is the same value that is returned if the event index is found in the first timeline entry. No consequence because this code is never executed */
2016-07-06 22:46:51 +00:00
2016-09-07 20:19:10 +00:00
return timelineIndex ;
}
2016-07-06 22:46:51 +00:00
2016-09-07 20:19:10 +00:00
uint16 Timeline : : addEventGetEventIndex ( TimelineEvent * event ) {
2016-08-27 21:10:13 +00:00
if ( _eventCount = = _eventMaxCount )
error ( " Too many events " ) ;
2016-09-20 19:51:42 +00:00
if ( ( event - > _type > = kDMEventTypeCorridor ) & & ( event - > _type < = kDMEventTypeDoor ) ) {
2016-09-07 20:19:10 +00:00
TimelineEvent * curEvent = _events ;
for ( uint16 eventIndex = 0 ; eventIndex < _eventMaxCount ; eventIndex + + , curEvent + + ) {
2016-09-20 19:51:42 +00:00
if ( ( curEvent - > _type > = kDMEventTypeCorridor ) & & ( curEvent - > _type < = kDMEventTypeDoor ) ) {
if ( ( event - > _mapTime = = curEvent - > _mapTime ) & & ( event - > getMapXY ( ) = = curEvent - > getMapXY ( ) ) & & ( ( curEvent - > _type ! = kDMEventTypeWall ) | | ( curEvent - > _Cu . A . _cell = = event - > _Cu . A . _cell ) ) ) {
2016-09-10 19:54:22 +00:00
curEvent - > _Cu . A . _effect = event - > _Cu . A . _effect ;
2016-09-07 20:19:10 +00:00
return eventIndex ;
2016-07-06 22:46:51 +00:00
}
continue ;
2016-09-20 19:51:42 +00:00
} else if ( ( curEvent - > _type = = kDMEventTypeDoorAnimation ) & & ( event - > _mapTime = = curEvent - > _mapTime ) & & ( event - > getMapXY ( ) = = curEvent - > getMapXY ( ) ) ) {
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-10 19:54:22 +00:00
event - > _Cu . A . _effect = 1 - curEvent - > _Cu . A . _effect ;
2016-09-07 20:19:10 +00:00
deleteEvent ( eventIndex ) ;
break ;
2016-07-06 22:46:51 +00:00
}
}
2016-09-20 19:51:42 +00:00
} else if ( event - > _type = = kDMEventTypeDoorAnimation ) {
2016-09-07 20:19:10 +00:00
TimelineEvent * curEvent = _events ;
for ( uint16 eventIndex = 0 ; eventIndex < _eventMaxCount ; eventIndex + + , curEvent + + ) {
if ( ( event - > _mapTime = = curEvent - > _mapTime ) & & ( event - > getMapXY ( ) = = curEvent - > getMapXY ( ) ) ) {
2016-09-20 19:51:42 +00:00
if ( curEvent - > _type = = kDMEventTypeDoor ) {
2016-09-11 22:03:48 +00:00
if ( curEvent - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-10 19:54:22 +00:00
curEvent - > _Cu . A . _effect = 1 - event - > _Cu . A . _effect ;
2016-09-07 20:19:10 +00:00
return eventIndex ;
2016-07-06 22:46:51 +00:00
}
2016-09-20 19:51:42 +00:00
if ( curEvent - > _type = = kDMEventTypeDoorAnimation ) {
2016-09-10 19:54:22 +00:00
curEvent - > _Cu . A . _effect = event - > _Cu . A . _effect ;
2016-09-07 20:19:10 +00:00
return eventIndex ;
2016-07-06 22:46:51 +00:00
}
}
}
2016-09-20 19:51:42 +00:00
} else if ( event - > _type = = kDMEventTypeDoorDestruction ) {
2016-09-07 20:19:10 +00:00
TimelineEvent * curEvent = _events ;
for ( uint16 eventIndex = 0 ; eventIndex < _eventMaxCount ; eventIndex + + , curEvent + + ) {
2016-09-11 07:46:35 +00:00
if ( ( event - > getMapXY ( ) = = curEvent - > getMapXY ( ) ) & & ( _vm - > getMap ( event - > _mapTime ) = = _vm - > getMap ( curEvent - > _mapTime ) ) ) {
2016-09-20 19:51:42 +00:00
if ( ( curEvent - > _type = = kDMEventTypeDoorAnimation ) | | ( curEvent - > _type = = kDMEventTypeDoor ) )
2016-09-07 20:19:10 +00:00
deleteEvent ( eventIndex ) ;
}
}
2016-07-06 22:46:51 +00:00
}
2016-09-07 20:19:10 +00:00
uint16 newEventIndex = _firstUnusedEventIndex ;
_events [ newEventIndex ] = * event ; /* Copy the event data (Megamax C can assign structures) */
2016-07-06 22:46:51 +00:00
do {
2016-08-25 20:38:03 +00:00
if ( _firstUnusedEventIndex = = _eventMaxCount )
2016-07-06 22:46:51 +00:00
break ;
2016-08-25 20:38:03 +00:00
_firstUnusedEventIndex + + ;
2016-09-20 19:51:42 +00:00
} while ( ( _events [ _firstUnusedEventIndex ] ) . _type ! = kDMEventTypeNone ) ;
2016-09-07 20:19:10 +00:00
_timeline [ _eventCount ] = newEventIndex ;
2016-08-25 20:38:03 +00:00
fixChronology ( _eventCount + + ) ;
2016-09-07 20:19:10 +00:00
return newEventIndex ;
2016-07-06 22:46:51 +00:00
}
2016-08-25 20:38:03 +00:00
void Timeline : : processTimeline ( ) {
while ( isFirstEventExpiered ( ) ) {
2016-09-07 20:19:10 +00:00
TimelineEvent newEvent ;
TimelineEvent * curEvent = & newEvent ;
extractFirstEvent ( curEvent ) ;
2016-09-11 07:46:35 +00:00
_vm - > _dungeonMan - > setCurrentMap ( _vm - > getMap ( newEvent . _mapTime ) ) ;
2016-09-20 20:26:00 +00:00
TimelineEventType curEventType = newEvent . _type ;
2016-09-20 19:51:42 +00:00
if ( ( curEventType > ( kDMEventTypeGroupReactionDangerOnSquare - 1 ) ) & & ( curEventType < ( kDMEventTypeUpdateBehavior3 + 1 ) ) )
2016-09-10 19:54:22 +00:00
_vm - > _groupMan - > processEvents29to41 ( newEvent . _Bu . _location . _mapX , newEvent . _Bu . _location . _mapY , curEventType , newEvent . _Cu . _ticks ) ;
2016-09-07 20:19:10 +00:00
else {
switch ( curEventType ) {
2016-09-20 19:51:42 +00:00
case kDMEventTypeMoveProjectileIgnoreImpacts :
case kDMEventTypeMoveProjectile :
2016-09-07 20:19:10 +00:00
_vm - > _projexpl - > processEvents48To49 ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeDoorAnimation :
2016-09-07 20:19:10 +00:00
processEventDoorAnimation ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeExplosion :
2016-09-07 20:19:10 +00:00
_vm - > _projexpl - > processEvent25 ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeFakeWall :
2016-09-07 20:19:10 +00:00
processEventSquareFakewall ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeDoorDestruction :
2016-09-07 20:19:10 +00:00
processEventDoorDestruction ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeDoor :
2016-09-07 20:19:10 +00:00
processEventSquareDoor ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypePit :
2016-09-07 20:19:10 +00:00
processEventSquarePit ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeTeleporter :
2016-09-07 20:19:10 +00:00
processEventSquareTeleporter ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeWall :
2016-09-07 20:19:10 +00:00
processEventSquareWall ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeCorridor :
2016-09-07 20:19:10 +00:00
processEventSquareCorridor ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeMoveGroupSilent :
case kDMEventTypeMoveGroupAudible :
2016-09-07 20:19:10 +00:00
processEventsMoveGroup ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeEnableGroupGenerator :
2016-09-07 20:19:10 +00:00
procesEventEnableGroupGenerator ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypePlaySound :
2016-09-12 20:36:17 +00:00
_vm - > _sound - > requestPlay ( newEvent . _Cu . _soundIndex , newEvent . _Bu . _location . _mapX , newEvent . _Bu . _location . _mapY , kDMSoundModePlayIfPrioritized ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeRemoveFluxcage :
2016-08-23 21:36:18 +00:00
if ( ! _vm - > _gameWon ) {
2016-09-10 19:54:22 +00:00
_vm - > _dungeonMan - > unlinkThingFromList ( Thing ( newEvent . _Cu . _slot ) , Thing ( 0 ) , newEvent . _Bu . _location . _mapX , newEvent . _Bu . _location . _mapY ) ;
curEvent = ( TimelineEvent * ) _vm - > _dungeonMan - > getThingData ( Thing ( newEvent . _Cu . _slot ) ) ;
2016-09-08 04:47:56 +00:00
( ( Explosion * ) curEvent ) - > setNextThing ( Thing : : _none ) ;
2016-07-11 12:33:25 +00:00
}
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeEnableChampionAction :
2016-09-07 20:19:10 +00:00
processEventEnableChampionAction ( newEvent . _priority ) ;
2016-09-10 19:50:57 +00:00
if ( newEvent . _Bu . _slotOrdinal )
processEventMoveWeaponFromQuiverToSlot ( newEvent . _priority , _vm - > ordinalToIndex ( newEvent . _Bu . _slotOrdinal ) ) ;
2016-09-07 20:21:01 +00:00
_vm - > _championMan - > drawChampionState ( ( ChampionIndex ) newEvent . _priority ) ;
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeHideDamageReceived :
2016-09-07 20:19:10 +00:00
processEventHideDamageReceived ( newEvent . _priority ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeLight :
2016-08-24 06:03:55 +00:00
_vm - > _dungeonMan - > setCurrentMap ( _vm - > _dungeonMan - > _partyMapIndex ) ;
2016-09-07 20:19:10 +00:00
processEventLight ( curEvent ) ;
2016-08-25 19:25:18 +00:00
_vm - > _inventoryMan - > setDungeonViewPalette ( ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeInvisibility :
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > _party . _event71Count_Invisibility - - ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeChampionShield :
2016-09-10 19:50:57 +00:00
_vm - > _championMan - > _champions [ newEvent . _priority ] . _shieldDefense - = newEvent . _Bu . _defense ;
2016-09-09 05:32:32 +00:00
setFlag ( _vm - > _championMan - > _champions [ newEvent . _priority ] . _attributes , kDMAttributeStatusBox ) ;
2016-09-07 20:19:10 +00:00
_vm - > _championMan - > drawChampionState ( ( ChampionIndex ) newEvent . _priority ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeThievesEye :
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > _party . _event73Count_ThievesEye - - ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypePartyShield :
2016-09-10 19:50:57 +00:00
_vm - > _championMan - > _party . _shieldDefense - = newEvent . _Bu . _defense ;
2016-08-25 20:38:03 +00:00
refreshAllChampionStatusBoxes ( ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeSpellShield :
2016-09-10 19:50:57 +00:00
_vm - > _championMan - > _party . _spellShieldDefense - = newEvent . _Bu . _defense ;
2016-09-07 20:21:01 +00:00
refreshAllChampionStatusBoxes ( ) ;
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeFireShield :
2016-09-10 19:50:57 +00:00
_vm - > _championMan - > _party . _fireShieldDefense - = newEvent . _Bu . _defense ;
2016-09-07 20:21:01 +00:00
refreshAllChampionStatusBoxes ( ) ;
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypePoisonChampion : {
2016-09-07 20:19:10 +00:00
uint16 championIndex = newEvent . _priority ;
_vm - > _championMan - > _champions [ championIndex = newEvent . _priority ] . _poisonEventCount - - ;
2016-09-10 19:50:57 +00:00
_vm - > _championMan - > championPoison ( championIndex , newEvent . _Bu . _attack ) ;
2016-09-07 20:19:10 +00:00
}
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeViAltarRebirth :
2016-09-07 20:19:10 +00:00
processEventViAltarRebirth ( curEvent ) ;
2016-07-11 12:33:25 +00:00
break ;
2016-09-20 19:51:42 +00:00
case kDMEventTypeFootprints :
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > _party . _event79Count_Footprints - - ;
2016-09-22 05:01:56 +00:00
break ;
default :
break ;
2016-07-11 12:33:25 +00:00
}
}
2016-08-24 06:03:55 +00:00
_vm - > _dungeonMan - > setCurrentMap ( _vm - > _dungeonMan - > _partyMapIndex ) ;
2016-07-11 12:33:25 +00:00
}
}
2016-08-25 20:38:03 +00:00
bool Timeline : : isFirstEventExpiered ( ) {
2016-09-11 07:46:35 +00:00
return ( _eventCount & & ( _vm - > filterTime ( _events [ _timeline [ 0 ] ] . _mapTime ) < = _vm - > _gameTime ) ) ;
2016-07-11 12:33:25 +00:00
}
2016-09-07 20:58:18 +00:00
void Timeline : : extractFirstEvent ( TimelineEvent * event ) {
2016-09-07 20:19:10 +00:00
uint16 eventIndex = _timeline [ 0 ] ;
2016-07-11 12:33:25 +00:00
2016-09-07 20:19:10 +00:00
* event = _events [ eventIndex ] ;
deleteEvent ( eventIndex ) ;
2016-07-11 12:33:25 +00:00
}
2016-09-07 20:58:18 +00:00
void Timeline : : processEventDoorAnimation ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-09-08 04:47:56 +00:00
Square * curSquare = ( Square * ) & _vm - > _dungeonMan - > _currMapData [ mapX ] [ mapY ] ;
2016-09-14 19:27:09 +00:00
DoorState doorState = ( DoorState ) ( * curSquare ) . getDoorState ( ) ;
if ( doorState = = kDMDoorStateDestroyed )
2016-07-11 13:38:25 +00:00
return ;
2016-09-07 20:58:18 +00:00
2016-07-11 13:38:25 +00:00
event - > _mapTime + + ;
2016-09-10 19:54:22 +00:00
int16 sensorEffect = event - > _Cu . A . _effect ;
2016-09-11 22:03:48 +00:00
if ( sensorEffect = = kDMSensorEffectClear ) {
2016-09-07 20:58:18 +00:00
Door * curDoor = ( Door * ) _vm - > _dungeonMan - > getSquareFirstThingData ( mapX , mapY ) ;
bool verticalDoorFl = curDoor - > opensVertically ( ) ;
if ( ( _vm - > _dungeonMan - > _currMapIndex = = _vm - > _dungeonMan - > _partyMapIndex ) & & ( mapX = = _vm - > _dungeonMan - > _partyMapX )
2016-09-14 19:27:09 +00:00
& & ( mapY = = _vm - > _dungeonMan - > _partyMapY ) & & ( doorState ! = kDMDoorStateOpen ) ) {
2016-08-23 05:54:16 +00:00
if ( _vm - > _championMan - > _partyChampionCount > 0 ) {
2016-09-14 19:27:09 +00:00
curSquare - > setDoorState ( kDMDoorStateOpen ) ;
2016-07-11 13:38:25 +00:00
// Strangerke
// Original bug fixed - A closing horizontal door wounds champions to the head instead of to the hands. Missing parenthesis in the condition cause all doors to wound the head in addition to the torso
// See BUG0_78
2016-09-09 05:32:32 +00:00
int16 wounds = kDMWoundTorso | ( verticalDoorFl ? kDMWoundHead : kDMWoundReadHand | kDMWoundActionHand ) ;
2016-09-10 12:31:49 +00:00
if ( _vm - > _championMan - > getDamagedChampionCount ( 5 , wounds , kDMAttackTypeSelf ) )
2016-09-18 22:17:36 +00:00
_vm - > _sound - > requestPlay ( kDMSoundIndexPartyDamaged , mapX , mapY , kDMSoundModePlayIfPrioritized ) ;
2016-07-11 13:38:25 +00:00
}
event - > _mapTime + + ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-11 13:38:25 +00:00
return ;
}
2016-09-07 20:58:18 +00:00
Thing groupThing = _vm - > _groupMan - > groupGetThing ( mapX , mapY ) ;
uint16 creatureAttributes = _vm - > _dungeonMan - > getCreatureAttributes ( groupThing ) ;
2016-09-18 09:18:11 +00:00
if ( ( groupThing ! = Thing : : _endOfList ) & & ! getFlag ( creatureAttributes , kDMCreatureMaskNonMaterial ) ) {
2016-09-07 20:58:18 +00:00
if ( doorState > = ( verticalDoorFl ? CreatureInfo : : getHeight ( creatureAttributes ) : 1 ) ) { /* Creature height or 1 */
2016-09-18 20:15:51 +00:00
if ( _vm - > _groupMan - > getDamageAllCreaturesOutcome ( ( Group * ) _vm - > _dungeonMan - > getThingData ( groupThing ) , mapX , mapY , 5 , true ) ! = kDMKillOutcomeAllCreaturesInGroup )
2016-09-20 19:51:42 +00:00
_vm - > _groupMan - > processEvents29to41 ( mapX , mapY , kDMEventTypeCreateReactionDangerOnSquare , 0 ) ;
2016-09-07 20:58:18 +00:00
2016-09-14 19:27:09 +00:00
int16 nextState = doorState - 1 ;
doorState = ( doorState = = kDMDoorStateOpen ) ? kDMDoorStateOpen : ( DoorState ) nextState ;
2016-09-07 20:58:18 +00:00
curSquare - > setDoorState ( doorState ) ;
2016-09-18 22:17:36 +00:00
_vm - > _sound - > requestPlay ( kDMSoundIndexWoodenThudAttackTrolinAntmanStoneGolem , mapX , mapY , kDMSoundModePlayIfPrioritized ) ;
2016-07-11 13:38:25 +00:00
event - > _mapTime + + ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-11 13:38:25 +00:00
return ;
}
}
}
2016-09-14 19:27:09 +00:00
if ( ( sensorEffect = = kDMSensorEffectSet ) & & ( doorState = = kDMDoorStateOpen ) )
2016-09-07 20:58:18 +00:00
return ;
2016-07-23 10:54:25 +00:00
2016-09-14 19:27:09 +00:00
if ( ( sensorEffect = = kDMSensorEffectClear ) & & ( doorState = = kDMDoorStateClosed ) )
2016-09-07 20:58:18 +00:00
return ;
2016-09-14 19:27:09 +00:00
int16 nextDoorEffect = doorState + 1 ;
int16 prevDoorEffect = doorState - 1 ;
doorState = ( DoorState ) ( ( sensorEffect = = kDMSensorEffectSet ) ? prevDoorEffect : nextDoorEffect ) ;
2016-09-07 20:58:18 +00:00
curSquare - > setDoorState ( doorState ) ;
2016-09-18 22:17:36 +00:00
_vm - > _sound - > requestPlay ( kDMSoundIndexDoorRattle , mapX , mapY , kDMSoundModePlayIfPrioritized ) ;
2016-09-07 20:58:18 +00:00
2016-09-11 22:03:48 +00:00
if ( sensorEffect = = kDMSensorEffectSet ) {
2016-09-14 19:27:09 +00:00
if ( doorState = = kDMDoorStateOpen )
2016-07-11 13:38:25 +00:00
return ;
2016-09-14 19:27:09 +00:00
} else if ( doorState = = kDMDoorStateClosed )
2016-09-07 20:58:18 +00:00
return ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-11 13:38:25 +00:00
}
2016-07-11 14:12:12 +00:00
2016-09-07 20:58:18 +00:00
void Timeline : : processEventSquareFakewall ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-09-07 20:58:18 +00:00
byte * curSquare = & _vm - > _dungeonMan - > _currMapData [ mapX ] [ mapY ] ;
2016-09-10 19:54:22 +00:00
int16 effect = event - > _Cu . A . _effect ;
2016-09-11 22:03:48 +00:00
if ( effect = = kDMSensorEffectToggle )
2016-09-13 05:46:38 +00:00
effect = getFlag ( * curSquare , kDMSquareMaskFakeWallOpen ) ? kDMSensorEffectClear : kDMSensorEffectSet ;
2016-07-11 14:12:12 +00:00
2016-09-11 22:03:48 +00:00
if ( effect = = kDMSensorEffectClear ) {
2016-09-07 20:58:18 +00:00
if ( ( _vm - > _dungeonMan - > _currMapIndex = = _vm - > _dungeonMan - > _partyMapIndex ) & & ( mapX = = _vm - > _dungeonMan - > _partyMapX ) & & ( mapY = = _vm - > _dungeonMan - > _partyMapY ) ) {
2016-07-11 14:12:12 +00:00
event - > _mapTime + + ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-11 14:12:12 +00:00
} else {
2016-09-07 20:58:18 +00:00
Thing groupThing = _vm - > _groupMan - > groupGetThing ( mapX , mapY ) ;
2016-09-18 09:18:11 +00:00
if ( ( groupThing ! = Thing : : _endOfList ) & & ! getFlag ( _vm - > _dungeonMan - > getCreatureAttributes ( groupThing ) , kDMCreatureMaskNonMaterial ) ) {
2016-07-11 14:12:12 +00:00
event - > _mapTime + + ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-09-07 20:58:18 +00:00
} else
2016-09-13 05:46:38 +00:00
clearFlag ( * curSquare , kDMSquareMaskFakeWallOpen ) ;
2016-07-11 14:12:12 +00:00
}
2016-09-07 20:58:18 +00:00
} else
2016-09-13 05:46:38 +00:00
setFlag ( * curSquare , kDMSquareMaskFakeWallOpen ) ;
2016-07-11 14:12:12 +00:00
}
2016-07-11 14:15:23 +00:00
2016-09-07 20:58:18 +00:00
void Timeline : : processEventDoorDestruction ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
Square * square = ( Square * ) & _vm - > _dungeonMan - > _currMapData [ event - > _Bu . _location . _mapX ] [ event - > _Bu . _location . _mapY ] ;
2016-09-14 19:27:09 +00:00
square - > setDoorState ( kDMDoorStateDestroyed ) ;
2016-07-11 14:15:23 +00:00
}
2016-07-11 14:18:39 +00:00
2016-09-07 20:58:18 +00:00
void Timeline : : processEventSquareDoor ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
int16 doorState = Square ( _vm - > _dungeonMan - > _currMapData [ event - > _Bu . _location . _mapX ] [ event - > _Bu . _location . _mapY ] ) . getDoorState ( ) ;
2016-09-14 19:27:09 +00:00
if ( doorState = = kDMDoorStateDestroyed )
2016-07-11 14:18:39 +00:00
return ;
2016-09-07 20:58:18 +00:00
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-14 19:27:09 +00:00
event - > _Cu . A . _effect = ( doorState = = kDMDoorStateOpen ) ? kDMSensorEffectClear : kDMSensorEffectSet ;
2016-09-11 22:03:48 +00:00
else if ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) {
2016-09-14 19:27:09 +00:00
if ( ( doorState = = kDMDoorStateOpen ) | | ( doorState = = kDMDoorStateClosed ) )
2016-09-07 20:58:18 +00:00
return ;
2016-07-11 14:18:39 +00:00
}
2016-09-20 19:51:42 +00:00
event - > _type = kDMEventTypeDoorAnimation ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-11 14:18:39 +00:00
}
2016-07-11 14:38:15 +00:00
2016-09-07 20:58:18 +00:00
void Timeline : : processEventSquarePit ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-07-11 14:38:15 +00:00
2016-09-08 05:15:12 +00:00
byte * square = & _vm - > _dungeonMan - > _currMapData [ mapX ] [ mapY ] ;
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-13 05:46:38 +00:00
event - > _Cu . A . _effect = getFlag ( * square , kDMSquareMaskPitOpen ) ? kDMSensorEffectClear : kDMSensorEffectSet ;
2016-07-11 14:38:15 +00:00
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) {
2016-09-13 05:46:38 +00:00
setFlag ( * square , kDMSquareMaskPitOpen ) ;
2016-09-08 05:15:12 +00:00
moveTeleporterOrPitSquareThings ( mapX , mapY ) ;
2016-09-07 20:58:18 +00:00
} else
2016-09-13 05:46:38 +00:00
clearFlag ( * square , kDMSquareMaskPitOpen ) ;
2016-07-11 14:38:15 +00:00
}
2016-08-25 20:38:03 +00:00
void Timeline : : moveTeleporterOrPitSquareThings ( uint16 mapX , uint16 mapY ) {
2016-09-07 21:29:04 +00:00
if ( ( _vm - > _dungeonMan - > _currMapIndex = = _vm - > _dungeonMan - > _partyMapIndex )
& & ( mapX = = _vm - > _dungeonMan - > _partyMapX ) & & ( mapY = = _vm - > _dungeonMan - > _partyMapY ) ) {
2016-08-25 20:09:30 +00:00
_vm - > _moveSens - > getMoveResult ( Thing : : _party , mapX , mapY , mapX , mapY ) ;
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > drawChangedObjectIcons ( ) ;
2016-07-11 14:38:15 +00:00
}
2016-09-07 21:29:04 +00:00
Thing curThing = _vm - > _groupMan - > groupGetThing ( mapX , mapY ) ;
if ( curThing ! = Thing : : _endOfList )
_vm - > _moveSens - > getMoveResult ( curThing , mapX , mapY , mapX , mapY ) ;
curThing = _vm - > _dungeonMan - > getSquareFirstObject ( mapX , mapY ) ;
Thing nextThing = curThing ;
int16 thingsToMoveCount = 0 ;
while ( curThing ! = Thing : : _endOfList ) {
2016-09-10 22:33:54 +00:00
if ( curThing . getType ( ) > kDMThingTypeGroup )
2016-09-07 21:29:04 +00:00
thingsToMoveCount + + ;
curThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
2016-07-11 14:38:15 +00:00
}
2016-09-07 21:29:04 +00:00
curThing = nextThing ;
while ( ( curThing ! = Thing : : _endOfList ) & & thingsToMoveCount ) {
thingsToMoveCount - - ;
nextThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
uint16 curThingType = curThing . getType ( ) ;
2016-09-10 22:33:54 +00:00
if ( curThingType > kDMThingTypeGroup )
2016-09-07 21:29:04 +00:00
_vm - > _moveSens - > getMoveResult ( curThing , mapX , mapY , mapX , mapY ) ;
2016-09-10 22:33:54 +00:00
if ( curThingType = = kDMThingTypeProjectile ) {
2016-09-08 04:47:56 +00:00
Projectile * projectile = ( Projectile * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
TimelineEvent * newEvent ;
2016-09-07 21:29:04 +00:00
newEvent = & _events [ projectile - > _eventIndex ] ;
2016-09-10 19:54:22 +00:00
newEvent - > _Cu . _projectile . setMapX ( _vm - > _moveSens - > _moveResultMapX ) ;
newEvent - > _Cu . _projectile . setMapY ( _vm - > _moveSens - > _moveResultMapY ) ;
newEvent - > _Cu . _projectile . setDir ( ( Direction ) _vm - > _moveSens - > _moveResultDir ) ;
2016-09-11 07:46:35 +00:00
newEvent - > _Bu . _slot = _vm - > thingWithNewCell ( curThing , _vm - > _moveSens - > _moveResultCell ) . toUint16 ( ) ;
2016-09-19 05:05:37 +00:00
_vm - > setMap ( newEvent - > _mapTime , _vm - > _moveSens - > _moveResultMapIndex ) ;
2016-09-10 22:33:54 +00:00
} else if ( curThingType = = kDMThingTypeExplosion ) {
2016-09-07 21:29:04 +00:00
TimelineEvent * newEvent = _events ;
for ( uint16 i = 0 ; i < _eventMaxCount ; newEvent + + , i + + ) {
2016-09-20 19:51:42 +00:00
if ( ( newEvent - > _type = = kDMEventTypeExplosion ) & & ( newEvent - > _Cu . _slot = = curThing . toUint16 ( ) ) ) { /* BUG0_23 A Fluxcage explosion remains on a square forever. If you open a pit or teleporter on a square where there is a Fluxcage explosion, the Fluxcage explosion is moved but the associated event is not updated (because Fluxcage explosions do not use k25_TMEventTypeExplosion but rather k24_TMEventTypeRemoveFluxcage) causing the Fluxcage explosion to remain in the dungeon forever on its destination square. When the k24_TMEventTypeRemoveFluxcage expires the explosion thing is not removed, but it is marked as unused. Consequently, any objects placed on the Fluxcage square after it was moved but before it expires become orphans upon expiration. After expiration, any object placed on the fluxcage square is cloned when picked up */
2016-09-10 19:50:57 +00:00
newEvent - > _Bu . _location . _mapX = _vm - > _moveSens - > _moveResultMapX ;
newEvent - > _Bu . _location . _mapY = _vm - > _moveSens - > _moveResultMapY ;
2016-09-11 07:46:35 +00:00
newEvent - > _Cu . _slot = _vm - > thingWithNewCell ( curThing , _vm - > _moveSens - > _moveResultCell ) . toUint16 ( ) ;
2016-09-19 05:05:37 +00:00
_vm - > setMap ( newEvent - > _mapTime , _vm - > _moveSens - > _moveResultMapIndex ) ;
2016-07-11 14:38:15 +00:00
}
}
}
2016-09-07 21:29:04 +00:00
curThing = nextThing ;
2016-07-11 14:38:15 +00:00
}
}
2016-07-11 14:41:23 +00:00
2016-09-07 21:29:04 +00:00
void Timeline : : processEventSquareTeleporter ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-07-11 14:41:23 +00:00
2016-09-07 21:29:04 +00:00
byte * curSquare = & _vm - > _dungeonMan - > _currMapData [ mapX ] [ mapY ] ;
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-13 05:46:38 +00:00
event - > _Cu . A . _effect = getFlag ( * curSquare , kDMSquareMaskTeleporterOpen ) ? kDMSensorEffectClear : kDMSensorEffectSet ;
2016-07-11 14:41:23 +00:00
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) {
2016-09-13 05:46:38 +00:00
setFlag ( * curSquare , kDMSquareMaskTeleporterOpen ) ;
2016-09-07 21:29:04 +00:00
moveTeleporterOrPitSquareThings ( mapX , mapY ) ;
} else
2016-09-13 05:46:38 +00:00
clearFlag ( * curSquare , kDMSquareMaskTeleporterOpen ) ;
2016-07-11 14:41:23 +00:00
}
2016-07-11 15:06:24 +00:00
2016-09-07 21:29:04 +00:00
void Timeline : : processEventSquareWall ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
int16 mapX = event - > _Bu . _location . _mapX ;
int16 mapY = event - > _Bu . _location . _mapY ;
2016-09-07 21:29:04 +00:00
Thing curThing = _vm - > _dungeonMan - > getSquareFirstThing ( mapX , mapY ) ;
2016-09-10 19:54:22 +00:00
uint16 curCell = event - > _Cu . A . _cell ;
2016-09-07 21:29:04 +00:00
while ( curThing ! = Thing : : _endOfList ) {
int16 curThingType = curThing . getType ( ) ;
2016-09-10 22:33:54 +00:00
if ( ( curThingType = = kDMstringTypeText ) & & ( curThing . getCell ( ) = = event - > _Cu . A . _cell ) ) {
2016-09-08 04:47:56 +00:00
TextString * textString = ( TextString * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-07 21:29:04 +00:00
textString - > setVisible ( ! textString - > isVisible ( ) ) ;
else
2016-09-11 22:03:48 +00:00
textString - > setVisible ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) ;
2016-09-10 22:33:54 +00:00
} else if ( curThingType = = kDMThingTypeSensor ) {
2016-09-08 04:47:56 +00:00
Sensor * curThingSensor = ( Sensor * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
2016-09-07 21:29:04 +00:00
uint16 curSensorType = curThingSensor - > getType ( ) ;
uint16 curSensorData = curThingSensor - > getData ( ) ;
2016-09-11 22:03:48 +00:00
if ( curSensorType = = kDMSensorWallCountdown ) {
2016-09-07 21:29:04 +00:00
if ( curSensorData > 0 ) {
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) {
2016-09-07 21:29:04 +00:00
if ( curSensorData < 511 )
curSensorData + + ;
} else
curSensorData - - ;
curThingSensor - > setData ( curSensorData ) ;
2016-09-11 22:03:48 +00:00
if ( curThingSensor - > getAttrEffectA ( ) = = kDMSensorEffectHold ) {
2016-09-07 21:29:04 +00:00
int16 triggerSetEffect = ( ( curSensorData = = 0 ) ! = curThingSensor - > getAttrRevertEffectA ( ) ) ;
2016-09-11 22:03:48 +00:00
_vm - > _moveSens - > triggerEffect ( curThingSensor , triggerSetEffect ? kDMSensorEffectSet : kDMSensorEffectClear , mapX , mapY , curCell ) ;
2016-09-07 21:29:04 +00:00
} else if ( curSensorData = = 0 )
2016-09-12 19:48:16 +00:00
_vm - > _moveSens - > triggerEffect ( curThingSensor , ( SensorEffect ) curThingSensor - > getAttrEffectA ( ) , mapX , mapY , curCell ) ;
2016-07-11 15:06:24 +00:00
}
2016-09-11 22:03:48 +00:00
} else if ( curSensorType = = kDMSensorWallAndOrGate ) {
2016-09-10 19:54:22 +00:00
int16 bitMask = 1 < < ( event - > _Cu . A . _cell ) ;
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle ) {
2016-09-07 21:29:04 +00:00
if ( getFlag ( curSensorData , bitMask ) )
clearFlag ( curSensorData , bitMask ) ;
else
setFlag ( curSensorData , bitMask ) ;
2016-09-10 19:54:22 +00:00
} else if ( event - > _Cu . A . _effect )
2016-09-07 21:29:04 +00:00
clearFlag ( curSensorData , bitMask ) ;
else
setFlag ( curSensorData , bitMask ) ;
2016-09-10 19:50:57 +00:00
2016-09-07 21:29:04 +00:00
curThingSensor - > setData ( curSensorData ) ;
bool triggerSetEffect = ( Sensor : : getDataMask1 ( curSensorData ) = = Sensor : : getDataMask2 ( curSensorData ) ) ! = curThingSensor - > getAttrRevertEffectA ( ) ;
2016-09-11 22:03:48 +00:00
if ( curThingSensor - > getAttrEffectA ( ) = = kDMSensorEffectHold )
_vm - > _moveSens - > triggerEffect ( curThingSensor , triggerSetEffect ? kDMSensorEffectSet : kDMSensorEffectClear , mapX , mapY , curCell ) ;
2016-09-07 21:29:04 +00:00
else if ( triggerSetEffect )
2016-09-12 19:48:16 +00:00
_vm - > _moveSens - > triggerEffect ( curThingSensor , ( SensorEffect ) curThingSensor - > getAttrEffectA ( ) , mapX , mapY , curCell ) ;
2016-09-11 22:03:48 +00:00
} else if ( ( ( ( curSensorType > = kDMSensorWallSingleProjLauncherNewObj ) & & ( curSensorType < = kDMSensorWallDoubleProjLauncherExplosion ) ) | | ( curSensorType = = kDMSensorWallSingleProjLauncherSquareObj ) | | ( curSensorType = = kDMSensorWallDoubleProjLauncherSquareObj ) ) & & ( curThing . getCell ( ) = = event - > _Cu . A . _cell ) ) {
2016-09-07 21:29:04 +00:00
triggerProjectileLauncher ( curThingSensor , event ) ;
if ( curThingSensor - > getAttrOnlyOnce ( ) )
curThingSensor - > setTypeDisabled ( ) ;
2016-09-11 22:03:48 +00:00
} else if ( curSensorType = = kDMSensorWallEndGame ) {
2016-09-07 21:29:04 +00:00
_vm - > delay ( 60 * curThingSensor - > getAttrValue ( ) ) ;
_vm - > _restartGameAllowed = false ;
_vm - > _gameWon = true ;
_vm - > endGame ( true ) ;
2016-07-11 15:06:24 +00:00
}
}
2016-09-07 21:29:04 +00:00
curThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
2016-07-11 15:06:24 +00:00
}
2016-08-25 20:09:30 +00:00
_vm - > _moveSens - > processRotationEffect ( ) ;
2016-07-11 15:06:24 +00:00
}
2016-09-08 04:47:56 +00:00
void Timeline : : triggerProjectileLauncher ( Sensor * sensor , TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
int16 mapX = event - > _Bu . _location . _mapX ;
int16 mapY = event - > _Bu . _location . _mapY ;
2016-09-10 19:54:22 +00:00
uint16 cell = event - > _Cu . A . _cell ;
2016-09-11 07:46:35 +00:00
uint16 projectileCell = _vm - > returnOppositeDir ( ( Direction ) cell ) ;
2016-09-08 04:47:56 +00:00
int16 sensorType = sensor - > getType ( ) ;
int16 sensorData = sensor - > getData ( ) ;
int16 kineticEnergy = sensor - > getActionKineticEnergy ( ) ;
int16 stepEnergy = sensor - > getActionStepEnergy ( ) ;
2016-09-11 22:03:48 +00:00
bool launchSingleProjectile = ( sensorType = = kDMSensorWallSingleProjLauncherNewObj ) | |
( sensorType = = kDMSensorWallSingleProjLauncherExplosion ) | |
( sensorType = = kDMSensorWallSingleProjLauncherSquareObj ) ;
2016-09-08 04:47:56 +00:00
Thing firstProjectileAssociatedThing ;
Thing secondProjectileAssociatedThing ;
2016-09-11 22:03:48 +00:00
if ( ( sensorType = = kDMSensorWallSingleProjLauncherExplosion ) | | ( sensorType = = kDMSensorWallDoubleProjLauncherExplosion ) )
2016-09-08 04:47:56 +00:00
firstProjectileAssociatedThing = secondProjectileAssociatedThing = Thing ( sensorData + Thing : : _firstExplosion . toUint16 ( ) ) ;
2016-09-11 22:03:48 +00:00
else if ( ( sensorType = = kDMSensorWallSingleProjLauncherSquareObj ) | | ( sensorType = = kDMSensorWallDoubleProjLauncherSquareObj ) ) {
2016-09-08 04:47:56 +00:00
firstProjectileAssociatedThing = _vm - > _dungeonMan - > getSquareFirstThing ( mapX , mapY ) ;
while ( firstProjectileAssociatedThing ! = Thing : : _none ) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList. If there are no more objects on the square then this loop may return an undefined value, this can crash the game. In the original DM and CSB dungeons, the number of times that these sensors are triggered is always controlled to be equal to the number of available objects (with a countdown sensor or a number of once only sensors) */
uint16 projectiveThingCell = firstProjectileAssociatedThing . getCell ( ) ;
2016-09-11 08:45:20 +00:00
if ( ( firstProjectileAssociatedThing . getType ( ) > kDMThingTypeSensor ) & & ( ( projectiveThingCell = = cell ) | | ( projectiveThingCell = = _vm - > turnDirRight ( cell ) ) ) )
2016-09-08 04:47:56 +00:00
break ;
firstProjectileAssociatedThing = _vm - > _dungeonMan - > getNextThing ( firstProjectileAssociatedThing ) ;
}
if ( firstProjectileAssociatedThing = = Thing : : _none ) /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList */
return ;
_vm - > _dungeonMan - > unlinkThingFromList ( firstProjectileAssociatedThing , Thing ( 0 ) , mapX , mapY ) ; /* The object is removed without triggering any sensor effects */
if ( ! launchSingleProjectile ) {
secondProjectileAssociatedThing = _vm - > _dungeonMan - > getSquareFirstThing ( mapX , mapY ) ;
while ( secondProjectileAssociatedThing ! = Thing : : _none ) { /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList. If there are no more objects on the square then this loop may return an undefined value, this can crash the game */
uint16 projectiveThingCell = secondProjectileAssociatedThing . getCell ( ) ;
2016-09-11 08:45:20 +00:00
if ( ( secondProjectileAssociatedThing . getType ( ) > kDMThingTypeSensor ) & & ( ( projectiveThingCell = = cell ) | | ( projectiveThingCell = = _vm - > turnDirRight ( cell ) ) ) )
2016-07-11 15:06:24 +00:00
break ;
2016-09-08 04:47:56 +00:00
secondProjectileAssociatedThing = _vm - > _dungeonMan - > getNextThing ( secondProjectileAssociatedThing ) ;
2016-07-11 15:06:24 +00:00
}
2016-09-08 04:47:56 +00:00
if ( secondProjectileAssociatedThing = = Thing : : _none ) /* BUG0_19 The game crashes when an object launcher sensor is triggered. Thing::_none should be Thing::_endOfList */
launchSingleProjectile = true ;
else
_vm - > _dungeonMan - > unlinkThingFromList ( secondProjectileAssociatedThing , Thing : : _none , mapX , mapY ) ; /* The object is removed without triggering any sensor effects */
2016-07-11 15:06:24 +00:00
}
2016-09-08 04:47:56 +00:00
} else {
firstProjectileAssociatedThing = _vm - > _dungeonMan - > getObjForProjectileLaucherOrObjGen ( sensorData ) ;
if ( ( firstProjectileAssociatedThing ) = = Thing : : _none )
return ;
secondProjectileAssociatedThing = _vm - > _dungeonMan - > getObjForProjectileLaucherOrObjGen ( sensorData ) ;
if ( ! launchSingleProjectile & & ( secondProjectileAssociatedThing = = Thing : : _none ) )
launchSingleProjectile = true ;
2016-07-11 15:06:24 +00:00
}
2016-09-08 04:47:56 +00:00
if ( launchSingleProjectile )
2016-09-11 07:46:35 +00:00
projectileCell = _vm - > normalizeModulo4 ( projectileCell + _vm - > getRandomNumber ( 2 ) ) ;
2016-09-08 04:47:56 +00:00
/* BUG0_20 The game crashes if the launcher sensor is on a map boundary and shoots in a direction outside the map */
mapX + = _vm - > _dirIntoStepCountEast [ cell ] ;
mapY + = _vm - > _dirIntoStepCountNorth [ cell ] ;
2016-08-25 20:19:34 +00:00
_vm - > _projexpl - > _createLauncherProjectile = true ;
2016-09-08 04:47:56 +00:00
_vm - > _projexpl - > createProjectile ( firstProjectileAssociatedThing , mapX , mapY , projectileCell , ( Direction ) cell , kineticEnergy , 100 , stepEnergy ) ;
if ( ! launchSingleProjectile )
2016-09-11 08:45:20 +00:00
_vm - > _projexpl - > createProjectile ( secondProjectileAssociatedThing , mapX , mapY , _vm - > turnDirRight ( projectileCell ) , ( Direction ) cell , kineticEnergy , 100 , stepEnergy ) ;
2016-09-08 04:47:56 +00:00
2016-08-25 20:19:34 +00:00
_vm - > _projexpl - > _createLauncherProjectile = false ;
2016-07-11 15:06:24 +00:00
}
2016-07-12 05:56:59 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : processEventSquareCorridor ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-09-08 04:47:56 +00:00
Thing curThing = _vm - > _dungeonMan - > getSquareFirstThing ( mapX , mapY ) ;
while ( curThing ! = Thing : : _endOfList ) {
int16 curThingType = curThing . getType ( ) ;
2016-09-10 22:33:54 +00:00
if ( curThingType = = kDMstringTypeText ) {
2016-09-08 04:47:56 +00:00
TextString * textString = ( TextString * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
bool textCurrentlyVisible = textString - > isVisible ( ) ;
2016-09-11 22:03:48 +00:00
if ( event - > _Cu . A . _effect = = kDMSensorEffectToggle )
2016-09-08 04:47:56 +00:00
textString - > setVisible ( ! textCurrentlyVisible ) ;
else
2016-09-11 22:03:48 +00:00
textString - > setVisible ( ( event - > _Cu . A . _effect = = kDMSensorEffectSet ) ) ;
2016-09-08 04:47:56 +00:00
if ( ! textCurrentlyVisible & & textString - > isVisible ( ) & & ( _vm - > _dungeonMan - > _currMapIndex = = _vm - > _dungeonMan - > _partyMapIndex ) & & ( mapX = = _vm - > _dungeonMan - > _partyMapX ) & & ( mapY = = _vm - > _dungeonMan - > _partyMapY ) ) {
2016-09-11 21:06:29 +00:00
_vm - > _dungeonMan - > decodeText ( _vm - > _stringBuildBuffer , curThing , kDMTextTypeMessage ) ;
2016-09-16 05:46:10 +00:00
_vm - > _textMan - > printMessage ( kDMColorWhite , _vm - > _stringBuildBuffer ) ;
2016-07-12 05:56:59 +00:00
}
2016-09-10 22:33:54 +00:00
} else if ( curThingType = = kDMThingTypeSensor ) {
2016-09-08 04:47:56 +00:00
Sensor * curSensor = ( Sensor * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
2016-09-11 22:03:48 +00:00
if ( curSensor - > getType ( ) = = kDMSensorFloorGroupGenerator ) {
2016-09-08 04:47:56 +00:00
int16 creatureCount = curSensor - > getAttrValue ( ) ;
2016-09-20 19:51:42 +00:00
if ( getFlag ( creatureCount , kDMMaskRandomizeGeneratedCreatureCount ) )
creatureCount = _vm - > getRandomNumber ( getFlag ( creatureCount , kDMMaskGeneratedCreatureCount ) ) ;
2016-09-08 04:47:56 +00:00
else
creatureCount - - ;
uint16 healthMultiplier = curSensor - > getActionHealthMultiplier ( ) ;
if ( healthMultiplier = = 0 )
healthMultiplier = _vm - > _dungeonMan - > _currMap - > _difficulty ;
2016-09-17 23:02:02 +00:00
_vm - > _groupMan - > groupGetGenerated ( ( CreatureType ) curSensor - > getData ( ) , healthMultiplier , creatureCount , ( Direction ) _vm - > getRandomNumber ( 4 ) , mapX , mapY ) ;
2016-09-08 04:47:56 +00:00
if ( curSensor - > getAttrAudibleA ( ) )
2016-09-18 22:17:36 +00:00
_vm - > _sound - > requestPlay ( kDMSoundIndexBuzz , mapX , mapY , kDMSoundModePlayIfPrioritized ) ;
2016-09-08 04:47:56 +00:00
if ( curSensor - > getAttrOnlyOnce ( ) )
curSensor - > setTypeDisabled ( ) ;
else {
uint16 actionTicks = curSensor - > getActionTicks ( ) ;
if ( actionTicks ! = 0 ) {
curSensor - > setTypeDisabled ( ) ;
if ( actionTicks > 127 )
actionTicks = ( actionTicks - 126 ) < < 6 ;
TimelineEvent newEvent ;
2016-09-20 19:51:42 +00:00
newEvent . _type = kDMEventTypeEnableGroupGenerator ;
2016-09-19 05:05:37 +00:00
newEvent . _mapTime = _vm - > setMapAndTime ( _vm - > _dungeonMan - > _currMapIndex , _vm - > _gameTime + actionTicks ) ;
2016-09-08 04:47:56 +00:00
newEvent . _priority = 0 ;
2016-09-10 19:50:57 +00:00
newEvent . _Bu . _location . _mapX = mapX ;
newEvent . _Bu . _location . _mapY = mapY ;
newEvent . _Bu . _location . _mapY = mapY ;
2016-09-08 04:47:56 +00:00
addEventGetEventIndex ( & newEvent ) ;
2016-07-12 05:56:59 +00:00
}
}
}
}
2016-09-08 04:47:56 +00:00
curThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
2016-07-12 05:56:59 +00:00
}
}
2016-07-12 06:04:06 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : processEventsMoveGroup ( TimelineEvent * event ) {
bool randomDirectionMoveRetried = false ;
2016-09-10 19:50:57 +00:00
uint16 mapX = event - > _Bu . _location . _mapX ;
uint16 mapY = event - > _Bu . _location . _mapY ;
2016-07-12 06:04:06 +00:00
T0252001 :
2016-09-08 04:47:56 +00:00
if ( ( ( _vm - > _dungeonMan - > _currMapIndex ! = _vm - > _dungeonMan - > _partyMapIndex ) | | ( mapX ! = _vm - > _dungeonMan - > _partyMapX ) | | ( mapY ! = _vm - > _dungeonMan - > _partyMapY ) ) & & ( _vm - > _groupMan - > groupGetThing ( mapX , mapY ) = = Thing : : _endOfList ) ) { /* BUG0_24 Lord Chaos may teleport into one of the Black Flames and become invisible until the Black Flame is killed. In this case, _vm->_groupMan->f175_groupGetThing returns the Black Flame thing and the Lord Chaos thing is not moved into the dungeon until the Black Flame is killed */
2016-09-20 19:51:42 +00:00
if ( event - > _type = = kDMEventTypeMoveGroupAudible )
2016-09-18 22:17:36 +00:00
_vm - > _sound - > requestPlay ( kDMSoundIndexBuzz , mapX , mapY , kDMSoundModePlayIfPrioritized ) ;
2016-09-08 04:47:56 +00:00
2016-09-11 19:22:22 +00:00
_vm - > _moveSens - > getMoveResult ( Thing ( event - > _Cu . _slot ) , kDMMapXNotOnASquare , 0 , mapX , mapY ) ;
2016-07-12 06:04:06 +00:00
} else {
2016-09-08 04:47:56 +00:00
if ( ! randomDirectionMoveRetried ) {
randomDirectionMoveRetried = true ;
2016-09-10 19:54:22 +00:00
Group * group = ( Group * ) _vm - > _dungeonMan - > getThingData ( Thing ( event - > _Cu . _slot ) ) ;
2016-09-17 13:13:20 +00:00
if ( ( group - > _type = = kDMCreatureTypeLordChaos ) & & ! _vm - > getRandomNumber ( 4 ) ) {
2016-07-12 06:04:06 +00:00
switch ( _vm - > getRandomNumber ( 4 ) ) {
case 0 :
2016-09-08 04:47:56 +00:00
mapX - - ;
2016-07-12 06:04:06 +00:00
break ;
case 1 :
2016-09-08 04:47:56 +00:00
mapX + + ;
2016-07-12 06:04:06 +00:00
break ;
case 2 :
2016-09-08 04:47:56 +00:00
mapY - - ;
2016-07-12 06:04:06 +00:00
break ;
case 3 :
2016-09-08 04:47:56 +00:00
mapY + + ;
2016-07-12 06:04:06 +00:00
}
2016-09-08 04:47:56 +00:00
if ( _vm - > _groupMan - > isSquareACorridorTeleporterPitOrDoor ( mapX , mapY ) )
2016-07-12 06:04:06 +00:00
goto T0252001 ;
}
}
event - > _mapTime + = 5 ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-12 06:04:06 +00:00
}
}
2016-07-12 06:08:57 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : procesEventEnableGroupGenerator ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
Thing curThing = _vm - > _dungeonMan - > getSquareFirstThing ( event - > _Bu . _location . _mapX , event - > _Bu . _location . _mapY ) ;
2016-09-08 05:15:12 +00:00
while ( curThing ! = Thing : : _none ) {
2016-09-10 22:33:54 +00:00
if ( ( curThing . getType ( ) ) = = kDMThingTypeSensor ) {
2016-09-08 05:15:12 +00:00
Sensor * curSensor = ( Sensor * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
2016-09-11 22:03:48 +00:00
if ( curSensor - > getType ( ) = = kDMSensorDisabled ) {
curSensor - > setDatAndTypeWithOr ( kDMSensorFloorGroupGenerator ) ;
2016-07-12 06:08:57 +00:00
return ;
}
}
2016-09-08 05:15:12 +00:00
curThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
2016-07-12 06:08:57 +00:00
}
}
2016-07-12 06:18:25 +00:00
2016-08-25 20:38:03 +00:00
void Timeline : : processEventEnableChampionAction ( uint16 champIndex ) {
2016-09-08 05:15:12 +00:00
Champion * curChampion = & _vm - > _championMan - > _champions [ champIndex ] ;
curChampion - > _enableActionEventIndex = - 1 ;
2016-09-09 05:32:32 +00:00
clearFlag ( curChampion - > _attributes , kDMAttributeDisableAction ) ;
2016-09-10 12:31:49 +00:00
if ( curChampion - > _actionIndex ! = kDMActionNone ) {
2016-09-08 05:15:12 +00:00
curChampion - > _actionDefense - = _actionDefense [ curChampion - > _actionDefense ] ;
2016-07-12 06:18:25 +00:00
}
2016-09-08 05:15:12 +00:00
if ( curChampion - > _currHealth ) {
2016-09-10 12:31:49 +00:00
if ( ( curChampion - > _actionIndex = = kDMActionShoot ) & & ( curChampion - > _slots [ kDMSlotReadyHand ] = = Thing : : _none ) ) {
2016-09-10 09:47:36 +00:00
int16 slotIndex = kDMSlotQuiverLine1_1 ;
if ( _vm - > _championMan - > isAmmunitionCompatibleWithWeapon ( champIndex , kDMSlotActionHand , slotIndex ) )
_vm - > _championMan - > addObjectInSlot ( ( ChampionIndex ) champIndex , _vm - > _championMan - > getObjectRemovedFromSlot ( champIndex , slotIndex ) , kDMSlotReadyHand ) ;
2016-09-08 05:15:12 +00:00
else {
for ( int16 quiverSlotIndex = 0 ; quiverSlotIndex < 3 ; quiverSlotIndex + + ) {
2016-09-10 09:47:36 +00:00
slotIndex = quiverSlotIndex + kDMSlotQuiverLine2_1 ;
if ( _vm - > _championMan - > isAmmunitionCompatibleWithWeapon ( champIndex , kDMSlotActionHand , slotIndex ) )
_vm - > _championMan - > addObjectInSlot ( ( ChampionIndex ) champIndex , _vm - > _championMan - > getObjectRemovedFromSlot ( champIndex , slotIndex ) , kDMSlotReadyHand ) ;
2016-07-12 06:18:25 +00:00
}
}
}
2016-09-09 05:32:32 +00:00
setFlag ( curChampion - > _attributes , kDMAttributeActionHand ) ;
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > drawChampionState ( ( ChampionIndex ) champIndex ) ;
2016-07-12 06:18:25 +00:00
}
2016-09-10 12:31:49 +00:00
curChampion - > _actionIndex = kDMActionNone ;
2016-07-12 06:18:25 +00:00
}
2016-07-12 06:27:57 +00:00
2016-08-25 20:38:03 +00:00
void Timeline : : processEventMoveWeaponFromQuiverToSlot ( uint16 champIndex , uint16 slotIndex ) {
2016-09-08 05:15:12 +00:00
Champion * curChampion = & _vm - > _championMan - > _champions [ champIndex ] ;
if ( curChampion - > _slots [ slotIndex ] ! = Thing : : _none )
2016-07-12 06:27:57 +00:00
return ;
2016-09-08 05:15:12 +00:00
2016-09-10 09:47:36 +00:00
if ( hasWeaponMovedSlot ( champIndex , curChampion , kDMSlotQuiverLine1_1 , slotIndex ) )
2016-07-12 06:27:57 +00:00
return ;
2016-09-08 05:15:12 +00:00
2016-09-10 09:47:36 +00:00
for ( uint16 srcSlotIndex = kDMSlotQuiverLine2_1 ; srcSlotIndex < = kDMSlotQuiverLine2_2 ; srcSlotIndex + + ) {
2016-09-08 05:15:12 +00:00
if ( hasWeaponMovedSlot ( champIndex , curChampion , srcSlotIndex , slotIndex ) )
2016-07-12 06:27:57 +00:00
break ;
}
}
2016-09-08 04:47:56 +00:00
bool Timeline : : hasWeaponMovedSlot ( int16 champIndex , Champion * champ , uint16 sourceSlotIndex , int16 destSlotIndex ) {
2016-09-10 22:33:54 +00:00
if ( Thing ( champ - > _slots [ sourceSlotIndex ] ) . getType ( ) = = kDMThingTypeWeapon ) {
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > addObjectInSlot ( ( ChampionIndex ) champIndex , _vm - > _championMan - > getObjectRemovedFromSlot ( champIndex , sourceSlotIndex ) ,
2016-07-12 06:31:10 +00:00
( ChampionSlot ) destSlotIndex ) ;
2016-07-12 06:27:57 +00:00
return true ;
}
return false ;
}
2016-07-12 06:31:10 +00:00
2016-08-25 20:38:03 +00:00
void Timeline : : processEventHideDamageReceived ( uint16 champIndex ) {
2016-09-08 05:15:12 +00:00
Champion * curChampion = & _vm - > _championMan - > _champions [ champIndex ] ;
curChampion - > _hideDamageReceivedIndex = - 1 ;
if ( ! curChampion - > _currHealth )
2016-07-12 06:31:10 +00:00
return ;
2016-09-08 05:15:12 +00:00
2016-08-25 19:25:18 +00:00
if ( _vm - > indexToOrdinal ( champIndex ) = = _vm - > _inventoryMan - > _inventoryChampionOrdinal ) {
2016-08-25 06:12:23 +00:00
_vm - > _eventMan - > showMouse ( ) ;
2016-08-25 19:25:18 +00:00
_vm - > _inventoryMan - > drawStatusBoxPortrait ( ( ChampionIndex ) champIndex ) ;
2016-08-25 06:12:23 +00:00
_vm - > _eventMan - > hideMouse ( ) ;
2016-07-12 06:31:10 +00:00
} else {
2016-09-09 05:32:32 +00:00
setFlag ( curChampion - > _attributes , kDMAttributeNameTitle ) ;
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > drawChampionState ( ( ChampionIndex ) champIndex ) ;
2016-07-12 06:31:10 +00:00
}
}
2016-07-12 06:33:45 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : processEventLight ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
int16 lightPower = event - > _Bu . _lightPower ;
2016-09-08 05:15:12 +00:00
if ( lightPower = = 0 )
2016-07-12 06:33:45 +00:00
return ;
2016-08-22 22:31:34 +00:00
2016-09-08 05:15:12 +00:00
bool negativeLightPower = ( lightPower < 0 ) ;
if ( negativeLightPower )
lightPower = - lightPower ;
2016-08-22 22:31:34 +00:00
2016-09-08 05:15:12 +00:00
int16 weakerLightPower = lightPower - 1 ;
int16 lightAmount = _vm - > _championMan - > _lightPowerToLightAmount [ lightPower ] - _vm - > _championMan - > _lightPowerToLightAmount [ weakerLightPower ] ;
if ( negativeLightPower ) {
lightAmount = - lightAmount ;
weakerLightPower = - weakerLightPower ;
2016-07-12 06:33:45 +00:00
}
2016-09-08 05:15:12 +00:00
_vm - > _championMan - > _party . _magicalLightAmount + = lightAmount ;
if ( weakerLightPower ) {
TimelineEvent newEvent ;
2016-09-20 19:51:42 +00:00
newEvent . _type = kDMEventTypeLight ;
2016-09-10 19:50:57 +00:00
newEvent . _Bu . _lightPower = weakerLightPower ;
2016-09-19 05:05:37 +00:00
newEvent . _mapTime = _vm - > setMapAndTime ( _vm - > _dungeonMan - > _partyMapIndex , _vm - > _gameTime + 4 ) ;
2016-09-08 05:15:12 +00:00
newEvent . _priority = 0 ;
addEventGetEventIndex ( & newEvent ) ;
2016-07-12 06:33:45 +00:00
}
}
2016-07-12 06:36:53 +00:00
2016-08-25 20:38:03 +00:00
void Timeline : : refreshAllChampionStatusBoxes ( ) {
2016-09-09 05:12:36 +00:00
for ( uint16 idx = kDMChampionFirst ; idx < _vm - > _championMan - > _partyChampionCount ; idx + + )
2016-09-09 05:32:32 +00:00
setFlag ( _vm - > _championMan - > _champions [ idx ] . _attributes , kDMAttributeStatusBox ) ;
2016-07-12 06:36:53 +00:00
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > drawAllChampionStates ( ) ;
2016-07-12 06:36:53 +00:00
}
2016-07-12 06:44:15 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : processEventViAltarRebirth ( TimelineEvent * event ) {
2016-09-10 19:50:57 +00:00
int16 mapX = event - > _Bu . _location . _mapX ;
int16 mapY = event - > _Bu . _location . _mapY ;
2016-09-10 19:54:22 +00:00
uint16 cell = event - > _Cu . A . _cell ;
2016-09-08 05:15:12 +00:00
uint16 championIndex = event - > _priority ;
2016-09-10 19:54:22 +00:00
uint16 rebirthStep = event - > _Cu . A . _effect ;
2016-09-08 05:15:12 +00:00
switch ( rebirthStep ) { /* Rebirth is a 3 steps process (Step 2 -> Step 1 -> Step 0). Step is stored in the Effect value of the event */
2016-07-12 06:44:15 +00:00
case 2 :
2016-09-08 05:15:12 +00:00
_vm - > _projexpl - > createExplosion ( Thing : : _explRebirthStep1 , 0 , mapX , mapY , cell ) ;
2016-07-12 06:44:15 +00:00
event - > _mapTime + = 5 ;
T0255002 :
2016-09-08 05:15:12 +00:00
rebirthStep - - ;
2016-09-10 19:54:22 +00:00
event - > _Cu . A . _effect = rebirthStep ;
2016-08-25 20:38:03 +00:00
addEventGetEventIndex ( event ) ;
2016-07-12 06:44:15 +00:00
break ;
2016-09-08 05:15:12 +00:00
case 1 : {
Thing curThing = _vm - > _dungeonMan - > getSquareFirstThing ( mapX , mapY ) ;
while ( curThing ! = Thing : : _endOfList ) {
2016-09-10 22:33:54 +00:00
if ( ( curThing . getCell ( ) = = cell ) & & ( curThing . getType ( ) = = kDMThingTypeJunk ) ) {
2016-09-08 05:15:12 +00:00
int16 iconIndex = _vm - > _objectMan - > getIconIndex ( curThing ) ;
2016-09-08 23:09:25 +00:00
if ( iconIndex = = kDMIconIndiceJunkChampionBones ) {
2016-09-08 05:15:12 +00:00
Junk * junkData = ( Junk * ) _vm - > _dungeonMan - > getThingData ( curThing ) ;
if ( junkData - > getChargeCount ( ) = = championIndex ) {
_vm - > _dungeonMan - > unlinkThingFromList ( curThing , Thing ( 0 ) , mapX , mapY ) ; /* BUG0_25 When a champion dies, no bones object is created so it is not possible to bring the champion back to life at an altar of Vi. Each time a champion is brought back to life, the bones object is removed from the dungeon but it is not marked as unused and thus becomes an orphan. After a large number of champion deaths, all JUNK things are exhausted and the game cannot create any more. This also affects the creation of JUNK things dropped by some creatures when they die (Screamer, Rockpile, Magenta Worm, Pain Rat, Red Dragon) */
junkData - > setNextThing ( Thing : : _none ) ;
2016-07-12 06:44:15 +00:00
event - > _mapTime + = 1 ;
goto T0255002 ;
}
}
}
2016-09-08 05:15:12 +00:00
curThing = _vm - > _dungeonMan - > getNextThing ( curThing ) ;
}
2016-07-12 06:44:15 +00:00
}
break ;
case 0 :
2016-08-23 05:54:16 +00:00
_vm - > _championMan - > viAltarRebirth ( event - > _priority ) ;
2016-07-12 06:44:15 +00:00
}
}
2016-07-19 16:04:14 +00:00
2016-09-08 04:47:56 +00:00
void Timeline : : saveEventsPart ( Common : : OutSaveFile * file ) {
2016-08-25 20:38:03 +00:00
for ( uint16 i = 0 ; i < _eventMaxCount ; + + i ) {
TimelineEvent * event = & _events [ i ] ;
2016-07-19 16:04:14 +00:00
file - > writeSint32BE ( event - > _mapTime ) ;
file - > writeByte ( event - > _type ) ;
file - > writeByte ( event - > _priority ) ;
2016-09-10 19:50:57 +00:00
file - > writeByte ( event - > _Bu . _location . _mapX ) ; // writing bytes of the union I think should preserve the union's identity
file - > writeByte ( event - > _Bu . _location . _mapY ) ;
2016-09-10 19:54:22 +00:00
file - > writeUint16BE ( event - > _Cu . A . _cell ) ; // writing bytes of the union I think should preserve the union's identity
file - > writeUint16BE ( event - > _Cu . A . _effect ) ;
2016-07-19 16:04:14 +00:00
}
}
2016-09-08 04:47:56 +00:00
void Timeline : : saveTimelinePart ( Common : : OutSaveFile * file ) {
2016-08-25 20:38:03 +00:00
for ( uint16 i = 0 ; i < _eventMaxCount ; + + i )
file - > writeUint16BE ( _timeline [ i ] ) ;
2016-07-19 16:04:14 +00:00
}
2016-09-08 04:47:56 +00:00
void Timeline : : loadEventsPart ( Common : : InSaveFile * file ) {
2016-08-25 20:38:03 +00:00
for ( uint16 i = 0 ; i < _eventMaxCount ; + + i ) {
TimelineEvent * event = & _events [ i ] ;
2016-07-22 19:33:45 +00:00
event - > _mapTime = file - > readSint32BE ( ) ;
2016-09-20 20:26:00 +00:00
event - > _type = ( TimelineEventType ) file - > readByte ( ) ;
2016-07-22 19:33:45 +00:00
event - > _priority = file - > readByte ( ) ;
2016-09-10 19:50:57 +00:00
event - > _Bu . _location . _mapX = file - > readByte ( ) ;
event - > _Bu . _location . _mapY = file - > readByte ( ) ;
2016-09-10 19:54:22 +00:00
event - > _Cu . A . _cell = file - > readUint16BE ( ) ;
event - > _Cu . A . _effect = file - > readUint16BE ( ) ;
2016-07-22 19:33:45 +00:00
}
}
2016-09-08 04:47:56 +00:00
void Timeline : : loadTimelinePart ( Common : : InSaveFile * file ) {
2016-08-25 20:38:03 +00:00
for ( uint16 i = 0 ; i < _eventMaxCount ; + + i )
_timeline [ i ] = file - > readUint16BE ( ) ;
2016-07-22 19:33:45 +00:00
}
2016-06-30 17:59:35 +00:00
}