Skip to content

Commit b69fcde

Browse files
committed
xBehaveMgr work
1 parent ecbed9c commit b69fcde

File tree

2 files changed

+157
-4
lines changed

2 files changed

+157
-4
lines changed

src/SB/Core/x/xBehaveMgr.cpp

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,11 @@ void xPsyche::Amnesia(S32 i)
209209
while (g != NULL)
210210
{
211211
xGoal* thisg = g;
212-
g = g->Next();
213-
// this->goallist = this->goallist->Next();
212+
g = thisg->Next();
214213

215-
if (i == 0 && this->GIDInStack(thisg->GetID()) != NULL)
214+
if ((i != 0) || (this->GIDInStack(thisg->GetID()) == 0))
216215
{
217-
continue;
216+
thisg->Clear();
218217
}
219218
}
220219
}
@@ -238,3 +237,145 @@ S32 xPsyche::IndexInStack(S32 gid) const
238237

239238
return da_idx;
240239
}
240+
241+
S32 xPsyche::GoalPopToBase(S32 overpend)
242+
{
243+
if (this->flg_psyche & 4)
244+
{
245+
return 0;
246+
}
247+
else if (this->staktop < 1)
248+
{
249+
return 0;
250+
}
251+
else
252+
{
253+
xPsyche::GoalPop(this->goalstak[0]->GetID(), overpend);
254+
if ((this->pendtype != PEND_TRAN_NONE) && ((this->flg_psyche & 1)))
255+
{
256+
this->ForceTran(0.01f, NULL);
257+
258+
}
259+
return 1;
260+
}
261+
}
262+
263+
xGoal* xPsyche::GetCurGoal() const
264+
{
265+
if (this->staktop < 0)
266+
{
267+
return NULL;
268+
}
269+
else
270+
{
271+
return this->goalstak[this->staktop];
272+
}
273+
}
274+
275+
S32 xPsyche::GIDOfActive() const
276+
{
277+
if (this->staktop < 0)
278+
{
279+
return 0;
280+
}
281+
else
282+
{
283+
return this->goalstak[this->staktop]->GetID();
284+
}
285+
}
286+
287+
S32 xPsyche::GIDOfPending() const
288+
{
289+
if (this->pendgoal != 0)
290+
{
291+
return this->pendgoal->GetID();
292+
}
293+
else
294+
{
295+
return 0;
296+
}
297+
}
298+
299+
xGoal* xPsyche::GetPrevRecovery(S32 gid)
300+
{
301+
S32 idx_start = -1;
302+
S32 i;
303+
xGoal* recgoal = NULL;
304+
xGoal* tmpgoal = NULL;
305+
306+
if (gid == 0)
307+
{
308+
for (idx_start = this->staktop; idx_start >= 0; idx_start--)
309+
{
310+
tmpgoal = this->goalstak[idx_start];
311+
if (tmpgoal->GetFlags() & 8)
312+
{
313+
recgoal = tmpgoal;
314+
break;
315+
}
316+
}
317+
}
318+
else
319+
{
320+
for (i = this->staktop; i >= 0; i--)
321+
{
322+
if (gid == this->goalstak[i]->GetID())
323+
{
324+
idx_start = i - 1;
325+
break;
326+
}
327+
}
328+
if (idx_start > 0)
329+
{
330+
for (S32 i = idx_start; i >= 0; i--)
331+
{
332+
tmpgoal = this->goalstak[i];
333+
if (tmpgoal->GetFlags() & 8)
334+
{
335+
recgoal = tmpgoal;
336+
break;
337+
}
338+
}
339+
}
340+
}
341+
return recgoal;
342+
}
343+
344+
void xPsyche::SetTopState(en_GOALSTATE state)
345+
{
346+
if (this->staktop >= 0)
347+
{
348+
this->goalstak[this->staktop]->SetState(state);
349+
}
350+
}
351+
352+
F32 xPsyche::TimerGet(en_xpsytime tymr)
353+
{
354+
if (this->staktop < 0)
355+
{
356+
return -1.0f;
357+
}
358+
return *(&this->tmr_stack[0][this->staktop] + tymr); // ...what?
359+
}
360+
361+
void xPsyche::TimerClear()
362+
{
363+
if (this->staktop < 0)
364+
{
365+
return;
366+
}
367+
// Missing unreachable branch here. Otherwise functionally identical.
368+
this->tmr_stack[0][this->staktop] = 0.0f;
369+
}
370+
371+
void xPsyche::TimerUpdate(F32 dt)
372+
{
373+
F32* p;
374+
if (this->staktop < 0)
375+
{
376+
return;
377+
}
378+
379+
p = &this->tmr_stack[0][this->staktop];
380+
*p += dt;
381+
}

src/SB/Core/x/xBehaviour.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ enum en_psynote
6767
PSY_NOTE_FORCE = 0x7fffffff
6868
};
6969

70+
enum en_xpsytime
71+
{
72+
XPSY_TYMR_CURGOAL = 0,
73+
XPSY_TYMR_NOMORE = 1,
74+
};
75+
7076
struct xGoal;
7177

7278
struct xPSYNote
@@ -110,6 +116,7 @@ struct xPsyche : RyzMemData
110116
{
111117
return gid_safegoal;
112118
}
119+
xGoal* GetPrevRecovery(S32 gid);
113120
S32 Timestep(F32 dt, void* updCtxt);
114121
xGoal* FindGoal(S32 gid);
115122
S32 GoalSet(S32 gid, S32 r5);
@@ -125,10 +132,15 @@ struct xPsyche : RyzMemData
125132
void BrainExtend();
126133
void BrainEnd();
127134
xGoal* AddGoal(S32 gid, void* createData);
135+
void ForceTran(F32, void*);
128136
void FreshWipe();
137+
F32 TimerGet(en_xpsytime tymr);
138+
void TimerClear();
139+
void SetTopState(en_GOALSTATE);
129140
void SetOwner(xBase*, void*);
130141
void KillBrain(xFactory*);
131142
void Lobotomy(xFactory*);
143+
void TimerUpdate(F32 dt);
132144
void SetSafety(S32 goalID)
133145
{
134146
gid_safegoal = goalID;

0 commit comments

Comments
 (0)