Random thoughts about scripting - Page 2

Random thoughts about scripting

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Archangel of Death
Posts: 854
Joined: 28 Jan 2005, 18:15

Post by Archangel of Death »

I'm thinking that even with the slowness of lua, having the ammo carrier go through lua to call a function (or functions) in a target unit's cob to reload it's ammo will be faster than having the target doing anything of its own accord. A few ammo transporters using fancy script, or however many dozens/hundreds of other units all using fancy script?
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Almost all units need to use fancy scripts for my mod concept to work but maybe I can accellerate it with Lua...
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

FLOZi wrote:Actually, it's HitByWeaponId(Z,X,id,damage)
In Total Annihilation:

HitByWeapon(var1,var2)
// first argument = z-position = x-angle
// second argument = x-position = z-angle
// In fact in HitByWeapon(var1,var2)
// var1 is the z-coordinate of the received shot, and so the amount of wanted rotation around the x-axis.
// var2 is the x-coordinate of the received shot, and so the amount of wanted rotation around the z-axis.
// Both coordinates exprimed in the local reference, centered and oriented by the unit, it's the axes seen in 3Do Builder, save maybe z whose sign might be inverted
// Arguments are normalised: get HYPOT(var1,var2) is always 400, or sometimes 399
// This mean you can get the direction to the impact,
// not the distance to the point of impact.
// And it's direction from unit center toward point of impact,
// not direction the shot was travelling.

The confusion is because tradionnally HitByWeapon is used only to make units rock when shot at, and when the unit is hit on the back-front axis, it must rock around the left-right axis, and vice-versa.

But that was in Total Annihilation, I have yet to investigate what are the HitByWeapon arguments in Spring.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Pretty much the same I think, only they are normalised to 500
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Ok, I just tried: Camembert.ufo. The following units work very well in TA. And answer WhiteHawk question about directionnal damage on a torso that turns.

However, to my dismay, it doesn't work in Spring! The three numbers are, from top to down, first HitByWeapon argument, second HitByWeapon argument, and health. As you can see, in Spring, both HitByWeapon argument remain at zero. Both in 0.74b3 and 0.75.

Yet, you said they are normalised to 500 and not 400 in Spring, so apparently you managed to get them work. Before I go whine in development forum, can you tell me if you really had them work,and if so, what's wrong with my unit?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Yes I really have it working quite well thanks.

Sadly I don't have HPI tools installed anymore, so I'll take my longer-than-a-line idiotic nickname and leave you to it, until you post it zipped. :wink:

Ok I lied, nothing looks terribly out of place, what happens when it is hit? Just nothing at all?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

http://spring.unknown-files.net/file/28 ... rt_as_sd7/
http://spring.unknown-files.net/file/28 ... rt_in_zip/

Can you give me your working exemple?

As I said, when it is hit, HitByWeapon is called, but both argument are 0, no matter where's the point of impact. So of course I can't get the hit direction. Since my "camembert" works very fine in TA, I first assumed Spring was broken, until I recalled that what you said implied Spring supported HitByWeapon.

And what's with WhiteHawk quoting us verbatim both way in PM? Sorry for misplacing the not-capital letter btw.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Post by yuritch »

It's possible that HitByWeapon works good for s3o units and not that well for 3do ones (since they seem to define collision spheres in different ways). FLOZi, which unit you tested the directional damage on? Was its model 3do or s3o?
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

It was s3o - but I suspect the problem lies with the weapon you are using, script looks fine. In Spring the values passed to HitByWeapon (or HitByWeaponId in 0.75, which is what i was testing, but I don't see any reason why HitByWeapon wouldn't) are based on impulse value of the weapon.

Here's the weapon I used for testing

Code: Select all

[m2105]
	{
	id=102;
	name=m2a1 105mm;
		rendertype=1;
	//model=shell;
	smoketrail=1;	
	color=255;		
	ballistic=1;
	turret=1;
	size=2.4;
	collisionsize=1;//4;
	
	range=2500;
	reloadtime=2;
	weaponvelocity=592;
	areaofeffect=48;//105;
	soundstart=105mm;
	soundhit=Artillery1;
      soundwater=exmine7;
      accuracy=1;//1400;
      edgeeffectiveness=0.0001;
      minbarrelangle=-45;
      holdtime=1;
	shakemagnitude=4;
	shakeduration=0.5;
	energypershot=125;
      
	targetmoveerror=0.02;

	startsmoke=1;
	impulsefactor=10;
	impulseboost=0;

	[DAMAGE]
		{
		default=1;
		}
	}
Alot of that is probably unnessacery rubbish. First thing to try is giving your weapon some small value for impulsefactor i suppose
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

I tested in both 74b3 and 75 of 1st may, HitByWeapon arguments are 0 in both.

I renamed HitByWeapon into HitByWeaponId, still HitByWeaponId arguments are 0.

I turned my Camembert into a s3o, still HitByWeapon arguments are 0.

I gave my Camembert your weapon, still HitByWeapon arguments are 0.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

That is very odd.

The next version of the buildbot will have my latest patch with get PRINT(v1,v2,v3,v4) where PRINT is 81. You can use it to print the values to chat to be absolutely certain of what they are?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Ok, after rattle told me:
<rattle> i think the idea behind is that only weapons with push a unit away can make it wobble

I just upped about every value possibly related in your weapon FBI, and now it works. Well, the HitByWeapons arguments are apparently not like in TA, because the wrong segment gets highlighted (it highlight the opposite to the one it should), but at least I have non null arguments.

It's a shame you can only read the direction of weapons that "push", but at least I know what caused my problem.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

zwzsg wrote:Well, the HitByWeapons arguments are apparently not like in TA, because the wrong segment gets highlighted (it highlight the opposite to the one it should), but at least I have non null arguments.
It's possible that its just registering the hit on the opposite side, sometimes my weapon did this, too. I reduced it as much as possible but it still happened quite a bit, which is why partly why I gave directional damage a miss for now. I think perhaps beamlasers wouldn't suffer from this though, due to the special nature of their collision detection.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

My area of effect is so bit I'm sure which side it hits.

Nah, it seems like in Spring, the argument passed to hitbyweapon gives the absolute angle, not the local one.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

zwzsg wrote:My area of effect is so bit I'm sure which side it hits.

Nah, it seems like in Spring, the argument passed to hitbyweapon gives the absolute angle, not the local one.
Oh that's what you meant. Yes, it does.

What do you mean you're sure which side it hits?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

Uploaded the working demo:
http://spring.unknown-files.net/file/28 ... w_Working/
It's a little mod, drop it into you Spring/mods/ and run it like any mod.

Still annoys me that something that worked so quickly in TA took so many hours to make working in Spring. That the angles are map-absolute and not unit-relative seem like an bug from the devs, and I wish non-pushing weapons could have directionnal damage too (but not necessarly via the HitByWeapon way however).

By sure I meant that when the shot hits a screen away, there's no doubt whether it hits right or left. Huge AoE FTW!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Registering on the wrong side comes from the issue that projectiles only check collission on one point per frame which means if the first frame the projectile spends inside the unit is on the other side of the hitsphere the code tells you the impact was on the other side. This is a big issue for mods with small units, too. The CvC tank main gun would be much faster if it didn't have as much of a tendency to phase through small targets.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

No. As I said twice already, I used such a big area of effect weapon that it affects the unit even when it hits 200 m away. When the point of impact is 200 m from the unit, there is zero doubt which side was hit.

Sometimes I feel like half I says is always ignored.

I was under the impression it registers from the wrong side because I supposed it worked like in TA, with the angle noted relatively to the unit. While in Spring, the angle I got from the ATAN of the HitByWeapon arguments comes noted as a map-absolute angle. Which imo is a bug and should be fixed. This is proved by how, now that I added the unit angle, my scripts works as it should: The quarter of direction of impact gets highlighted, no matter which way the unit is facing (and not matter how its turret turned)).

Anyway, just try it, it works.

However that was actually only the first step toward getting directionnal damage. Now we must:
- Find a way to read the weapon damage.
- Find a way to change the weapon damage after it has been dealt.


At first I thought about using 'get HEALTH' to know how much damage was dealt, and 'set HEALTH' to double or halve it. Problem is set/get HEALTH is in % of full health, integers only, so isn't precise enough for small shots on heavy units. But since FLOZi talks about 'HitByWeaponId(Z,X,id,damage)', I guess we can use that fourth argument to know the damage in hitpoint. We can't use the "set ARMORED to 0/1;" because, unless that was changed in Spring, haven't retested actually, HitByWeapon is called after damage is dealt, so too late to activate damagemodifier. Maybe there's some magic LUA commands to set hitpoints? It would be very convoluted, but theorically we could script-force-spawn small shots inside the unit to self-damage it? Any other ideas?

And despite having managed to get it work, I still need to get the dev:
- Correct the bug with HitByWeapon arguments using wrong coordinate system.
- Devise a way to get directionnal damage with non-pushing weapon.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

*sigh*.

Perhaps you should listen to us, as well.

Yes, HitByWeaponID(x,z,id,damage) supplies the damage, and, of much greater importance, the value you return from that function sets the damage done as a %. i.e. return 100 just does normal damage, return 500 would do 5 times as much, etc.

I already have directional damage working as well as you can with ballistic wepaons.

I still don't understand how you can always be sure it is registering as hitting the right side, you probably haven't tested it with a fast enough weapon to make the problem as apparant as it really is. A huge AOE will just mean that the unit registers a (direct) hit on both sides.

My only issue is that my script is ugly:

Code: Select all

#define SOUTH_CHECK(varName) varName >= (0 - FRONT_ARC) && varName <= FRONT_ARC
#define EAST_CHECK(varName) varName > FRONT_ARC && varName < (<180> - REAR_ARC)
#define WEST_CHECK(varName) varName > (0 - (<180> - REAR_ARC)) && varName < (0 - FRONT_ARC)

HitByWeaponId(z,x,id,damage)
{
	var unitPacked, turrPacked, hullArmour, turrArmour, newDamage, unitAngle, hullAngle, turrAngle, tempDamage;
	unitPacked = get PIECE_XZ(turret);
	turrPacked = get PIECE_XZ(flare);
	
	unitAngle = get ATAN(x,z);
	hullAngle = get HEADING;
	turrAngle = get XZ_ATAN(turrPacked - unitPacked);
	
	if (SOUTH_CHECK(unitAngle)) { // South
	  if (SOUTH_CHECK(hullAngle)) {
	    hullArmour = FRONT_ARMOUR;
	    if (SOUTH_CHECK(turrAngle)) 
                  turrArmour = TURR_FRONT_ARMOUR;
              }
              // etc etc etc etc lots of nasty nested ifs
              // some code to return a nice % if penetration > 
              // armour value
              // where armour is some weighted average of 
              // turret and hull
}
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

I'm sorry, I failed at finding any information on HitByWeaponID(x,z,id,damage) beside what you posted in that thread. I probably searched in the wrong places. Can you link or quote to where you said you had directionnal damage fully working, and, better, link me to a unit which has it? I would be very interested into looking at your code and testing it.

I'm not saying that my script will work with fast weapons hitting on center, I'm saying that, in order to test my script, I evacuated that issue by using a slow shot, fired far from target, and with large aoe shot. It doesn't mean the issue is solved for every weapons, just that it wasn't what caused my problem in that particular case.

A huge AOE will just mean that the unit registers a (direct) hit on both sides
Err, what? I don't think the Z and X can have both values at once, so that can't be what you mean. Do you mean that HitByWeap gets called twice with large aoe weapons? My weap had quite a large aoe, yet only one side register a hit. But I guess lots of parameter could influence that. Was slow expanding explosion added to Spring for instance?


But bottomline is, if the engine use the value returned by HitByWeap to change the damage dealt, that's very good, and make directionnal damage, and lots other kind of damage tweak, very easy.
Post Reply

Return to “Game Development”