1111#include " zNPCSpawner.h"
1212#include " zNPCMessenger.h"
1313#include " zNPCGoals.h"
14+ #include " zNPCTypeTiki.h"
1415#include " zGlobals.h"
1516#include " xFactory.h"
1617#include " zRenderState.h"
1718
1819#include " xBehaveMgr.h"
20+ #include " xstransvc.h"
1921
2022#include < types.h>
2123
@@ -303,7 +305,7 @@ void zNPCCommon::RenderExtraPostParticles()
303305void zNPCMgr::ScenePostRender ()
304306{
305307 xLightKit_Enable (globals.player .ent .lightKit , globals.currWorld );
306- enum _SDRenderState old_rendstat = zRenderStateCurrent ();
308+ _SDRenderState old_rendstat = zRenderStateCurrent ();
307309 zRenderState (SDRS_NPCVisual);
308310 for (int i = 0 ; i < npclist.cnt ; i++)
309311 {
@@ -330,3 +332,118 @@ void zNPCMgr::ScenePostRender()
330332 xLightKit_Enable (0 , globals.currWorld );
331333 zRenderState (old_rendstat);
332334}
335+
336+ void zNPCMgr::ScenePostParticleRender ()
337+ {
338+ xLightKit_Enable (globals.player .ent .lightKit , globals.currWorld );
339+ _SDRenderState old_rendstat = zRenderStateCurrent ();
340+ zRenderState (SDRS_NPCVisual);
341+ for (int i = 0 ; i < npclist.cnt ; i++)
342+ {
343+ zNPCCommon* npc = (zNPCCommon*)npclist.list [i];
344+ if (npc->flg_xtrarend & 0x2 )
345+ {
346+ npc->flg_xtrarend &= ~0x2 ;
347+ }
348+ else
349+ {
350+ continue ;
351+ }
352+
353+ if (npc->baseFlags & 0x40 )
354+ {
355+ continue ;
356+ }
357+
358+ if (npc->model == NULL || !(npc->model ->Flags & 0x400 ))
359+ {
360+ npc->RenderExtraPostParticles ();
361+ }
362+ }
363+ xLightKit_Enable (0 , globals.currWorld );
364+ zRenderState (old_rendstat);
365+ }
366+
367+ void zNPCMgr::SceneTimestep (xScene* xscn, F32 dt)
368+ {
369+ DBG_PerfTrack ();
370+ if (g_firstFrameUpdateAllNPC != 0 )
371+ {
372+ BackdoorUpdateAllNPCsOnce (xscn, dt);
373+ g_firstFrameUpdateAllNPC = 0 ;
374+ }
375+ zNPCMsg_Timestep (xscn, dt);
376+ zNPCTiki_Timestep (xscn, dt);
377+ zNPCCommon_Timestep (xscn, dt);
378+ zNPCRobot_Timestep (xscn, dt);
379+ zNPCVillager_SceneTimestep (xscn, dt);
380+ }
381+
382+ void zNPCMgr::BackdoorUpdateAllNPCsOnce (xScene* xscn, F32 dt)
383+ {
384+ for (int i = 0 ; i < npclist.cnt ; i++)
385+ {
386+ zNPCCommon* npc = (zNPCCommon*)npclist.list [i];
387+ xSceneID2Name (globals.sceneCur , npc->id );
388+
389+ if (npc->baseFlags & 0x40 && npc->update != NULL )
390+ {
391+ npc->update (npc, xscn, 1 .0f / 60 );
392+ }
393+ }
394+ }
395+
396+ en_NPCTYPES zNPCMgr::NPCTypeForModel (U32 brainID, U32 mdl_hash)
397+ {
398+ if (brainID != NULL )
399+ {
400+ for (int i = 0 ; i < sizeof (g_brainTable) / sizeof (g_brainTable[0 ]); i++)
401+ {
402+ if (brainID == g_brainTable[i].id )
403+ {
404+ return g_brainTable[i].type ;
405+ }
406+ }
407+ }
408+
409+ en_NPCTYPES usetype = NPC_TYPE_UNKNOWN;
410+ for (NPCMTypeTable* rec = g_tbltype; rec->useNPCType != NPC_TYPE_UNKNOWN; rec++)
411+ {
412+ if (rec->hashOfName == mdl_hash)
413+ {
414+ usetype = rec->useNPCType ;
415+ break ;
416+ }
417+ }
418+
419+ if (usetype == NPC_TYPE_UNKNOWN)
420+ {
421+ usetype = NPC_TYPE_COMMON;
422+ }
423+
424+ return usetype;
425+ }
426+
427+ xEnt* zNPCMgr::CreateNPC (xEntAsset* asset)
428+ {
429+ zNPCCommon* npc;
430+ en_NPCTYPES nt;
431+ U32 size;
432+ xModelAssetInfo* modelAsset = (xModelAssetInfo*)xSTFindAsset (asset->modelInfoID , &size);
433+
434+ // FIXME: Replace with actually getting the right model hash from the packed data
435+ nt = this ->NPCTypeForModel (modelAsset->BrainID , *(&asset->modelInfoID + 3 ));
436+ npc = (zNPCCommon*)npcFactory->CreateItem (nt, NULL , NULL );
437+
438+ npc->Init (asset);
439+ XOrdAppend (&npclist, npc);
440+
441+ if (npclist.cnt == npclist.max )
442+ {
443+ XOrdSort (&npclist, zNPCMgr_OrdComp_npcid);
444+ }
445+
446+ this ->DBG_Reset ();
447+
448+ return npc;
449+ }
0 commit comments