Game Development Community

fxReplicatorBlocker

by Thomas \"Man of Ice\" Lund · 09/21/2004 (10:08 pm) · 17 comments

Download Code File

What is this
I've always felt the replicators to be powerful, and thanks Melv for those! But they are lacking a little, and today I finally got around to do something about some of the things I feel are missing.

This is a nifty little new object type that allows you to block out replication inside a replicator area. The idea has long been in my head, and today I saw the unused VehicleBlocker code. So I jumped right into it and coded away.

Screenshots tell it all, so here is one:

www.codejar.com/torque/replicatorblocker.jpg
Dump some of these into your scene and you can have 1 replicator create a huge forrest, and the blockers then "carve" paths through the forrest as needed. The alternative would be to have tons of replicators and fiddling with their sizes and rotations.

Engine changes

It is quite easy to add this.

Add the 2 attached files to the game/fx dir, and then do the following changes

main.cc
After this
Con::setIntVariable("$TypeMasks::StaticRenderedObjectType", StaticRenderedObjectType);
   Con::setIntVariable("$TypeMasks::DamagableItemObjectType",  DamagableItemObjectType);
add this
Con::setIntVariable("$TypeMasks::fxReplicatorBlockerObjectType", fxReplicatorBlockerObjectType);

objectTypes.h
After this
DamagableItemObjectType =     bit(27),
add this
fxReplicatorBlockerObjectType =    bit(28),

fxShapeReplicator changes

in game/fx/fxShapeReplicator.cc find this
// Initialise RayCast Search Start/End Positions.
            ShapeStart = ShapeEnd = ShapePosition;
            ShapeStart.z = 2000.f;
            ShapeEnd.z= -2000.f;

and change it to

// Initialise RayCast Search Start/End Positions.
            ShapeStart = ShapeEnd = ShapePosition;
            ShapeStart.z = 2000.f;
            ShapeEnd.z= -2000.f;

			// Check for blockers
		    RayInfo         BlockerRayEvent;
			if (isServerObject()) {
				if (gServerContainer.collideBox(ShapeStart, ShapeEnd, fxReplicatorBlockerObjectType, &BlockerRayEvent)) {
					continue;
				}
			} else {
				if (gClientContainer.collideBox( ShapeStart, ShapeEnd, fxReplicatorBlockerObjectType, &BlockerRayEvent)) {
					continue;
				}
			}

Script changes
Open common/editor/objectBuilderGui.gui and add this somewhere in there
function ObjectBuilderGui::buildfxReplicatorBlocker(%this)
{
   %this.className = "fxReplicatorBlocker";
   %this.addField("dimensions", "TypePoint3", "Dimensions",  "2 2 2");
   %this.process();
}

Open common/editor/EditorGui.cs and find this:
%Environment_Item[10] = "fxFoliageReplicator";
   %Environment_Item[11] = "fxLight";
and add this
%Environment_Item[12]  = "fxReplicatorBlocker";

(or whatever is the next item number)

Thats it!!

In your mission editor add replicators and blockers as you see fit. Good luck and enjoy!!

TODO
I ran out of time for today, so I didnt get the blockers to properly update themselves graphically when you change their dimension. A save/reload of the level does the trick.

This should also go into the foilage replicator, but I ran out of time. I'll add this later too.

#1
09/21/2004 (10:44 pm)
The download is not working.

Can you re-upload it?
#2
09/21/2004 (11:54 pm)
Classic. I'll re-upload tonight (@work now). I'll post here when I re-uploaded the file.
#3
09/22/2004 (5:55 am)
OK - reuploadet the zip. I hope that did it

Oh! And remember that you need to hit "Apply" on the replicator to force it to place the shapes. Just adding the blocker will not trigger replication
#4
09/22/2004 (5:56 am)
Works ;)
Thanks.
#6
09/22/2004 (12:49 pm)
Primo idea! I will definitely use this.

[HOW]EdM|EGTGE
#7
09/22/2004 (1:44 pm)
A really nice idea. Look forward to your redux with fxFoliageReplicator!!

Also I haven't looked but are fxShapeReplicator and fxFoliageReplicator up to date with the latest GG changes in 1.3? I am thinking specifically of the databits changes I am pretty sure that Foliage is but I hadn't thought about Shape until I saw this resource.
#8
09/23/2004 (12:17 am)
Very cool :)
#9
03/07/2005 (6:52 am)
To get this working with fxFoliageReplicator...

in game/fx/fxFoliageReplicator.cc find this


FoliageStart = FoliageEnd = FoliagePosition;
FoliageStart.z = 2000.f;
FoliageEnd.z= -2000.f;

and change it to

// Check for blockers
RayInfo BlockerRayEvent;
if (isServerObject())
{
if (gServerContainer.collideBox(FoliageStart, FoliageEnd, fxReplicatorBlockerObjectType, &BlockerRayEvent))
{
continue;
}
}
else
{
if (gClientContainer.collideBox( FoliageStart, FoliageEnd, fxReplicatorBlockerObjectType, &BlockerRayEvent))
{
continue;
}
}
#10
08/26/2005 (4:19 am)
this is good , thank you thomas.
#11
02/21/2006 (5:14 am)
Sorry for the necro, but can this be used in real time?...

For example.. I've got a massive forrest populated using replicators, containing trees, shrubs, grass... etc..
Then along comes a missile and blows a chunk out of the ground, destroying all trees, sending debris into the air...fires and so on.. places a ReplicatorBlocker where the trees once were, leaving a nice large hole in the forrest.

can this be done or is this a mission startup time only object?
#12
02/21/2006 (9:53 am)
Hey Jason, I'm not actually using the blocker but I've looked at the code a bit. In general it's a mission loadtime event that places all the trees, and would look to the blocker to not place the trees there. What you would want to do is modify the fxfoliagereplicator or the shape replicator or whatever to take some sort of bounding volume and remove any trees / foliage items it's placed within those bounds in realtime. I've thought about doing this myself for certain things with the fxfoliagereplicator, just haven't done it yet.
#13
02/21/2006 (12:40 pm)
Hey

Yeah - its a load time thing. fxReplicator shoots rays to place the trees.

But in theory it should be quite easy to write a different kind of object, that based on a radius does a setVisible(false) on every object of type X. It would even be a script only thing.

Just an idea to get you on track.
#14
04/26/2006 (9:48 pm)
Thankyou so much for this resource. It helps me out alot! Btw, it works fine in TGE 1.4.
#15
01/30/2007 (9:10 am)
Excellent idea ;) Thanks for taking the time and initiative to work it up.
EDIT: One thing that tripped my build up:
fxReplicatorBlockerObjectType = bit(28),
This looks like it needs to be BIT(28), in TGE 1.5. I got lots (and lots) of errors, but they all went away after changing this.

EDIT: Upon testing, I found that I'm getting an error. Whenever I try to create or load an fxShapeReplicator, I get the following error:
img393.imageshack.us/img393/4583/torqueerroragainuy2.png
#16
08/18/2008 (1:15 pm)
Unfortunately, I'm getting the same error.
#17
01/29/2009 (4:45 am)
Works in TGEA 1.8.