Revealing unit when unit is attacking

Revealing unit when unit is attacking

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

Post Reply
GamerSg
Posts: 13
Joined: 23 Aug 2010, 09:50

Revealing unit when unit is attacking

Post by GamerSg »

Im modifying Spring 1944 atm and am trying to make artillery units which have very very long firing range, to be revealed when they fire even if the opponent does not have any unit in range of the artillery. This behaviour is similar to starcraft1 where siege tanks on high ground or far range would be revealed when they fired.

Where should i look to script this behaviour in?
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Revealing unit when unit is attacking

Post by aegis »

you can call Spring.SetUnitAlwaysVisible from a gadget to reveal the unit when it fires, then use a timer to call it again to hide the unit after a bit

http://springrts.com/wiki/Lua_SyncedCtrl#Unit_LOS
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Revealing unit when unit is attacking

Post by KDR_11k »

Alternatively you can manually override the LOS state with some call-ins. Still, I think it would be a better idea to instead show artillery warnings on the location of the artillery without revealing the specific unit (kinda like Micro Modules' artillery warning, except focused on the launcher instead of the target).
GamerSg
Posts: 13
Joined: 23 Aug 2010, 09:50

Re: Revealing unit when unit is attacking

Post by GamerSg »

Thanks for the help guys, ill look into your recommendations.
GamerSg
Posts: 13
Joined: 23 Aug 2010, 09:50

Re: Revealing unit when unit is attacking

Post by GamerSg »

Just another question,

I do not seem to be able to locate a callin which is related to a unit firing.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Revealing unit when unit is attacking

Post by Argh »

Call it from the Unit's script, or you can use projectileCreated()

(caution, you will need to filter it very carefully or it will eat a lot of CPU)
GamerSg
Posts: 13
Joined: 23 Aug 2010, 09:50

Re: Revealing unit when unit is attacking

Post by GamerSg »

I agree, using the unit script should be far more efficient instead of using a callin and checking everytime any unit fires.

However i believe that the unit scripts are not coded in Lua but rather a C like language. I have been unable to locate any documentation/tutorials on unit scripting. Anyway, i opened up my unit's script and tried adding the visibility which (expected) could not compile.

Code: Select all

FireWeapon1()
{
	emit-sfx PAK40_Muzzleflash from flare;
	emit-sfx PAK40_MuzzleDust from flare;
	move barrel to z-axis RECOIL now;
	//Fire teh weap0n!!!11
	CREW_FIRING;
	get DO_SEISMIC_PING(15);
	sleep 100;
	move barrel to z-axis [0] speed RETURN_SPEED;
	//Now reload...
	CREW_RELOADING
	set STEALTH to 0;
	set VISIBLE to 1;  //I added this line
	sleep VISIBLE_PERIOD;
	set VISIBLE to 0; //I added this line
	set STEALTH to 1;
}
Mainly the line set VISIBLE to 1;
Scriptor complains that there is no variable VISIBLE defined.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Revealing unit when unit is attacking

Post by Argh »

They're (mainly) still using BOS. You need to make changes and compile the script with Scriptor.

Calling Lua (to set AlwaysVisible until a gameframe timer expires) is straightforward:

Code: Select all

lua_MakeMeVisible(arg) {return 0;}//This empty script hooks into Spring's Lua system

FireWeapon1()
{
   emit-sfx PAK40_Muzzleflash from flare;
   emit-sfx PAK40_MuzzleDust from flare;
   move barrel to z-axis RECOIL now;
   //Fire teh weap0n!!!11
   CREW_FIRING;
   get DO_SEISMIC_PING(15);
   sleep 100;
   move barrel to z-axis [0] speed RETURN_SPEED;
   //Now reload...
   CREW_RELOADING
   set STEALTH to 0;
   sleep VISIBLE_PERIOD;
   set STEALTH to 1;
   call-script lua_MakeMeVisible(time);//This calls a Lua function MakeMeVisible() with the argument "time", the amount of time to stay visible after firing
}
In Lua, to deal with calls from COB, you just need to set up the function MakeMeVisible in a Gadget function, and this:

Code: Select all

function MakeMeVisible(unitID,unitDef,team,time)
--do Lua logic here that passes to something dealt with in gameFrame
end
gadgetHandler:RegisterGlobal("MakeMeVisible", MakeMeVisible)
...makes Spring able to handle COB-->Lua callout behavior correctly.

Now you just need to write a Gadget timing loop for this, which (if you're not familiar with Lua yet) will be a bit of an adventure, as it will involve dealing with a table. Good luck :-)
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Revealing unit when unit is attacking

Post by Google_Frog »

If you want to do it the easy way convert the script to lua. Unit scripts are in Cob because they were written before lua unit scripts were available.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Revealing unit when unit is attacking

Post by FLOZi »

If you want to do it the easy way in s44, modify game_ammo.lua to set the unit always visible when it detects it has fired (Up to a 3 second delay with this method though :P )
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Revealing unit when unit is attacking

Post by KDR_11k »

IMO just use the explosion of the shot as the trigger so there's no early warning, only a position to counter-battery fire at.
Post Reply

Return to “Game Development”