@@ -33,14 +33,15 @@ void TEventExt::ExtData::SaveToStream(PhobosStreamWriter& Stm)
33
33
this ->Serialize (Stm);
34
34
}
35
35
36
- bool TEventExt::Execute (TEventClass* pThis, int iEvent, HouseClass* pHouse, ObjectClass* pObject ,
37
- CDTimerClass* pTimer, bool * isPersitant, TechnoClass* pSource, bool & bHandled )
36
+ std::optional< bool > TEventExt::Execute (TEventClass* pThis, int iEvent, HouseClass* pHouse,
37
+ ObjectClass* pObject, CDTimerClass* pTimer, bool * isPersitant, TechnoClass* pSource)
38
38
{
39
- bHandled = true ;
40
39
const auto eventKind = static_cast <PhobosTriggerEvent>(pThis->EventKind );
41
40
42
41
switch (eventKind)
43
42
{
43
+ // The triggering conditions that need to be checked at any time are written here
44
+
44
45
// helper struct
45
46
struct and_with { bool operator ()(int a, int b) { return a & b; } };
46
47
@@ -128,30 +129,23 @@ bool TEventExt::Execute(TEventClass* pThis, int iEvent, HouseClass* pHouse, Obje
128
129
case PhobosTriggerEvent::CellHasAnyTechnoTypeFromList:
129
130
return TEventExt::CellHasAnyTechnoTypeFromListTEvent (pThis, pObject, pHouse);
130
131
132
+
131
133
// If it requires an additional object as like mapping events 7 or 48, please fill it in here.
134
+
135
+ // They must be the same, but for other triggers to take effect normally, this cannot be judged outside case.
136
+ auto isSameEvent = [&]() { return eventKind == static_cast <PhobosTriggerEvent>(iEvent); };
137
+
138
+ // SomeTriggerAttachedToObject needs to be restricted to situations where ...
132
139
// case PhobosTriggerEvent::SomeTriggerAttachedToObject:
133
- case PhobosTriggerEvent::ShieldBroken:
134
- // They must be the same.
135
- if (eventKind == static_cast <PhobosTriggerEvent>(iEvent))
136
- {
137
- switch (eventKind)
138
- {
139
- // SomeTriggerAttachedToObject needs to be restricted to situations where ...
140
- // case PhobosTriggerEvent::SomeTriggerAttachedToObject:
141
- // return ...::ThisAttachedToObjectTEvent(pObject, ...);
140
+ // return isSameEvent() && ...::ThisAttachedToObjectTEvent(pObject, ...);
142
141
143
- // ShieldBroken needs to be restricted to situations where the shield is being attacked.
144
- case PhobosTriggerEvent::ShieldBroken:
145
- return ShieldClass::ShieldIsBrokenTEvent (pObject);
142
+ // ShieldBroken needs to be restricted to situations where the shield is being attacked.
143
+ case PhobosTriggerEvent::ShieldBroken:
144
+ return isSameEvent () && ShieldClass::ShieldIsBrokenTEvent (pObject);
146
145
147
- default :
148
- break ;
149
- }
150
- }
151
146
152
147
default :
153
- bHandled = false ;
154
- return true ;
148
+ return std::nullopt;
155
149
};
156
150
}
157
151
0 commit comments