Is it OK to use fireECM?

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Is it OK to use fireECM?

Post by Eric Walch »

Within the source code all the official functions are put in the entityAI file. They are called by a special "_select" function that transfers the AI function to the actual C function. This is done without a parameter or with a string as parameter.

I noticed that all official functions are of type "void". When you use a function in the normal entity file it will also work as long it has no parameters or only a string as parameter.

This far it is clear to me. But Giles used in his stationAI the function fireECM. This is not one of the official AI functions and is of type boolean. This means that on returning it has also a pointer for this boolean on the stack. Is this handled OK or will this in the end result in a stack overflow when used from within the AI machine?

I understood C has no procedures, so maybe a (void) function puts a nil pointer on the stack for the function name. (Pascal makes a difference between procedure and function but C doesn't)

So my question is: is it save to use the boolean AI function fireECM or should this be converted to a legal function in the proper way.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

As fireECM is documented in the wiki (though with the remark "used by stations and hermits to engage ECM") it never occured to me that it could not be an official AI method.

I have used it in own AIs for stations. It should be there in Anarchies.oxp. I have probably used it for ship AIs as well. So if it's not safe for some reason I would have to take it out again. And therefore I'd really like to know it.

By the way: How do ships fire their ECM, if not by fireECM?
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

McLaine wrote:
As fireECM is documented in the wiki (though with the remark "used by stations and hermits to engage ECM") it never occured to me that it could not be an official AI method.

I have used it in own AIs for stations. It should be there in Anarchies.oxp. I have probably used it for ship AIs as well. So if it's not safe for some reason I would have to take it out again. And therefore I'd really like to know it.
Documentation on the Wiki is not always correct. I already removed two non existing functions from the Wiki. (and added a lot more that where not documented before in the wiki). Also the explanation of some functions was completely wrong. Giles used fireECM only for stations but he has also made sometimes mistakes with his own code.

Even if fireECM is not OK it will only leave one boolean on the stack every time it is used. And that is little as only stations are using it now. So even after long time of playing it would hardly be noticeable on the stack.
McLaine wrote:
By the way: How do ships fire their ECM, if not by fireECM?
Ships fire their ECM with the legal command: fightOrFleeMissile. This command looks if a missile is targeted at himself or one of his escorts. If yes it adds the missile to its target list. Then it looks if it has EMC himself.

-If it has EMC, it calls the boolean function fireMissile from within the code with the right parameter transfer and returns from the call without giving an AI message.

-if it has not EMC, it calls the function performFlee with a desired range of 10 000 meters and sends the AI message "FLEEING"

The ship counts on it that the EMC has worked. He will not flee for a ECM hardened missile. Even stations could use this function fightOrFleeMissile to fireECM as long as the station has ECM.

-----

But if this fireECM function would be legal I would ask Ahruman to also declare some similar boolean functions to be legal. (fireMissile, launchEnergyBomb, cloacking-on/off etc.). All of them are already present as boolean functions but I suspect the stack will be corrupted when called from within the AI machine.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Thinking in terms of “leaving things on the stack” isn’t very helpful. The stack is not a concept that’s directly relevant to C or Objective-C language questions.

In principle, a function returning a value could have a different call sequence to one returning nothing. However, the OpenStep/Cocoa/GNUstep library wouldn’t work properly on a system where that was the case. In practice, using a method which returns a value as though it did not is not a problem.
Post Reply