Game Development Community

How to implement object polimorphism ?

by Bruno Grieco · in Torque Game Engine · 06/18/2004 (12:30 pm) · 9 replies

Guys,

I have 10 crows, say I want one of them to be a supercrow. If I do an activatePackage(supercrow), all of them become supercrows.

%this.activatepackage(supercrow) doesn't work since activatepackage is not a member of the AIPlayer Hierarchy.

How do I implement the polymorphism for just one object ?

TIA

#1
06/18/2004 (12:44 pm)
Not sure if I understand exactly what you want, but you can use the namespace stuff to "inherit" script classes. ie:

datablock crowData(baseCrow)
{ 
  //all crow attribs
};

datablock crowData(superCrow : baseCrow)
{
  //my super abilities
};
#2
06/18/2004 (7:09 pm)
Nope,

What I want is a crow to become a supercrow and then become a crow again.

Separate datablocks would imply separate objects. Polymorphism is when an object behaves like another but it's still the same object.
#3
06/18/2004 (7:54 pm)
You're going to have to set a new datablock on the crow when it changes, then set it back, not modify the datablock.

Datablocks are by definition shared data.
#4
06/19/2004 (5:57 am)
Ben,

Could you be more specific on how I should do it.

TIA

Bruno
#5
06/19/2004 (7:38 am)
Yeah, you will have to make a seperate DB for the supercrow and have that switch at runtime, OR you could also code some mutator functions for the AI class where you could change properties on an instance of crow.

I like your idea Bruno, very cool! Have you or anyone else gotten AI to fly around?

-s
#6
06/19/2004 (11:04 am)
Example:

%crow.setDataBlock(NormalCrowDataBlock);

%crow.setDataBlock(SuperCrowDataBlock);
#7
06/19/2004 (12:31 pm)
Thanks Ben,

I guess that since the parameters don't change much, all I would have to do is having a different classname for each datablock.

@Stephen,

I got AI to fly around by changing the Player.cc, allowing them to fly. There was other guy who managed to attach them to hoverVehicles. There is also some discussions about AIVehicles, cause bots just can't drive. Badguy made an AISterring function that can handle cars but I haven't had much luck adding a 3rd dimension to that.
#8
06/21/2004 (1:50 am)
Bruno: What did you change in order for the player to fly?
#9
06/21/2004 (6:43 am)
I mixed both resources below in Player.cc. XY plane movement is done by setMoveDestination, Z movement is done by setAimPosition.

swimming

air control

HTH