ToME: the Tales of Maj'Eyal

Everything about ToME
It is currently Fri Sep 20, 2019 5:34 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Sep 22, 2015 9:10 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 62
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.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 10:01 pm 
Offline
Sher'Tul

Joined: Mon Jun 23, 2014 11:50 am
Posts: 1439
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?


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 10:58 pm 
Offline
Perspiring Physicist

Joined: Sun Sep 09, 2012 7:43 am
Posts: 5931
No idea on this one.

_________________
My feedback meter decays into coding. Give me feedback and I make mods.


Top
 Profile  
 
PostPosted: Tue Sep 22, 2015 11:28 pm 
Offline
Uruivellas

Joined: Wed Apr 30, 2008 5:55 pm
Posts: 708
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. :)


Top
 Profile  
 
PostPosted: Wed Sep 23, 2015 10:02 pm 
Offline
Higher

Joined: Wed Jul 22, 2015 8:12 pm
Posts: 62
Thanks guys. My current setup is to superload Player:act() and then check the game.pause flag (and my ai flag) like so:
Code:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group