2019-12-12 07:08 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000684Spring engineGeneralpublic2007-11-18 02:33
ReporterKDR_11k 
Assigned ToKloot 
PrioritynormalSeverityfeatureReproducibilityN/A
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000684: [patch] additional CEG functions
DescriptionThis patch adds three opcodes to the CEG definitions:
- m (modulo or sawtooth wave) returns the remainder of the runing value divided by m's parameter (so 100 m24 returns 4)
- s (sine) returns the sine of the running value with the parameter acting as the amplitude
- k (discrete) returns the running value floored to an integral multiple of the parameter (k is often used as the name for the variable meaning an integral multiple of a certain value)

Additionally, all weapons that have one now supply their remaining ttl as the damage param to their trail CEG (Flame uses curTime instead).

This patch also adds the set constant CEG_DAMAGE (99), it defines the damage value for all CEGs triggered with emit-sfx 1024+x to allow for some variability in the emitted effects to e.g. make a charging energy ball grow larger or have smoke get progressively darker as the unit's HP decreases.

It also fixes the bug where an explosion in the air over water is considered a water explosion (switches the order in which air and water explosions are determined) and it prevents LaserProjectiles from emitting their CEG once checkCol is false (e.g. when the laser has impacted and is contracting).
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon cegTweaks.patch (8,481 bytes) 2007-11-15 23:55 -
    Index: Sim/Projectiles/ExplosionGenerator.cpp
    ===================================================================
    --- Sim/Projectiles/ExplosionGenerator.cpp	(revision 4796)
    +++ Sim/Projectiles/ExplosionGenerator.cpp	(working copy)
    @@ -324,6 +324,9 @@
     #define OP_LOADP  8 // load a void* into the pointer register
     #define OP_STOREP 9 // store the pointer register into a void*
     #define OP_DIR	  10 //stor the float3 direction
    +#define OP_SAWTOOTH 11 //Performs a modulo to create a sawtooth wave
    +#define OP_DISCRETE 12 //Floors the value to a multiple of its parameter
    +#define OP_SINE   13 //Uses val as the phase of a sine wave
     
     void CCustomExplosionGenerator::ExecuteExplosionCode(const char *code, float damage, char *instance, int spawnIndex,const float3 &dir)
     {
    @@ -394,6 +397,22 @@
     				*(float3*)(instance + offset) = dir;
     				break;
     			}
    +			case OP_SAWTOOTH: {
    +				val -= *(float*)code * floor(val / *(float*)code);
    +				  //this translates to modulo except it works with floats
    +				code += 4;
    +				break;
    +			}
    +			case OP_DISCRETE: {
    +				val = *(float*)code * floor(val / *(float*)code);
    +				code += 4;
    +				break;
    +			}
    +			case OP_SINE: {
    +				val = *(float*)code * sin(val);
    +				code += 4;
    +				break;
    +			}
     			default: {
     				assert(false);
     				break;
    @@ -436,6 +455,9 @@
     			if (c=='i')	opcode = OP_INDEX;
     			else if (c=='r') opcode = OP_RAND;
     			else if (c=='d') opcode = OP_DAMAGE;
    +			else if (c=='m') opcode = OP_SAWTOOTH;
    +			else if (c=='k') opcode = OP_DISCRETE;
    +			else if (c=='s') opcode = OP_SINE;
     			else if (isdigit(c)||c=='.'||c=='-') { opcode = OP_ADD; p--; }
     			else throw content_error("Explosion script error: \"" + script + "\"  : \'" + string(1, c) + "\' is unknown opcode.");
     
    @@ -619,9 +641,9 @@
     	float h2=ground->GetHeight2(pos.x,pos.z);
     
     	unsigned int flags = 0;
    -	if (h2<-3) flags = SPW_WATER;
    +	if (pos.y-max((float)0,h2)>20) flags = SPW_AIR;
    +	else if (h2<-3) flags = SPW_WATER;
     	else if (pos.y<-15) flags = SPW_UNDERWATER;
    -	else if (pos.y-max((float)0,h2)>20) flags = SPW_AIR;
     	else flags = SPW_GROUND;
     	if (hit) flags |= SPW_UNIT;
     	else flags |= SPW_NO_UNIT;
    Index: Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp	(working copy)
    @@ -56,7 +56,7 @@
     	}
     	else {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +			ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed);
     		}
     	}
     	UpdateGroundBounce();
    Index: Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp	(working copy)
    @@ -70,7 +70,7 @@
     	} else {
     		if (ttl > 0) {
     			if (cegTag.size() > 0) {
    -				ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, speed);
    +				ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, speed);
     			}
     		}
     	}
    Index: Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp	(working copy)
    @@ -114,7 +114,7 @@
     	}
     
     	if (cegTag.size() > 0) {
    -		ceg.Explosion(pos, 0.0f, (sparks.size() > 0)? sparks[0].size: 0.0f, 0x0, 0.0f, 0x0, speed);
    +		ceg.Explosion(pos, ttl, (sparks.size() > 0)? sparks[0].size: 0.0f, 0x0, 0.0f, 0x0, speed);
     	}
     
     	UpdateGroundBounce();
    Index: Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp	(working copy)
    @@ -81,7 +81,7 @@
     	}
     
     	if (cegTag.size() > 0) {
    -		ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +		ceg.Explosion(pos, curTime, intensity, 0x0, 0.0f, 0x0, speed);
     	}
     }
     
    Index: Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp	(working copy)
    @@ -80,9 +80,9 @@
     
     	ttl--;
     
    -	if (ttl > 0) {
    +	if (ttl > 0 && checkCol) {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +			ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed);
     		}
     	}
     	
    Index: Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp	(working copy)
    @@ -235,7 +235,7 @@
     		targPos = orgTargPos;
     
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, dir);
    +			ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, dir);
     		}
     	} else {
     		// only when TTL <= 0 do projectiles
    Index: Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp	(working copy)
    @@ -211,7 +211,7 @@
     
     	if (ttl > 0) {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, dir);
    +			ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, dir);
     		}
     	}
     
    Index: Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp	(revision 4796)
    +++ Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp	(working copy)
    @@ -133,7 +133,7 @@
     			speed = dir * curSpeed;
     
     			if (cegTag.size() > 0) {
    -				ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, speed);
    +				ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, speed);
     			}
     		} else {
     			speed *= 0.98f;
    Index: Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- Sim/Units/COB/CobInstance.cpp	(revision 4796)
    +++ Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -102,6 +102,7 @@
     #define STEALTH                   96 // set or get
     #define CRASHING                  97 // set or get, returns whether aircraft isCrashing state
     #define CHANGE_TARGET             98 // set, the value it's set to determines the affected weapon
    +#define CEG_DAMAGE                99 // set
     #define COB_ID                   100 // get
     #define ALPHA_THRESHOLD          103 // set or get
     #define SET_WEAPON_UNIT_TARGET   106 // get (fake set)
    @@ -672,7 +673,7 @@
     				//float3 relDir = -unit->localmodel->GetPieceDirection(piece) * 0.2f;
     				float3 dir = unit->frontdir * relDir.z + unit->updir * relDir.y + unit->rightdir * relDir.x;
     				dir.Normalize();
    -				unit->unitDef->sfxExplGens[index]->Explosion(pos, 1, 1, unit, 0, 0, dir);
    +				unit->unitDef->sfxExplGens[index]->Explosion(pos, unit->cegDamage, 1, unit, 0, 0, dir);
     			}
     			else if (type & 2048)  //make a weapon fire from the piece
     			{
    @@ -1462,6 +1463,10 @@
     			unit->weapons[param - 1]->avoidTarget = true;
     			break;
     		}
    +		case CEG_DAMAGE: {
    +			unit->cegDamage = param;
    +			break;
    +		}
     		case ALPHA_THRESHOLD: {
     			unit->alphaThreshold = float(param) / 255.0f;
     			break;
    Index: Sim/Units/Unit.cpp
    ===================================================================
    --- Sim/Units/Unit.cpp	(revision 4796)
    +++ Sim/Units/Unit.cpp	(working copy)
    @@ -222,7 +222,8 @@
     	usingScriptMoveType(false),
     	lodCount(0),
     	currentLOD(0),
    -	alphaThreshold(0.1f)
    +	alphaThreshold(0.1f),
    +	cegDamage(1)
     {
     #ifdef DIRECT_CONTROL_ALLOWED
     	directControl=0;
    Index: Sim/Units/Unit.h
    ===================================================================
    --- Sim/Units/Unit.h	(revision 4796)
    +++ Sim/Units/Unit.h	(working copy)
    @@ -367,6 +367,7 @@
     	LuaUnitMaterial luaMats[LUAMAT_TYPE_COUNT];
     
     	float alphaThreshold; //minimum alpha value for a texel to be drawn
    +	int cegDamage;			//the damage value passed to CEGs spawned by this unit's script
     
     protected:
     	void ChangeTeamReset();
    
    patch file icon cegTweaks.patch (8,481 bytes) 2007-11-15 23:55 +
  • patch file icon cegTweaks_update.patch (8,082 bytes) 2007-11-17 13:07 -
    Index: Sim/Projectiles/ExplosionGenerator.cpp
    ===================================================================
    --- Sim/Projectiles/ExplosionGenerator.cpp	(revision 4806)
    +++ Sim/Projectiles/ExplosionGenerator.cpp	(working copy)
    @@ -325,6 +325,9 @@
     #define OP_LOADP  8 // load a void* into the pointer register
     #define OP_STOREP 9 // store the pointer register into a void*
     #define OP_DIR	  10 //stor the float3 direction
    +#define OP_SAWTOOTH 11 //Performs a modulo to create a sawtooth wave
    +#define OP_DISCRETE 12 //Floors the value to a multiple of its parameter
    +#define OP_SINE   13 //Uses val as the phase of a sine wave
     
     void CCustomExplosionGenerator::ExecuteExplosionCode(const char *code, float damage, char *instance, int spawnIndex,const float3 &dir)
     {
    @@ -395,6 +398,22 @@
     				*(float3*)(instance + offset) = dir;
     				break;
     			}
    +			case OP_SAWTOOTH: {
    +				val -= *(float*)code * floor(val / *(float*)code);
    +				  //this translates to modulo except it works with floats
    +				code += 4;
    +				break;
    +			}
    +			case OP_DISCRETE: {
    +				val = *(float*)code * floor(val / *(float*)code);
    +				code += 4;
    +				break;
    +			}
    +			case OP_SINE: {
    +				val = *(float*)code * sin(val);
    +				code += 4;
    +				break;
    +			}
     			default: {
     				assert(false);
     				break;
    @@ -437,6 +456,9 @@
     			if (c=='i')	opcode = OP_INDEX;
     			else if (c=='r') opcode = OP_RAND;
     			else if (c=='d') opcode = OP_DAMAGE;
    +			else if (c=='m') opcode = OP_SAWTOOTH;
    +			else if (c=='k') opcode = OP_DISCRETE;
    +			else if (c=='s') opcode = OP_SINE;
     			else if (isdigit(c)||c=='.'||c=='-') { opcode = OP_ADD; p--; }
     			else throw content_error("Explosion script error: \"" + script + "\"  : \'" + string(1, c) + "\' is unknown opcode.");
     
    Index: Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/EmgProjectile.cpp	(working copy)
    @@ -56,7 +56,7 @@
     	}
     	else {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +			ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed);
     		}
     	}
     	UpdateGroundBounce();
    Index: Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp	(working copy)
    @@ -70,7 +70,7 @@
     	} else {
     		if (ttl > 0) {
     			if (cegTag.size() > 0) {
    -				ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, speed);
    +				ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, speed);
     			}
     		}
     	}
    Index: Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/FireBallProjectile.cpp	(working copy)
    @@ -114,7 +114,7 @@
     	}
     
     	if (cegTag.size() > 0) {
    -		ceg.Explosion(pos, 0.0f, (sparks.size() > 0)? sparks[0].size: 0.0f, 0x0, 0.0f, 0x0, speed);
    +		ceg.Explosion(pos, ttl, (sparks.size() > 0)? sparks[0].size: 0.0f, 0x0, 0.0f, 0x0, speed);
     	}
     
     	UpdateGroundBounce();
    Index: Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/FlameProjectile.cpp	(working copy)
    @@ -81,7 +81,7 @@
     	}
     
     	if (cegTag.size() > 0) {
    -		ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +		ceg.Explosion(pos, curTime, intensity, 0x0, 0.0f, 0x0, speed);
     	}
     }
     
    Index: Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/LaserProjectile.cpp	(working copy)
    @@ -80,9 +80,9 @@
     
     	ttl--;
     
    -	if (ttl > 0) {
    +	if (ttl > 0 && checkCol) {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, intensity, 0x0, 0.0f, 0x0, speed);
    +			ceg.Explosion(pos, ttl, intensity, 0x0, 0.0f, 0x0, speed);
     		}
     	}
     	
    Index: Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/MissileProjectile.cpp	(working copy)
    @@ -235,7 +235,7 @@
     		targPos = orgTargPos;
     
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, dir);
    +			ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, dir);
     		}
     	} else {
     		// only when TTL <= 0 do projectiles
    Index: Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/StarburstProjectile.cpp	(working copy)
    @@ -211,7 +211,7 @@
     
     	if (ttl > 0) {
     		if (cegTag.size() > 0) {
    -			ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, dir);
    +			ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, dir);
     		}
     	}
     
    Index: Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp
    ===================================================================
    --- Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp	(revision 4806)
    +++ Sim/Projectiles/WeaponProjectiles/TorpedoProjectile.cpp	(working copy)
    @@ -133,7 +133,7 @@
     			speed = dir * curSpeed;
     
     			if (cegTag.size() > 0) {
    -				ceg.Explosion(pos, 0.0f, areaOfEffect, 0x0, 0.0f, 0x0, speed);
    +				ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, speed);
     			}
     		} else {
     			speed *= 0.98f;
    Index: Sim/Units/COB/CobInstance.cpp
    ===================================================================
    --- Sim/Units/COB/CobInstance.cpp	(revision 4806)
    +++ Sim/Units/COB/CobInstance.cpp	(working copy)
    @@ -102,6 +102,7 @@
     #define STEALTH                   96 // set or get
     #define CRASHING                  97 // set or get, returns whether aircraft isCrashing state
     #define CHANGE_TARGET             98 // set, the value it's set to determines the affected weapon
    +#define CEG_DAMAGE                99 // set
     #define COB_ID                   100 // get
     #define ALPHA_THRESHOLD          103 // set or get
     #define SET_WEAPON_UNIT_TARGET   106 // get (fake set)
    @@ -672,7 +673,7 @@
     				//float3 relDir = -unit->localmodel->GetPieceDirection(piece) * 0.2f;
     				float3 dir = unit->frontdir * relDir.z + unit->updir * relDir.y + unit->rightdir * relDir.x;
     				dir.Normalize();
    -				unit->unitDef->sfxExplGens[index]->Explosion(pos, 1, 1, unit, 0, 0, dir);
    +				unit->unitDef->sfxExplGens[index]->Explosion(pos, unit->cegDamage, 1, unit, 0, 0, dir);
     			}
     			else if (type & 2048)  //make a weapon fire from the piece
     			{
    @@ -1462,6 +1463,10 @@
     			unit->weapons[param - 1]->avoidTarget = true;
     			break;
     		}
    +		case CEG_DAMAGE: {
    +			unit->cegDamage = param;
    +			break;
    +		}
     		case ALPHA_THRESHOLD: {
     			unit->alphaThreshold = float(param) / 255.0f;
     			break;
    Index: Sim/Units/Unit.cpp
    ===================================================================
    --- Sim/Units/Unit.cpp	(revision 4806)
    +++ Sim/Units/Unit.cpp	(working copy)
    @@ -222,7 +222,8 @@
     	usingScriptMoveType(false),
     	lodCount(0),
     	currentLOD(0),
    -	alphaThreshold(0.1f)
    +	alphaThreshold(0.1f),
    +	cegDamage(1)
     {
     #ifdef DIRECT_CONTROL_ALLOWED
     	directControl=0;
    Index: Sim/Units/Unit.h
    ===================================================================
    --- Sim/Units/Unit.h	(revision 4806)
    +++ Sim/Units/Unit.h	(working copy)
    @@ -367,6 +367,7 @@
     	LuaUnitMaterial luaMats[LUAMAT_TYPE_COUNT];
     
     	float alphaThreshold; //minimum alpha value for a texel to be drawn
    +	int cegDamage;			//the damage value passed to CEGs spawned by this unit's script
     
     protected:
     	void ChangeTeamReset();
    
    patch file icon cegTweaks_update.patch (8,082 bytes) 2007-11-17 13:07 +

-Relationships
+Relationships

-Notes

~0001438

KDR_11k (reporter)

Updated to remove conflict with newer version (Kloot already did the air-water fix)

~0001444

Kloot (developer)

Looks fine, I'll commit this soonish.

~0001446

Kloot (developer)

Done, r4824.
+Notes

-Issue History
Date Modified Username Field Change
2007-11-15 23:55 KDR_11k New Issue
2007-11-15 23:55 KDR_11k File Added: cegTweaks.patch
2007-11-17 13:07 KDR_11k File Added: cegTweaks_update.patch
2007-11-17 13:07 KDR_11k Note Added: 0001438
2007-11-17 19:34 Kloot Note Added: 0001444
2007-11-18 02:33 Kloot Note Added: 0001446
2007-11-18 02:33 Kloot Status new => resolved
2007-11-18 02:33 Kloot Resolution open => fixed
2007-11-18 02:33 Kloot Assigned To => Kloot
+Issue History