Page 1 of 1

call Guards function in BG

Posted: Mon Feb 11, 2019 4:32 pm
by agentorangeguy
Which function would I need to overwrite to handle what happens when guards are called? I need to rewrite it to handle being arrested in U6 , and make sure guards cannot be called outside of towns and such. Let me know, thanks!

Re: call Guards function in BG

Posted: Mon Feb 11, 2019 5:32 pm
by Knight Captain
Do you have a Locate function or similar that defines the towns as x,y coordinates?

There is a Usecode Intrinsic for calling the guards and another for canceling the arrest. Those to my knowledge are built into Exult. The more advanced behavior of SI calling specific local guards is via Usecode.

Re: call Guards function in BG

Posted: Mon Feb 11, 2019 6:01 pm
by Donfrow
When you say the guards are build into Exult, is that for both BG and SI? You mention specific guards are via usecode in SI, but is the rest of that via Exult itself? Ie, type of guard is the usecode but guards/arrest is Exult?

Re: call Guards function in BG

Posted: Mon Feb 11, 2019 9:28 pm
by Knight Captain
It seems I may be wrong here. Exult actually uses this in a very helpful way.

The Usecode Intrinsic is UI_call_guards();

I'm testing it now in SI.
Silver Seed keep - No reaction.
Moonshade - Rangers
Fawn - Fawn Guards
Sleeping Bull - UI_attack_avatar();
Monitor - Pikemen
Furnace - Zhelkas has no reaction.
Mad Mage Isle - UI_attack_avatar(); with Erstam killing himself with a botched attack. No skeletons, apparently.

If the bribe is paid, the guards are called off with UI_stop_arresting();

As to how it figures out which to send, I'm not certain.

Re: call Guards function in BG

Posted: Tue Feb 12, 2019 12:28 pm
by agentorangeguy
I wonder though, is there a specific "event" called from the Avatar regarding arrests? Like, death is what, if (event == 4 (or DEATH)) or something then you can call a custom function to handle the death events.

Re: call Guards function in BG

Posted: Tue Feb 12, 2019 12:38 pm
by Knight Captain
There is no Arrest event. You could set a DEATH condition that would move the Avatar to jail if you wanted though.

Re: call Guards function in BG

Posted: Tue Feb 12, 2019 7:11 pm
by Donfrow
If I'm understanding correctly, there are the intrinsics used for calling the guards, but the engine itself is is triggering the the intrinsic calls and are hard coded?

Re: call Guards function in BG

Posted: Wed Feb 13, 2019 10:43 am
by Knight Captain
In my test case I was using the UI_call_guards intrinsic via Erinon's Axe by dropping it (event == UNREADIED). After that everything was via the engine rather than my Usecode. So the determination of which guards to send or even if to send any at all was not mine to pick.

If I had to guess a way to do this, I'd also set a gflag when the guards come. Then if that flag is set when the Avatar dies, another function could be called to resurrect him, heal him, move him to a jail cell, and clear the gflag and any NPC flags on the party.

The gflag would have to also be unset if the bribe is paid.

Re: call Guards function in BG

Posted: Wed Feb 13, 2019 9:59 pm
by Donfrow
Ah thanks, I was wondering since I've never found a way to disable the guard call in my mod if you happen to attach a friendly in the location that used to be a city, it calls the original SI guards. For me, it would be nice to disable that altogether.

That was different than what agentorangeguy was looking for though, so I won't hijack his thread further!

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 11:57 am
by Knight Captain
It's probably worthwhile to keep the thread together.

I imagine Dominus or myself would need to poke into the engine code to see if anything is hard-coded.

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 3:30 pm
by Dominus
I took a look and so far I can confirm that guards will not be called when the place is considered a dungeon.
How guards are called depending on the place is done by looking up what guards are near:
Function at https://github.com/exult/exult/blob/mas ... n.cc#L2675
and in that this will look up what guard shape (gshape) is around https://github.com/exult/exult/blob/mas ... n.cc#L2706
So when there are no guards in the area then no guards will be called.

As to when guards are called is also dependent on the alignment of the crime witness, though I don't completely understand that part.
https://github.com/exult/exult/blob/mas ... n.cc#L2589

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 4:07 pm
by Knight Captain
Might be fun to change the Avatar's alignment and test.

Looks like the locations are hardcoded for SI to determine the guard shape:
https://github.com/exult/exult/blob/mas ... n.cc#L2545

Any non-SI game (BG, any hypothetical new game) the hardcoded location check is skipped. Shouldn't the guards only be called if there is a witness, Dominus?

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 4:32 pm
by Dominus
Yes, but I'm not entirely sure how when partymembers step in as witnesses. There is also a relevant function in actors.cc when you become a bully

And yes, I didn't see the hardcoding for SI cities. I wonder how that came to be. At first glance I'd have thought the other way should work there as well. Probably need to go through the history of gamewin to learn that. But that is no fun ;)

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 9:15 pm
by Donfrow
That's strange. I will have to retest but I could have sworn in my original mod if I attacked a friendly NPC near where Fawn used to be the Fawn guards came and arrested me, despite no NPC's with the Fawn guard shape in the area. I may not be remembering accurately though as it's been awhile.

I will have to retest this sometime to see. Not a big issue for me overall. Since the thread popped up figured I would see what was known about it (you are all wonderful people). I have other things to keep me busy rather than some guards for now.

Re: call Guards function in BG

Posted: Thu Feb 14, 2019 9:30 pm
by Dominus
Yes, for SI it is hardcoded.

Re: call Guards function in BG

Posted: Fri Feb 15, 2019 12:40 pm
by Knight Captain
This is a tricky one because of the way Mods are used. They are still the main game (BG/SI) to the engine even if the map is entirely clean and new.

Re: call Guards function in BG

Posted: Fri Feb 15, 2019 2:35 pm
by Dominus
this could be another area that might need a de-hardcoding...
It probably needed to be hardcoded because the way we did for BG was not sufficient in SI. Different guard types and larger areas that needed to be guarded (think of fellowship camp just near Fawn).
Or no one took a look again :)

AND what I'm unsure about in the code: if there are no guards in the area, it *should* still not call any guards, even if the shape is hardcoded for that area.

Re: call Guards function in BG

Posted: Mon Feb 18, 2019 11:10 pm
by Alexander
The title of this thread got me thinking, it would be neat if YOU could call the guards when people attack you in town (De Snel, Lydia, and Voldin come to mind, as a few examples), and they'd come help. Ultima Online has this feature, which even works if you witness a theft.

It would definitely help with the problem of guards being completely useless in the single-player Ultima games, although I'm sure it would be very difficult, if not impossible, to implement. Maybe it could be a dialogue option when you talk to a guard.

Re: call Guards function in BG

Posted: Tue Feb 19, 2019 1:52 am
by agentorangeguy
Guards WILL show up if you eat food that isn't yours...so it would be very helpful to be able to set regions where they won't show up.. I just tested it. I created some bread, just the Avatar, ate it and guards came rolling in out of nowhere. :O

Re: call Guards function in BG

Posted: Tue Feb 19, 2019 6:52 am
by Dominus
So no guards in the greater area or maybe even guard eggs?
I saw no code that is specific to stealing food...

Re: call Guards function in BG

Posted: Tue Feb 19, 2019 12:50 pm
by Knight Captain
This sort of thing was so problematic that the Usecode for parts of it was disabled in SI. That's why the party never complains about theft. I wonder if the behavior changes if there is no one in the party in your mod, AgentOrangeGuy?

This may be related to the item flag OKAY_TO_TAKE.

Alexander, yes it would be a ton of work. Similar to the idea to have Julia be able to make musket balls out of iron.

Re: call Guards function in BG

Posted: Tue Feb 19, 2019 7:13 pm
by agentorangeguy
I don't know what area it would have been in on the standard U7 BG game, but on my mod it was kind of an area that would have been the deep forest on U7 also. Was only the Avatar in the party. I dropped some bread via ES and no other npcs were around. I ate one then I got swarmed by guards lol.

It would be good to be able to determine where and what type of guards show up as in SI that way there is no weird behavior by the guards out in the middle of the wilderness haha

Re: call Guards function in BG

Posted: Sat Feb 23, 2019 3:29 pm
by agentorangeguy
What are the chances we could get this de-hardcoded so we have more ability to alter how it's handled?

Specifically, what guards show up and where. In BG I think its the standard guard, then another shape for the Trinsic guards. If you code those shapes specifically, you can change how they handle arrests and where they send you, but I'm not sure how to change which areas they do and don't show up