Looping around extended player actions

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Charidan
Higher
Posts: 64
Joined: Wed Jul 22, 2015 8:12 pm

Looping around extended player actions

#1 Post by Charidan »

I'm trying to make an AI that runs the player. I want it to be able to cause the player to take consecutive actions. The problem is that if I just try to write a loop, the game never updates the turn and so I just block execution.

What do I need to overwrite/hook/check to make sure that a move I have entered is executed fully, or alternately what do I check to make sure the game is waiting for player input? Ideally there is a function called when the game waits for player input that I can hook/superload to call my AI functions.
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.

Radon26
Sher'Tul
Posts: 1439
Joined: Mon Jun 23, 2014 11:50 am

Re: Looping around extended player actions

#2 Post by Radon26 »

Here goes stupid idea coming from someone who never coded anything in this game:

have you tried to make it skip a turn and then, if condition still isn't met, repeat, and if it is, stop?

HousePet
Perspiring Physicist
Posts: 6215
Joined: Sun Sep 09, 2012 7:43 am

Re: Looping around extended player actions

#3 Post by HousePet »

No idea on this one.
My feedback meter decays into coding. Give me feedback and I make mods.

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: Looping around extended player actions

#4 Post by grayswandir »

You probably need to take a look at Player's :act function, as that's what waits for user input, I believe. So, like, you put a wrapper around it that, if a flag is set, calls the npc act function with a given ai (somehow) instead of the player one.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Charidan
Higher
Posts: 64
Joined: Wed Jul 22, 2015 8:12 pm

Re: Looping around extended player actions

#5 Post by Charidan »

Thanks guys. My current setup is to superload Player:act() and then check the game.pause flag (and my ai flag) like so:

Code: Select all

local old_act = _M.act
function _M:act()
    old_act(game.player)
    if (not game.pause) and _M.ai_active then
        player_ai_act()
    end
end
And it's mostly working. For some reason now, every time I try to rest from the AI it gives me an error that a dialog is up so it can't rest. This is partially true, because the "You are resting..." dialog is open, except that shouldn't stop resting. If I can clean that up so the AI can rest again, I'll have a fully-functional (basic) AI that rests, auto explores, and walks into enemies it can see.

EDIT UPDATE: I added "and not game.player.resting" to the condition, and it still SAYS resting stopped because of dialog, but it seems to rest properly anyways. However, I have now learned that hotkeys don't work while the AI is active because of how I interact with the act() function, so I can't stop the AI once it's on, and it starts autoexploring back and forth between the level entrance and exit. Progress!
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.

Post Reply