• Welcome to Freedom Reborn Archive.
 

M25 AI in a mod situation

Started by Lunarman, May 12, 2008, 04:21:08 AM

Previous topic - Next topic

Lunarman

For those rare characters that don't fit any built-in AI or for supervillains that you want to have an extra edge, is it possible to have enemies in a campaign that are controlled using M25's AI?

If so, could you tell me how to do it? Do they use normal M25 AI files or is their AI written in a seperate file elsewhere?

Finally, I'm sure I've read somewhere that it's too processor intensive to have whole armies of villains controlled by M25's AI. Is that right?

Thanks a lot

Lunarman

p.s. Maybe, just maybe I'll finish the next issue of my mod soon ;)

Previsionary

yes, enemies can use m25 ai in mods. There're a few threads detailing how to do it in the scripting forum, iirc, and i thought it was added to the ffx manual.

The AI is made in the same way all custom AIs are made. If you run the m25 generator from the mod, it'll automatically be added to the correct file (m25aidata) otherwise the ai data will be in the heroes folder (assuming it's a custom character and not built in). Speaking of which, m25's campaign add on, the name escapes me, takes care of a good deal of that stuff itself if you have the preliminary stuff out of the way.

Yes, if too many characters are running around with custom AIs, it will take its toll on a person's pc, especially if they're using a bunch of different setups. However, that really depends on how many enemies you plan to have on screen at one time. If it's 15 or more, you may want to consider which AI you use, I'd think.

Lunarman

Thanks for the tips Prev. I couldn't find it in my FFX manual but i'll try just running the generator and then checking it all goes into the right folder.

Do I need to set a certain built-in ai in order for M25's AI to take over, or will it overide any built in ai automatically?

thanks

Previsionary

nope, from what I remember, you can set it to whatever and if you set up the ai correctly and call the correct hooks in your mission script, then the AI will automatically take over. I'll see if the thread is still around as it may have been erased when FR was on vacay.

Lunarman

Right, I ran him through the Rumble room AI generator and I've checked to see if the AI tactics have been written into the m25data file, they have. However the AI still doesn't run in my mission, what hooks do I need to call?

All I've got FFX related atm is:

import js
import ff
import cshelper
import event
import ai
import goal
import random
from js import *
from ff import *
from cshelper import *
from event import *
from ai import *
from goal import *
from random import *
from ffx import *

def OnPostInit():
ff.RENDER_WARP = 1
print 'postinit'
cshelper.play(opening_cs,'intro')

def OnPrecacheObjects():
print 'precache'

def OnMissionWon():
print 'Mission Won'

def OnMissionLose():
print 'Mission Lost'

def start_mission():
war()
#m25ai.SetupAI()
InitScripts()
setMission(4)
FFX_InitMission()
print 'fight started'


#m25ai.SetupAI() was my attempt to get things working but it requires a name in the brackets, and I don't know what.

Thanks a lot

Lunarman

p.s. my search on the wiki and scripting forum didn't turn up anything.

Previsionary

Ok, I'm going off my memory here, so bare with me.

From what I can remember, You need to call the following hooks before and during 'OnPostInit':

  • from ffx import *
  • setMission()
  • InitScripts()
  • FFX_InitMission()

and somewhere after Initscripts(), but still during OnPostInit() call:

heroes = getAllHeroes()
    for h in heroes:
    SetupAI(h)
    AIDisableCustom(h)


  • and you may need to call SetupAI(h) when you're ready to activate it.


GogglesPizanno

I'm at work right now, so this is all from memory... but one option would be to loop through all the characters/villains on a mission and call the "setupAI(charactername)" for each one within the loop. Though this would only initialize the AI for existing characters at the mission start.

Something Like:

def setupMissionCharacters():
     #ffx has functions defined for getting villains, heroes, minions etc...
     for char in getAllVillains(checkLiving = 1, clones = 1):
          m25ai.SetupAI(char)
          #any other code you need to apply to character Setup

         
If during the mission, you spawn any new characters, they will need to call that function for them as part of the spawning code if you want them to use the AI as well.

*EDIT*
:ph34r: by Prev!

Lunarman

many thanks to the both of you. I'll try that

M25

Yes, you need to call SetupAI(char) to get a character to use the AI.

You also need to call SetDefaultTeam(char) for all characters, including heroes, or the custom AI won't target them.

For cutscenes, use AIPeace() and AIWar() in place of peace() and war().



stumpy

(Sorry if this isn't the exact same question, but it's related.)

Can I set things up so that the M25 AI runs the FFX-spawned NPCs (from SUMMONER, PRIVATE ARMY, etc.), but leave the in-game AI to run the built-in baddies?

I have a custom with SUMMONER who summons a custom character minion in the FFX campaign (the modified FFvT3R campaign), but the minion just stands around. I assume this is because the M25 AI isn't active and isn't assigning teams properly to the baddies, so my minion doesn't know to fight any of them. (I have set FFX_RULES_CAMPAIGN_M25AI=1 in ffxextras.py, but that doesn't fix things by itself.)

To test, I did try calling SetDefaultTeam(c) for all of the chars before summoning the minion, but there must be more to it than that. Even though AreEnemies() returns 1 for him and a given baddy, he still has only "AI: mobjdummy_2 no tactic chosen this cycle." in the log. (FWIW, Target_GetCurrentTarget(char) returns 'wraith_1_1' as I would expect, but Target_GetTargetList(char, TARGET_ENEMY) returns []. I have the feeling that latter is a big clue as to what I am doing wrong...)

M25

It is perfectly fine to have custom AI for some characters and use the built-in AI for others.  If a character doesn't have an AI definition, or the python script either disables the custom AI for that character or simply doesn't turn it on to begin with, then the custom AI won't run. 

The target list is used to force the AI to go after specific targets/objects/civilians (useful for campaigns or scenarios) so it is ok if it is empty. 

It sounds like the AI is functioning, but when it runs through the AI definition for that specific character it can't find a tactic to apply.  Is the wraith_1_1 too far away to interact with?



stumpy

I think this is working for me now. I added a couple lines to ffx.py

  • In callM25AI_InitScripts() to set teams for already-spawned characters when FFX gets going.
  • In initAttribsForChar() to conditionally set teams for newly-spawned characters whose team is still 0.
I'm not sure that's perfect placement for the team-setting, but it hasn't caused any trouble, so I am happy with it.

Thanks.  :thumbup:

M25

The placement sounds right.  Maybe we can get this into the next ffx release.



stumpy

Good idea. I will submit it to the group this weekend, after I can play around with it a little more. I am tempted to add a little control (similar to the clone control or PRIVATE ARMY control) to the SUMMONER characters, too.