Game Development Community

Turret & AITurret classes, Version 1.20 for TGEA 1.8.1

by kcpdad · 06/02/2009 (8:05 pm) · 25 comments

Credits - To those that did the heavy lifting
This was tested with the TGEA Stronghold game example.

Click to Download

Instructions

**** MOST IMPORTANT **** -> Make a backup of your existing TGEA 1.8.1 installation!!!
Merge changes from the zip file into your TGEA 1.8.1 installation.
Add a new filter/folder called turrets to your project under T3D.
Add the two .cpp files(turret.cpp and aiTurret.cpp) as existing items to the filter/folder you just added.
Rebuild the engine.
Read the original Readme.txt for instructions on adding turrets to a mission.

Gotchas

If you add a turret to a mission, use the mission editor to set the value of the dynamic field "locked" to either true or false.
Otherwise the engine will crash if you execute a dump() method on the turret object in the console.

About the author

Hobbyist working on a tank game when time allows. Play the prototype at => http://60tons.battleop.com/

Page«First 1 2 Next»
#21
08/09/2010 (11:49 pm)
Hi all,

Does anyone have this working in T3D 1.1b2 yet? Player-controlled turrets are fine, but I'm getting a crash as soon as I add an AITurret to the level.

I've littered aiTurret.cpp (and all parents) with Con::errorf lines and I can see we go all the way up to simObject::onAdd() (via Parent::onAdd()) and all the way back to AITurret::onAdd but then !mDataBlock evaluates to true (I assume somehow mDataBlock is remaining as NULL). That is the last debug message I see before I crash.

When I run a debug build and the crash is intercepted, the line it points to is simObject.h line 686:

SimObjectId getId() const { return mId; }

Any thoughts?
#22
08/10/2010 (9:10 am)
Update: I am outputting mDataBlock->getName() to the console from Turret::onAdd() and AITurret::onAdd.

Just above the return true in Turret::onAdd, mDataBlock->getName() still returns GenericAITurret.

However - as soon as we return to AITurret::onAdd, mDataBlock becomes NULL again.
#23
01/25/2011 (8:11 pm)
@Andy: Did you ever track down that issue with the datablock turning NULL?
#24
01/26/2011 (12:06 am)
I didn't. In the end I got fed up of trying and ripped all the turret code out with intention of coming back to it at a later date. I haven't reached that date just yet...
#25
01/27/2011 (2:04 am)
*lots of conjecture deleted, just leaving the conclusion*

Basically, this comes down to a really simple issue that took me way too long to locate:
T3D's calls to onNewDataBlock follow the format "bool (pointer, bool)" while TGE's were "bool (pointer)." AITurret doesn't have a version of the function which takes a bool, so it's never getting called. Easy fix. And I think it'll fix a couple other smaller bugs relating to script callbacks in the process, since Turret's "base" onNewDatablock function was never even getting called.

Here's the fix. In turret.cc, add "bool reload" to both versions of onNewDatablock:
// [HNT] onNewDataBlock format change!
bool Turret::onNewDataBlock(GameBaseData *dptr, bool reload)
{
   return onNewDataBlock(dptr, reload, true);
   // [/HNT]
}
// [HNT] onNewDataBlock format change!
bool Turret::onNewDataBlock(GameBaseData *dptr, bool reload, bool callScript)
// [/HNT]
{
	mDataBlock = dynamic_cast<TurretData*>(dptr);

Do the same in turret.h:
void						onRemove();
   // [HNT] onNewDataBlock format change!
	bool						onNewDataBlock(GameBaseData* dptr, bool reload);
   // [/HNT]
	bool						onAdd(bool callScript);
	void						onRemove(bool callScript);
   // [HNT] onNewDataBlock format change!
	bool						onNewDataBlock(GameBaseData* dptr, bool reload, bool callScript);
   // [/HNT]
   virtual bool         getAIMove(Move*);

And in aiturret.cc:
// [HNT] onNewDataBlock format change!
bool AITurret::onNewDataBlock(GameBaseData* dptr, bool reload)
// [/HNT]
{
   // we call script so make sure turret class does not
   mDataBlock = dynamic_cast<AITurretData*>(dptr);
   // [HNT] onNewDataBlock format change!
   if (!mDataBlock || !Parent::onNewDataBlock(dptr, reload, false))
      // [/HNT]
      return false;

And finally aiturret.h:
// [HNT] onNewDataBlock format change!
   bool onNewDataBlock(GameBaseData* dptr, bool reload);
   // [/HNT]

That should do it.

If you don't want to bother patching all of the fixes together yourself, I've made a T3D resource: www.garagegames.com/community/resources/view/20792
Page«First 1 2 Next»