Skip to content

Commit 2af1b4d

Browse files
committed
Implements "Mission Timer Less Than", "Mission Timer Greater Than", and "Mission Timer Equals" trigger events.
1 parent 965f898 commit 2af1b4d

5 files changed

Lines changed: 203 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*******************************************************************************
2+
/* O P E N S O U R C E -- V I N I F E R A **
3+
/*******************************************************************************
4+
*
5+
* @project Vinifera
6+
*
7+
* @file LOGICEXT_HOOKS.CPP
8+
*
9+
* @author CCHyper
10+
*
11+
* @brief Contains the hooks for the extended LogicClass.
12+
*
13+
* @license Vinifera is free software: you can redistribute it and/or
14+
* modify it under the terms of the GNU General Public License
15+
* as published by the Free Software Foundation, either version
16+
* 3 of the License, or (at your option) any later version.
17+
*
18+
* Vinifera is distributed in the hope that it will be
19+
* useful, but WITHOUT ANY WARRANTY; without even the implied
20+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21+
* PURPOSE. See the GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public
24+
* License along with this program.
25+
* If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
******************************************************************************/
28+
#include "logicext_hooks.h"
29+
#include "logic.h"
30+
#include "fatal.h"
31+
#include "tibsun_globals.h"
32+
#include "vinifera_defines.h"
33+
#include "tag.h"
34+
#include "scenario.h"
35+
#include "debughandler.h"
36+
#include "asserthandler.h"
37+
38+
#include "hooker.h"
39+
#include "hooker_macros.h"
40+
41+
42+
/**
43+
* x
44+
*
45+
* @author: CCHyper
46+
*/
47+
static bool Logic_LogicTriggers_Spring(TagClass *tag)
48+
{
49+
if (!tag) {
50+
return false;
51+
}
52+
53+
/**
54+
* Mission timer state queries.
55+
*/
56+
if (!Scen->MissionTimer.Expired()) {
57+
if (tag->Spring(TEventType(TEVENT_MISSION_TIMER_LESS_THAN))) return true;
58+
59+
if (tag->Spring(TEventType(TEVENT_MISSION_TIMER_GREATER_THAN))) return true;
60+
61+
if (tag->Spring(TEventType(TEVENT_MISSION_TIMER_EQUALS))) return true;
62+
}
63+
64+
return false;
65+
}
66+
67+
68+
/**
69+
* x
70+
*/
71+
DECLARE_PATCH(_LogicClass_AI_LogicTriggers_Loop_Patch)
72+
{
73+
GET_REGISTER(TagClass *, tag, esi);
74+
75+
/**
76+
* Spring any new events. If one is sucessfully sprung, the loop will "continue".
77+
*/
78+
if (Logic_LogicTriggers_Spring(tag)) {
79+
goto continue_loop;
80+
}
81+
82+
/**
83+
* Stolen bytes/code.
84+
*/
85+
JMP_REG(ecx, 0x00506C1E);
86+
87+
continue_loop:
88+
JMP_REG(ecx, 0x00506C5E);
89+
}
90+
91+
92+
/**
93+
* Main function for patching the hooks.
94+
*/
95+
void LogicClassExtension_Hooks()
96+
{
97+
Patch_Jump(0x00506C18, &_LogicClass_AI_LogicTriggers_Loop_Patch);
98+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*******************************************************************************
2+
/* O P E N S O U R C E -- V I N I F E R A **
3+
/*******************************************************************************
4+
*
5+
* @project Vinifera
6+
*
7+
* @file LOGICEXT_HOOKS.H
8+
*
9+
* @author CCHyper
10+
*
11+
* @brief Contains the hooks for the extended LogicClass.
12+
*
13+
* @license Vinifera is free software: you can redistribute it and/or
14+
* modify it under the terms of the GNU General Public License
15+
* as published by the Free Software Foundation, either version
16+
* 3 of the License, or (at your option) any later version.
17+
*
18+
* Vinifera is distributed in the hope that it will be
19+
* useful, but WITHOUT ANY WARRANTY; without even the implied
20+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21+
* PURPOSE. See the GNU General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU General Public
24+
* License along with this program.
25+
* If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
******************************************************************************/
28+
#pragma once
29+
30+
31+
void LogicClassExtension_Hooks();

src/extensions/tevent/teventext.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include "house.h"
3131
#include "techno.h"
3232
#include "technotype.h"
33+
#include "tibsun_globals.h"
3334
#include "vinifera_defines.h"
35+
#include "scenario.h"
3436
#include "wwcrc.h"
3537
#include "asserthandler.h"
3638
#include "debughandler.h"
@@ -207,6 +209,12 @@ const char *TEventClassExtension::Event_Name(int action)
207209
return "Destroyed, Infantry, All...";
208210
case TEVENT_CONSTRUCTION_YARD:
209211
return "Construction yard exists";
212+
case TEVENT_MISSION_TIMER_LESS_THAN:
213+
return "Mission Timer Less Than";
214+
case TEVENT_MISSION_TIMER_GREATER_THAN:
215+
return "Mission Timer Greater Than";
216+
case TEVENT_MISSION_TIMER_EQUALS:
217+
return "Mission Timer Equals";
210218
default:
211219
return "<invalid>";
212220
}
@@ -253,6 +261,12 @@ const char *TEventClassExtension::Event_Description(int action)
253261
return "Triggers when all infantry of the specified side have been destroyed. Typically used for end of game conditions.";
254262
case TEVENT_CONSTRUCTION_YARD:
255263
return "Triggers if the specified house has one or more construction yards.";
264+
case TEVENT_MISSION_TIMER_LESS_THAN:
265+
return "Triggers when the mission timer drops below the time value specified.";
266+
case TEVENT_MISSION_TIMER_GREATER_THAN:
267+
return "Triggers when the mission timer is above the time value specified.";
268+
case TEVENT_MISSION_TIMER_EQUALS:
269+
return "Triggers when the mission timer equals time value specified.";
256270
default:
257271
return "<invalid>";
258272
}
@@ -331,6 +345,15 @@ bool TEventClassExtension::Satisfied(TEventClass *this_ptr, TEventType event, Ho
331345
case TEVENT_INFANTRY_DESTROYED:
332346
success = Infantry_Destroyed(this_ptr, event, house, object, td, tripped, source);
333347
break;
348+
case TEVENT_MISSION_TIMER_LESS_THAN:
349+
success = Mission_Timer_Less_Than(this_ptr, event, house, object, td, tripped, source);
350+
break;
351+
case TEVENT_MISSION_TIMER_GREATER_THAN:
352+
success = Mission_Timer_Greater_Than(this_ptr, event, house, object, td, tripped, source);
353+
break;
354+
case TEVENT_MISSION_TIMER_EQUALS:
355+
success = Mission_Timer_Equal_To(this_ptr, event, house, object, td, tripped, source);
356+
break;
334357

335358
/**
336359
* Unexpected TEventType.
@@ -682,3 +705,48 @@ bool TEventClassExtension::House_Has_Construction_Yard(TEventClass *this_ptr, TE
682705

683706
return false;
684707
}
708+
709+
710+
/**
711+
* Evaluation function for "TEVENT_MISSION_TIMER_LESS_THAN".
712+
*
713+
* @author: CCHyper
714+
*/
715+
bool TEventClassExtension::Mission_Timer_Less_Than(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source)
716+
{
717+
if (Scen->MissionTimer.Is_Active() && Scen->MissionTimer <= this_ptr->Data.Value) {
718+
return true;
719+
}
720+
721+
return false;
722+
}
723+
724+
725+
/**
726+
* Evaluation function for "TEVENT_MISSION_TIMER_GREATER_THAN".
727+
*
728+
* @author: CCHyper
729+
*/
730+
bool TEventClassExtension::Mission_Timer_Greater_Than(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source)
731+
{
732+
if (Scen->MissionTimer.Is_Active() && Scen->MissionTimer >= this_ptr->Data.Value) {
733+
return true;
734+
}
735+
736+
return false;
737+
}
738+
739+
740+
/**
741+
* Evaluation function for "TEVENT_MISSION_TIMER_EQUALS".
742+
*
743+
* @author: CCHyper
744+
*/
745+
bool TEventClassExtension::Mission_Timer_Equal_To(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source)
746+
{
747+
if (Scen->MissionTimer.Is_Active() && Scen->MissionTimer == this_ptr->Data.Value) {
748+
return true;
749+
}
750+
751+
return false;
752+
}

src/extensions/tevent/teventext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ TEventClassExtension final : public AbstractClassExtension
9292
static bool Power_Greater_Than(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
9393
static bool Infantry_Destroyed(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
9494
static bool House_Has_Construction_Yard(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
95+
static bool Mission_Timer_Less_Than(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
96+
static bool Mission_Timer_Greater_Than(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
97+
static bool Mission_Timer_Equal_To(TEventClass *this_ptr, TEventType event, HouseClass *house, const ObjectClass *object, TDEventClass &td, bool &tripped, TechnoClass *source);
9598
};

src/vinifera/vinifera_defines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ typedef enum ExtTEventType
186186
TEVENT_POWER_GREATER_THAN,
187187
TEVENT_INFANTRY_DESTROYED,
188188
TEVENT_CONSTRUCTION_YARD,
189+
TEVENT_MISSION_TIMER_LESS_THAN,
190+
TEVENT_MISSION_TIMER_GREATER_THAN,
191+
TEVENT_MISSION_TIMER_EQUALS,
189192

190193
/**
191194
* The new total ExtTEventType count.

0 commit comments

Comments
 (0)