New COB constants?

New COB constants?

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

New COB constants?

Post by Argh »

What, exactly do POW and PRINT do? PRINT looks like it's for debugging (useful!), POW, though... is that for hit-by-weapon?
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Post by yuritch »

POW works like this:
GET POW(2,2) would get you 4, POW(2,3) is 8. POW(x,y)=x^y.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Here's what they do:

POW is 80, PRINT 81, HEADING 82.

yuritch is correct about POW, however, the numbers need to be passed as *2^16, and are returned in such a format. This allows for floats to some degree. i.e. get POW (262144, 32768) = 131072, meaning pow(4,0.5)=2.

PRINT is indeed for debugging only - it prints the 4 get arguments to the chat. The main use of course being to check the value of some variable during the script. i.e.

Code: Select all

var myTest;
myTest = get POW (262144, 32768);
get PRINT (myTest)
Would print:
"Value 1: 131072, 2: 0, 3: 0, 4: 0"
to chat.

HEADING does what it says on the tin - returns unit->heading. This is of course possible already using the trig functions and piece locations, but this is just... neater.
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Post by Guessmyname »

set / get LAND to see if a plane has landed (and to force it to land)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

to see if a plane has landed
What's with GROUNDHEIGHT?


Oh and I would use a macro for POW by the way.

Code: Select all

#define POWER(x, y) get POW(x * 65536, y * 65536)
edit:
They do, I used macros like that before.
Last edited by rattle on 02 Jun 2007, 19:17, edited 2 times in total.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Um, macros don't work that way.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

rattle is right. Good tip too. :-)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

Okay, forget about macros. POWER(25, 0.5) => POW(25*65536,0*65536). Stupid useless, floatless even, scripting language. :(

Now there is another way to do this. I've changed the constant for [] to 65536 (as zwzsg pointed out a couple of times). "get POW([25], [0.5])" is something I could live with.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

No, I mean
A. #define doesn't respect variables, it's a simple replace action and won't see that POW(x,y) means look for POW(<value>,<value>) and move the values to the appropriate places.
B. #define sees its keyword as the first bunch of characters without whitespace, in Rattle's example "POW(x," would be replaced with "y) get POW(x * 65536, y * 65536)".
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Post by rattle »

White-spaces in macros never produced any errors for me.
"#define TEST(x, y) x * y" works as fine as "#define TEST(x,y) x*y".

I actually tested this with flozi's PRINT thing before posting.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

I've used macros like that myself and they work fine too.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

What is variable 79? I seem to be missing that from my STANDARD_COMMANDS_GPL that I built to keep all of this up to date.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Also, can we SET Heading? That'd be downright handy.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Post by yuritch »

Argh wrote:What is variable 79? I seem to be missing that from my STANDARD_COMMANDS_GPL that I built to keep all of this up to date.
Variable 79 is UPRIGHT. All the current set/get constants can be found in rts\Sim\Units\COB\CobInstance.cpp file in the svn.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Argh wrote:Also, can we SET Heading? That'd be downright handy.
Afraid not. I could try implementing that but I hve no idea if it would actually work.

79 is upright, as yuritch said. It is get and set.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Bump for great justice!

Just added:

TARGET_ID (83)
- usage: get TARGET_ID (weaponNum)
- returns the ID of the currently targetted unit by the passed weapon
- returns -1 if no target
- returns -2 if a force fire position target
- returns -3 if it's an intercept target
- returns -4 if the weapon doesn't exist

and LAST_ATTACKER_ID(83)
- usage: get LAST_ATTACKER_ID
- returns the ID of the last unit to attack
- returns -1 if there is no last attacker (unit has yet to be attacked) or last attacking unit is dead.

Just need to check them over with someone and I'll commit them to SVN. Hope they are useful for someone! :-)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Post by FLOZi »

Triple post for HUGE justice!

Just added:

LOS_RADIUS (85)
- usage: get LOS_RADIUS, set LOS_RADIUS to (radius)
- sets the LOS to the given radius, and sets the values held by the unit to that radius (Anyone familiar with the code will see why this distinction is important, otherwise, don't worry about it, it'll behave as you would expect)

AIR_LOS_RADIUS (86)
- usage: get AIR_LOS_RADIUS, set AIR_LOS_RADIUS to (radius)
- As for LOS_RADIUS but for air los.

EDIT: yes, I finally used edit.

set HEADING now works. Just for you Arghy-wargy. :wink:
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

So, if I write code like this:

Code: Select all

Stay_Put(Heading_Then)
{
SET MAX_SPEED 1;
Heading_Then = get HEADING;
sleep 30;
set HEADING (Heading_Then);
}
... will this completely immobilize the Unit?
User avatar
Peet
Malcontent
Posts: 4384
Joined: 27 Feb 2006, 22:04

Post by Peet »

edit: inobservant-peet is inobservant.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Well, yes, if you put those last two lines into a loop, add a few "to"s...
Post Reply

Return to “Engine”