Code:This is destprojectilelarge.ebg, one of the original EBG files that comes with Homeworld. It's a death event, although you could call it as another type of event if you really wanted to. Hopefully the bold comments will give you a good idea of how this file works. Let me know if this helps, or if it's just confusing. #line 1 "d:\\homeworld\\DataSrc\\ETG\\death\\DestProjectileLarge\\DestProjectileLarge.etg" #line 1 "d:\\homeworld\\dataSrc\\ETG\\etg.h" These look like preprocessor directives (like in C/C++), but deleting them doesn't seem to have any ill effects, so wipe 'em out! Lots of whitespace, no? It's not necessary. So take it out if it annoys you, or leave it in. Whatever. #line 112 "d:\\homeworld\\dataSrc\\ETG\\etg.h" #line 1 "d:\\homeworld\\DataSrc\\ETG\\death\\DestProjectileLarge\\DestProjectileLarge.etg" More comments. Blah. eventStart(float shipSize = 40, float velocity = 0.5) Here we go! This is like the start of a function in C/C++ All death events get passed shipSize (roughly equal to the radius of the collision sphere in the MEX) and velocity (the velocity of the ship that just died). You can change these variable names, but they're convenient, so why bother? #line 1 "d:\\homeworld\\src\\game\\soundeventdefs.h" #line 4 "d:\\homeworld\\DataSrc\\ETG\\death\\DestProjectileLarge\\DestProjectileLarge.etg" Wow. Whitespace and useless lines of stuff! variable You must declare your variables here. { float size float reactorOffset float shockSize float shockSizeRate You can't declare multiple variables on the same line float firepuffSize float firepuffSizeTemp float shiftLOF float shiftLOFTemp1 float shiftLOFTemp2 float shiftRTemp1 float shiftRTemp2 float shiftR float shiftTheta You can define initial values for your variables in this section if you want to. } startup { This stuff is executed as soon as the file is called. setDefaults() This resets a lot of variables to their default values. You'll meet these variables later... size <- fmult(shipSize, 0.6) fmult() multiplies two floating point numbers. <- redirects the output of the fmult() function into whatever is on the left. In C++, this would be size *= 0.6; } eachFrame Stuff in here is executed every frame. { at(0.01) Anything in these braces is executed 0.01 seconds after the file is called. { playSound([(4 + 4096)]) It plays a sound! A pretty nice Boom! if memory serves. I haven't tested all the different numbers you could supply as arguements. setDefaults() Makes sure everything is back to normal before it starts changing things shockSize <- fmult(size, 5) shockSizeRate <- fmult(size, 30) reactorOffset <- fmult(size, -0.6) These three user-defined variables have been set based on the size of the ship that this effect is for. setOffsetLOF(reactorOffset) Offset = obvious. LOF = Line of Fire (as near as I can tell) So this command sets how far foward or back the next object will be. This stays in effect until it is changed, or until a setDefaults() is executed. setScale(shockSize) Sets the scale. Most of the meshes (and all sprites) used in effects are about 1 meter on a side, to make setting the scale easier. This stays in effect until changed or until you setDefaults() setDeltaScale(shockSizeRate) Delta = change in. So after one second, the scale of whatever we're making will not be shockSize, but (shockSize + shockSizeRate). Get it? setColorA([255 + 255 * 256 + 255 * 65536 + 255 * 65536 * 256]) Think "SetColorAlpha" This sets transparency based on color. The format is (red) + (green)(256) + (blue)(65536) + (alpha)(65536 * 256). R,G,B, and A are all 255; that indicates fully opaque. This stays in effect until . . . you see the pattern? setAddColor(1.0, 0.75, 0.5) This adds color! Instead of one RGBA variable, this accepts 3 floating-point arguments, ranging from 0 to 1. This looks like a bright orange. setLighting(0) This thing will not be affected by the lighting in the level. setIllum(1) It will glow! setLifespan(0.1) It will last 0.1 seconds setTexture(textures\glow32 0, 0, 32, 32) It will have the glow32 texture, located in homeworld\etg\textures\ It will start texturing at (0,0) and will go for 32 pixels in each direction. Since glow32 is a 32x32 texture, that's the whole thing! createSprites(1, 0) Now something actually shows up on screen. It's a sprite, a two-dimensional object. It will stay face-on to the camera no matter how you movethe camera around. Since it's a bright glowing orange that expands and disappears quickly, I'd say it's the initial flash of an explosion. } at(0.01) This will happen 0.01 seconds after the file starts running. { setDefaults() Remember all those things that changed in the last set of braces? All reset. Poof. firepuffSizeTemp <- 1.5 firepuffSize <- fmult(firepuffSizeTemp, size) This is an odd way to multiply, but at least the variable gets set. shiftLOFTemp1 <- fmult(size, -3) shiftLOFTemp2 <- fmult(size, 3) shiftRTemp1 <- fmult(size, -0.5) shiftRTemp2 <- fmult(size, 0.5) shiftLOF <- frandom(shiftLOFTemp1, shiftLOFTemp2) shiftR <- frandom(shiftRTemp1, shiftRTemp2) frandom returns a random floating-point number between its two arguements. See how the programmer set up the ranges? shiftTheta <- frandom(0.01, [(360) * 2.0 * 3.14159265359789 / 360.0]) Something between 0.01 and 2pi. Do I smell an angle? setEffOffsetLOF(reactorOffset) setEffOffsetR(shiftR, shiftTheta) You've seen Offset and LOF before, but what's Eff? That is added because of what's coming next, an effect. R stands for radius. The first arguement is radius, and the second is angle, in radians. spawn(DPLboom.ebg, firepuffSize) spawn calls another EBG and lets it run independently. Even if this EBG dies before DPLboom.ebg is finished, it will keep going. firepuffSize is DPLboom.ebg's only arguement. } at(0.6) After 0.6 seconds, this stuff happens. { setDefaults() firepuffSizeTemp <- frandom(0.8, 1.3) firepuffSize <- fmult(firepuffSizeTemp, size) shiftLOFTemp1 <- fmult(size, -0.5) shiftLOFTemp2 <- fmult(size, 3) shiftRTemp1 <- fmult(size, -0.5) shiftRTemp2 <- fmult(size, 0.5) shiftLOF <- frandom(shiftLOFTemp1, shiftLOFTemp2) shiftR <- frandom(shiftRTemp1, shiftRTemp2) shiftTheta <- frandom(0.01, [(360) * 2.0 * 3.14159265359789 / 360.0]) setEffOffsetLOF(shiftLOF) setEffOffsetR(shiftR, shiftTheta) spawn(DPLboom.ebg, firepuffSize) Wow, it's just like that block of code that executed 0.59 seconds ago. The random values are within different ranges. } at(0.8) { setDefaults() firepuffSizeTemp <- frandom(0.8, 1.3) firepuffSize <- fmult(firepuffSizeTemp, size) shiftLOFTemp1 <- fmult(size, 0) shiftLOFTemp2 <- fmult(size, 3) shiftRTemp1 <- fmult(size, -0.5) shiftRTemp2 <- fmult(size, 0.5) shiftLOF <- frandom(shiftLOFTemp1, shiftLOFTemp2) shiftR <- frandom(shiftRTemp1, shiftRTemp2) shiftTheta <- frandom(0.01, [(360) * 2.0 * 3.14159265359789 / 360.0]) setEffOffsetLOF(shiftLOF) setEffOffsetR(shiftR, shiftTheta) spawn(DPLboom.ebg, firepuffSize) Same stuff, different randomized variables, so it's in a different place. } at(1.0) { setDefaults() firepuffSizeTemp <- frandom(0.8, 1.3) firepuffSize <- fmult(firepuffSizeTemp, size) shiftLOFTemp1 <- fmult(size, 0) shiftLOFTemp2 <- fmult(size, 4) shiftRTemp1 <- fmult(size, -0.5) shiftRTemp2 <- fmult(size, 0.5) shiftLOF <- frandom(shiftLOFTemp1, shiftLOFTemp2) shiftR <- frandom(shiftRTemp1, shiftRTemp2) shiftTheta <- frandom(0.01, [(360) * 2.0 * 3.14159265359789 / 360.0]) setEffOffsetLOF(shiftLOF) setEffOffsetR(shiftR, shiftTheta) spawn(DPLboom.ebg, firepuffSize) Yeah, another one. Whatever DPLboom.ebg is, it's good enough to make four copies! } } eachFrame { at(1) { hideParentShip() This removes the mesh of the dead ship deleteParentShip() This is a necessary part of cleanup. If you don't execute this, the game will continue to calculate the position and rotation of the dead ship. Forever. } at(2) { delete() Boom, it's all gone. No more sprites, lines, points, meshes, or effects. spawned effects will continue. } }



Get making those effects people!
