AI TOOLS ... Is AI modding switch off in the engine?

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

AI TOOLS ... Is AI modding switch off in the engine?

Post by Merr »

Pip, (or adherbal)

I've been trying to troubleshoot this for awhile ...

I see that the AI.BSF files goes into the my_campaign/AI folder ... ok.
Now, the script I'm tweaking is in the AITools.bsf ... well, that folder is only in the main directory and it's a no-no to tweak that ... ok.
So, I copy the script over to the AI.bsf but I have to rename the Function for duplicate problems. That's not good because I need to "add" code to a function, not create a new function.
The comments at the top of the AITools reads ;

// works in conjunction with mission scripting, Mission scripting overrides this so static units will nto advance and fire.
// called for every unit, multiple times. It gets called every time the AI does something. E.g. If it spots a new unit, if it comes under attack. See AI.bsf for details.

Ok, I've tried this in mission scripting inside my units bsf .... no luck.

Basically, I've tried a bunch of stuff but here are the details on what I'm doing ....

In the AITools.bsf there is a function ... FUNCTION AI_DoAttack(side, team, me, target)
For my new Sharpshooter unit I want the AI German_Sniper to use SNIPERSHOT when attacking ... code added before other conditions to ensure priority ;

Code: Select all

if(canFire != 0)
	{
		if( GetAttrib(me, "Sharpshooter") == 1 )
		{
			canFire = CallUnitFunctionDirect(me, "CHECK_UNIT_SHARPSHOOTER", me, GetUnitX(target), GetUnitY(target), target) ;
			//Log ("canFire", canFire) ;

			if ( canFire == 0 )
			{
				ClearUnitDestination(me) ;
				// fire HE...
				CallUnitFunctionDirect(me, "UNIT_SHARPSHOOTER", me, GetUnitX(target), GetUnitY(target)) ;
				//Log ("firing HE ", me, unit ) ;
				fire = 1 ;
			}					
		}
	}

 
The code works fine (no errors). My unit has the SHARPSHOOTER ability (basically the SniperShot but can be used at experience level 0) ... so everything should work ... in theory, but doesn't. The AI Sniper will always use HE fire.

I feel like the AI modding switch is turned off not recognizing the AI folder or any AI changes.

Any ideas?

Rob

EDIT : I saw the comment //Log ("firing HE ", me, unit ) ;
.... so I'm thinking ... do I have to create a Log? ... somewhere? I'm thinking NOT at the same time since the fire=1 is also use for AP and all it's doing is returning a value of 1 to satsify the function.
pipfromslitherine
Site Admin
Site Admin
Posts: 9863
Joined: Wed Mar 23, 2005 10:35 pm

Post by pipfromslitherine »

If you want to make use of a script used by the main game, but want to tweak it, simply copy the script into the same directory as your script that wants to include it (so in this case, the AI folder). The code always looks in the same directory as the script it is parsing first when including them.

That should allow you to tinker without any issues of replicated functions, because it will never include the core install version of the script file.

Hope that helps

Pip
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

Pip,

Hmm, I thought I tried this with no luck ... I'll give it another go ... Does the AI folder need a $DEFAULT.BSF to include the AI and AITools or not? I've tried that but it appears not to make a difference.

I'll try some more ...

Thanks!

Rob
pipfromslitherine
Site Admin
Site Admin
Posts: 9863
Joined: Wed Mar 23, 2005 10:35 pm

Post by pipfromslitherine »

Nope - it loads up the AI file and it should then get the AITools file from the same directory.

Although... it looks like the AI script actually includes the tools.bsf file, which is a combo of all the utility scripts that are used. But looking at the code what should happen is that any files it includes, it first looks in the directory the initial including file uses (in that case the AI folder). So it should be grabbing your local AITools anyway.

What exactly are you seeing happen?

Cheers

Pip
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

Ok ....

I did a quick test to see if the AI folder is being read properly by creating a bug in the AITools bsf ... it cried foul ... that's good !

Coincenditally, the bug I used in the AItools was commenting out the HE fire routine and the error directed me to the ThreatMap .... hmmm, so it now looks like I need to consider other AI Functions that drive it's logic. At least I'm advancing in my troubleshooting.

BTW, the problem was that the German_Sniper always used HE fire when logically it should use SNIPERSHOT.

Again, there's more logic buried in there somewhere that I'm missing.

The good news is that it's not your fault :P ... that is, the engines fault I mean :wink:

Thanks for the quick reply!

Rob
pipfromslitherine
Site Admin
Site Admin
Posts: 9863
Joined: Wed Mar 23, 2005 10:35 pm

Post by pipfromslitherine »

The three key functions are the first 3 in AITools - they select a target, work out how close to get, and then decide how to attack it, respectively. You'll probably want to add a check in AI_DoAttack which asks whether the sniper action is available, then uses it if it is available.

Awesome that you are delving so deep! A sniper mission is a great idea.

"Sniper!" ;)

Cheers

Pip
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

pipfromslitherine wrote: Awesome that you are delving so deep! A sniper mission is a great idea.

"Sniper!" ;)
Pip,

SUCCESS ... I figured it out ... now my AIsharpshooter (sniper_unit) will use snipershot!

After diving into how the AI think's and troubleshooting left and right I narrowed it down to the code that I posted above. When I called the function "CallUnitFunctionDirect" (both instances), the parameters didn't concur with the function. Perhaps I should have uncommented the Log and this would have debugged my error?

I created a monster ... it's alive, alive! Pretty satisfying since I'm not a programmer.

My next step is programming the AI sniper to use SniperShot as reaction fire !! This is going to be pretty ugly for the human player ... with a 40 point hit to morale it will stop a squad dead in it's tracks ... and he won't know where the shot came from!
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

pipfromslitherine wrote:Nope - it loads up the AI file and it should then get the AITools file from the same directory.

Although... it looks like the AI script actually includes the tools.bsf file, which is a combo of all the utility scripts that are used. But looking at the code what should happen is that any files it includes, it first looks in the directory the initial including file uses (in that case the AI folder). So it should be grabbing your local AITools anyway.
Pip,

I hate to bring up old ground but I discovered something that is (perhaps) something you didn't intend on happening. I got it to work (again) but I thought you need to know.
The problem relates to the date stamp of the AI.BSF ... I'll explain ... (hopefully you can follow my babbling)

Ok ... I was updating my Rescue_Prisoner scenario to v1.3.10 ...

Now, in my AI folder, I have two files ... AI.BSF, AITools.BSF ...
The AI.BSF I'm using is "unmodified" ... however, to get it to recognize the AITools.BSF I had to edit it (saving it with new date stamp) back when I had the initial problem.
The AITools.BSF has my new code in for the sniperAI ... no change required since you guys never changed this in 1.3.10.

Now, you guys changed the AI.BSF in v1.3.10 ... Well, I thought, no problem, I could simply copy/paste the new AI.BSF over from core ... NOT !

What happened was ... Since the program read the AI.BSF date stamp it assumed no changes and it never continued to read my modified AITools.BSF.
Basically, what happened (in my scenario) is that the AI_Sniper stopped using SniperShot because it never read the AITools.bsf.

To solve the problem ... I added the new code from v1.3.10 to my AI.BSF, this saved it with a new date/stamp ... viola!! She works now.
I'm pretty sure that simply copying over the new AI.BSF and saving it with a new date/stamp could have solved this too.

What I'm trying to say ... It appears that ;
(1) The AI.BSF file is required in AI folder if you make changes to the AITools.BSF
(2) The AI.BSF has to have a date/stamp not equal to the current release.

Now, there is another file called .... vssver.scc .. having this file in my AI folder made no difference to my solution (I'm not 100% sure, like 99% sure).

Just thought I'd let you know ... no big deal, just for future reference when others start farting around with BSF's.
pipfromslitherine
Site Admin
Site Admin
Posts: 9863
Joined: Wed Mar 23, 2005 10:35 pm

Post by pipfromslitherine »

Hmm - not quite sure what you mean. Are you saying that if you don't resave (but not modify) the file then it won't find the include file in the same directory?

Cheers

Pip
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

pipfromslitherine wrote:Hmm - not quite sure what you mean. Are you saying that if you don't resave (but not modify) the file then it won't find the include file in the same directory?

Cheers

Pip
Correct ..... Meaning if I simply move the AI.BSF from core to my AI folder ... it won't read the AITools.

You can duplicate this on your end (you got my beta) ...

Make a new scenario .... Add a US INF and add a GermanSniper beyond 6 tiles ... Move your INF to within 6 tiles (not closer than 2) ... wait for Sniper to shoot, he'll SNIPE (next turn with german)
Now, swap my AI.BSF with the new one (from core) .... run scenario again .... SNiper won't use SniperSHot ... appears to not be reading the AITools (which contains the code to have Sniper use SNipershot).

Then , open up the new AI.BSF ... add a comment (so NotePad++ will recogize a change and allow save), save it (new date), and run it ... Sniper uses SniperShot.

Funny huh?
Merr
Captain - Heavy Cruiser
Captain - Heavy Cruiser
Posts: 903
Joined: Mon Aug 16, 2010 2:00 pm

Post by Merr »

Pip,


Hmmm , I just ran my own test and it works dispite new AI.BSF having same date/stamp .... :oops:

Sorry for that .... I could have sworn it didn't work ..... The AI has a mind of it's own that's driving me crazy !!

At least we can chock this one to "operator error" .... again :oops:

Geez, I'm a pain in the butt eh?
Post Reply

Return to “Battle Academy : Modders Corner ”