• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Fixed Ship_FireAction Not Working

Pieter Boelen

Navigation Officer
Administrator
Storm Modder
Hearts of Oak Donator
And on the subject of BAD, BAD, BAD bugs, here's yet another one.
Refer to this code from PROGRAM\SEA_AI\AIShip.c:
Code:
void Ship_FireAction()
{
   ref rCharacter = GetEventData();         // we attack this character ---------- ERROR HERE!?!?!? -----------
   ref rMainGroupCharacter = GetEventData();     // commander character for rCharacter
   int iRelation = GetEventData();

// KK -->
   trace("Part 1");
   if (!TestRef(rCharacter) || !TestRef(rMainGroupCharacter)) return;
   trace("Part 2");
   int iCharacterIndex = GetCharacterIndex(rCharacter);
   if (iCharacterIndex < 0) return;
   trace("Part 3");
   int iMainGroupCharacterIndex = GetCharacterIndex(rMainGroupCharacter);
   if (iMainGroupCharacterIndex < 0) return;
   trace("Part 4");
// <-- KK

   ref rMainCharacter = GetMainCharacter();

   trace(GetMySimpleName(rMainGroupCharacter) + " attacks " + GetMySimpleName(rCharacter));

   // if companion - decrease reputation
   if (IsCompanion(rCharacter))
   {
     ChangeCharacterReputation(rMainCharacter, -15); // NK

     if (CheckAttribute(rCharacter, "CompanionEnemyEnable") && sti(rCharacter.CompanionEnemyEnable) == true)
     {
       SeaAI_SetCompanionEnemy(rCharacter); // disconnect companion from our group and set it enemy to us
     }

     return;
   }
This is a nice function that should be executed whenever you attack another ship.
I have noticed in the past that the "CompanionEnemyEnable" functionality no longer works.
Turns out it is worse: NOTHING here works at all. None of the traces I put in are being logged into compile.log even if:
- I fire upon and hit an enemy ship
- I manually fire upon and hit a companion ship
- I manually fire upon a companion ship while the "aim" is 'green'

It seems that the last step did eventually trigger *something* in that function, because I finally managed to get these error logs:
Code:
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
Using reference variable without initializing
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
no DST
RUNTIME ERROR - file: sea_ai\AIShip.c; line: 356
process event stack error
But it doesn't get past the line I marked in the code above, which completely skips the functionality.

Some of the things this function is supposed to be responsible for:
- Reputation hit for attacking companions
- Companions that can turn hostile (escort ships/some Standard storyline quest ships) to do so automatically when you fire upon them
- Bad penalty for attacking non-hostile ships at sea.

I need this function to add a penalty for attacking ships while under a friendly flag to them.


When I found some friendly Dutch ships and fired on them, they DID turn hostile, but I STILL didn't get to see the trace lines I added.
So either this function IS working, but it is bypassing my traces (What? How???) or some other functionality is doing what this function should be doing.

This is terrible.
 
I'd really appreciate if some other people test this as well.

PROGRAM\SEA_AI\AIShip.c and find the section of code I posted above.
Add the lines starting with trace( in my example as these are ones I added in my game version for testing purposes.
You might want to replace trace with TraceAndLog so that this also displays on your screen (I didn't do that on my end, because I've got too many flag-related stuff cluttering my screen at the moment).
Then play the game and try to convince it to call this function.

If you indeed cannot trigger it either and you have access to older modpack versions, try the same thing on those.
I'm pretty sure at some point in the past this did work, so if I'm correct in my finding that it doesn't work anymore, we need to know when it got broken.

This one especially @pedrwyth, @Grey Roger, @Hylie Pistof, @ANSEL, @Jason and @A.H to try out if you have the opportunity.
@Levis, you can probably skip on this for now as I think you have enough to figure out as it is. ;)
 
The only ship I've been escorting recently is the Montanez during testing of "Strange Things Going On", and as false flag recognition is still broken, she turns hostile without me needing to fire at her. I have to be careful not to fire at her by mistake and end up sinking the ship I'm supposed to protect!
 
The only ship I've been escorting recently is the Montanez during testing of "Strange Things Going On", and as false flag recognition is still broken, she turns hostile without me needing to fire at her. I have to be careful not to fire at her by mistake and end up sinking the ship I'm supposed to protect!
But that was an actual Companion Mutiny, wasn't it? That's different code altogether.
We actually have FOUR methods of turning friendly ships hostile:
- Flag relations on Refresh Battleinterface (this is related to false flag detection, but after my rewrite false flags will NOT be detected at this stage)
- Dynamic false flag detection updated every minute based on range between ships (it now appears the skill modifiers for this do strange things with the visibility range, which could be messing things up)
- Companion Mutiny (based on reputation of the companion character OR when hoisting a flag that is hostile to a companion ship; I made a change to this last part so that ONLY applies to quest traders and no other ships)
- Firing on friendly ships; any regular friendly ship WILL turn hostile when you fire on them, but companion ships will ONLY do this if this is enabled for them (applies to quest traders and some Standard Storyline quest ships)

These are all independent systems as far as the code is concerned.
The first two are vaguely related and are what I am currently rewriting. The last one is what my bug report here is about.

I'm pretty darn sure that I put code in place to have Companion Mutinies based on flag ONLY for quest traders and not for any other companions.
That is also what the added dialog option is for to tell them you'll be using a false flag to prevent them turning hostile. This does NOT affect quest ships as they shouldn't care about this in the first place.
They did at some point, but that was months ago.

Actually, the reason for me using Companion Mutiny for Quest Traders is BECAUSE of the bug I report in this thread.
In the past, firing on a companion ship would turn it hostile. But that functionality appears to be broken, so I had to implement something else to make it work.
It would be nice if the original functionality would work as well though.

You DID play through this scene very recently, didn't you? Was the Montanez your companion at the time you are talking about?
If she was not and you were flying a false flag, it is the normal bugged behaviour affecting you there. Apart from the visibility range problem, that isn't a huge concern as I am already well on my way to fixing that.
If she WAS a companion at the time, but mutinied, I really don't understand as that should no longer be possible. But again, as far as the code is concerned, that is still a very different problem.

And of course I do want them all to be fixed properly very soon. But I can't give us the system we want while my problem from the opening post still stands. :modding
 
You DID play through this scene very recently, didn't you? Was the Montanez your companion at the time you are talking about?
If she was not and you were flying a false flag, it is the normal bugged behaviour affecting you there. Apart from the visibility range problem, that isn't a huge concern as I am already well on my way to fixing that.
This is correct. Montanez became hostile when I was flying a false Portuguese flag when I arrived at Barbados and found her plus the two animist ships.

Where is 'Ship_FireAction' supposed to be called?
 
This is correct. Montanez became hostile when I was flying a false Portuguese flag when I arrived at Barbados and found her plus the two animist ships.
Ah, that's just the bugged false flag detection and not a new problem. That's a relief.

Where is 'Ship_FireAction' supposed to be called?
The code itself is in PROGRAM\SEA_AI\AIShip.c . As far as I can tell, it isn't being called anywhere at all, which means it is probably a stock game function that is called through the engine where we can't check nor access it.
It is doing something though, because I know it used to work and even if I didn't manage to trigger the traces, I did get error logs from it during play, which means it must have been called somehow.

This is why it needs to be tested by other people to confirm if it is just a problem on my end or a general one.
And if it is general, we need to find when it was introduced so we can track down the changes that broke it and hopefully restore this to its original functionality.
That'd be a very great thing because then we can actually execute the plan you suggested! :woot
 
I have to ask if this is the right way to change the code
 

Attachments

  • AIShip.c
    217.9 KB · Views: 131
I have to ask if this is the right way to change the code
Looks right to me! You might want to swap out "Trace" with "TraceAndLog" so you'll see it on the screen too if and when it happens.
Thanks for trying this. :cheers
 
DAMMIT! I just disabled EVERYTHING in that function and the ships I fire on STILL turns hostile.
So whatever is turning them hostile, apparently it isn't the function that looks like it is meant for just that purpose.
For crying out loud! :modding :modding :modding
 
I'm testing old versions from my archive now. This function DID get called properly in the stock game.
It is bugged already in Beta 3. In fact, the ship I attacked didn't even turn hostile. They seemed to be quite happy with me taking them out. Ohh
 
WE ARE BACK IN BUSINESS!
This section of code:
Code:
void Ship_FireAction()
{
   ref rCharacter = GetEventData();         // we attack this character
   ref rMainGroupCharacter = GetEventData();     // commander character for rCharacter
   int iRelation = GetEventData();

// KK -->
   if (!TestRef(rCharacter) || !TestRef(rMainGroupCharacter)) return;
   int iCharacterIndex = GetCharacterIndex(rCharacter);
   if (iCharacterIndex < 0) return;
   int iMainGroupCharacterIndex = GetCharacterIndex(rMainGroupCharacter);
   if (iMainGroupCharacterIndex < 0) return;
// <-- KK
Should be this instead:
Code:
void Ship_FireAction()
{
   // LDH restored 23Jan09
   aref rCharacter = GetEventData();         // we attack this character
   aref rMainGroupCharacter = GetEventData();     // commander character for rCharacter
   int iRelation = GetEventData();

// KK -->
   if (!TestRef(rCharacter) || !TestRef(rMainGroupCharacter)) return;
   int iCharacterIndex = sti(rCharacter.index);
   if (iCharacterIndex < 0) return;
   int iMainGroupCharacterIndex = sti(rMainGroupCharacter.index);
   if (iMainGroupCharacterIndex < 0) return;
// <-- KK
As far as I can tell, that returns all this code to full working order.
WITHOUT error logs this time, I might add.

That means I can finally continue with getting the false flag stuff to actually do some sensible things now.
 
As an unfortunate side-note: This function is NOT, as I had hoped, executed for EVERY ship you attack.
This is exclusively for ships that are NOT hostile to you. Which means it doesn't do anything when you have been recognized and I can't use it for that.
Different solution required....
 
To all, but especially @Grey Roger:
If you have any suggestions on how to handle this in a simple way that doesn't involve me having to add code for every cannonball impact, I'd greatly appreciate it.
What if there IS no bad effect when you fire the shot, but only after you sank/captured a ship while still under a friendly flag?

This is all assuming that eventually all gets into proper working order, of course. :facepalm
 
Why not use the function " Ship_HullHitEvent " or something like that from AIShip.c ?
 
Why not use the function " Ship_HullHitEvent " or something like that from AIShip.c ?
That's the one I was thinking of too. Probably the only option we've got left. :yes
Of course that would need an attribute added to the ship so it all happens only once, otherwise it becomes a bit overkill.

Need to think also of what to do when boarding an enemy ship while flying a friendly flag.
Would be nice to just call UpdateRMRelation and have that take into account whether your flag is friendly to them or not to define "act of piracy" too.
 
As an unfortunate side-note: This function is NOT, as I had hoped, executed for EVERY ship you attack.
This is exclusively for ships that are NOT hostile to you. Which means it doesn't do anything when you have been recognized and I can't use it for that.
Different solution required....
Why is that a problem? If the other ship attacked you while you were flying a friendly flag then you're defending yourself. You should only get the full negative effect if you're the one who initiates hostility by sailing up to a friendly ship and attacking it without provocation.
To all, but especially @Grey Roger:
If you have any suggestions on how to handle this in a simple way that doesn't involve me having to add code for every cannonball impact, I'd greatly appreciate it.
What if there IS no bad effect when you fire the shot, but only after you sank/captured a ship while still under a friendly flag?
That would do. You normally get the reward or penalty to your relations (and reputation gain if it was a governor's ship hunting quest) after you capture or sink the ship, so you may as well handle any other consequences at the same time. It also has the advantage that you don't get the massive penalty if you accidentally hit a friendly ship when you were aiming at a genuine enemy, only if you deliberately attack the friendly ship and follow the attack to its conclusion.
 
Why is that a problem? If the other ship attacked you while you were flying a friendly flag then you're defending yourself. You should only get the full negative effect if you're the one who initiates hostility by sailing up to a friendly ship and attacking it without provocation.
With this function back to normal working order, the penalty for firing on friendly ships has already returned.
This involves a reputation hit and also turns the nation whose ship you attacked hostile. That is something that should have already been working, but got broken in Build 14 Beta 3.

If you were discovered for flying a false flag, then the other ship is already hostile and this functionality does not get called at all (I checked).
So firing back would give you no hit to relations or reputation.

That would do. You normally get the reward or penalty to your relations (and reputation gain if it was a governor's ship hunting quest) after you capture or sink the ship, so you may as well handle any other consequences at the same time. It also has the advantage that you don't get the massive penalty if you accidentally hit a friendly ship when you were aiming at a genuine enemy, only if you deliberately attack the friendly ship and follow the attack to its conclusion.
Excellent! It can all be handled in the same function that is already being called for that anyway and we don't need extra tricks to determine if you fired on a ship with attributes to prevent it from being done more than once.
I'll add it to the code posted here: http://www.piratesahoy.net/threads/...-from-player-actions.25514/page-2#post-513055
Probably something involving:
Code:
GetNationRelation(GetCurrentFlag(), iNation) != RELATION_ENEMY
And then adding extra points to iActOfPiracy and NOT resetting it to 0 if you happen to have a LoM.

So should you lose ALL your LoMs if you do that? Or just the ones from nations allied to the one you attacked?
Lose points with ALL nations? Or just as normal? We can SetServedNation to PIRATE as well.
 
How about this?

Lose all your LoM's. If you have a served nation then you only have one LoM and you've just disgraced it, your nation wants nothing more to do with you - lose the LoM and naval status if you had it. If you have multiple LoM's then you have no served nation and are using them as a cover to legitimise piracy, and you've just blown that cover. (At least, that's how the nations see it. Maybe you've been using multiple LoM's to gain maximum reward for hunting pirates, but now you've effectively become a pirate.)

The nation you attacked and its allies all become hostile. Anyone else becomes wary unless their relation with you was already below wary - they don't care about the ship you attacked but you're untrustworthy and they don't know what you're going to attack next. Pirates, if they were previously hostile, become wary - you've shown yourself to be a pirate but haven't yet joined Pirates, though now they're not hostile so the way is open for you to do so. Meanwhile you have no served nation.
 
Pirates, if they were previously hostile, become wary - you've shown yourself to be a pirate but haven't yet joined Pirates, though now they're not hostile so the way is open for you to do so. Meanwhile you have no served nation.
I'd set the Pirates to Friendly which also sets your Served Nation to PIRATE.
NO served nation is not an option. And you already get that effect with the Pirates for betraying a single nation.
As I understand doing so under a friendly flag is a much worse offense than that, whatever happens to the pirates should not be less than what happens for a single betrayal.
 
From "globals.c":
Code:
#define PRIVATEER_NATION 8
#define NEUTRAL_NATION  9
#define UNKNOWN_NATION  10
#define ANY_NATION  11

#define PERSONAL_NATION  -1
I'm not sure what "NEUTRAL_NATION", "UNKNOWN_NATION" and "ANY_NATION" are used for, but it seems to me that "No served nation" ought to be an option with one or other of them. ;) Otherwise perhaps you could set served nation to "Personal", provided that doing so doesn't involve automatically hoisting the "Personal" flag.

In any case, you're right that attacking under a friendly flag is a particularly dishonourable way of betraying a nation and should get at least the same effect. But I still think that to get Pirate as served nation, you ought to need to go and join them; doing something naughty just opens the door for you.
 
Back
Top