Jun. 26th, 2021

Work Post

Jun. 26th, 2021 02:46 am
relee: Picture of Relee Starbreeze, Wizard (Default)
2:47am - Well, it's past my bedtime, and I'm in bed, but I'm thinking, and I want to think here in my journal where it'll be recorded for later.

I know that in my Roguelike project I'm using Actors for the Player character/s, NPCs, Enemies, and even Items and Special Effects. I want them to have different abilities that interact with the environment and other actors, and I want them to know how and when to use those abilities.

Up until now, I had hard coded this in the Actor subclasses Player and GreenEnemy. But when I pivoted the Map system so hard, it collided with the Actor system in a way that the whole thing needs to be redone, and why not redo it right, you know?

Ideally the stats, abilities and AI of the Actors should all be in a seperate file. Something I can easily edit to add or remove or modify abilities. Probably some sort of text file, or json or xml maybe.

These would be loaded into the game at runtime. I'm not sure exactly how to do it though, and that's what I've been thinking about.

The most basic abilities that the actors in the game currently have/need are move and attack. How do I make it work without direct coding?

I'm thinking if I directly code a collection of 'commands' that the text file can reference, I can build features outside of the game.

It's sort of like building a mini language.

3:00am - Anyways it's really late and I need to sleep. I'll have to build on this more next time.

Work Post

Jun. 26th, 2021 06:09 pm
relee: Picture of Relee Starbreeze, Wizard (Default)
6:13pm - Well I missed work again today, feel awful about that. But what's done is done, and I have time to do other things. I was going to do another other thing, but Reddit seems to be having troubles, so I'm here instead.

Right now the way my Roguelike Game works, each actor takes a turn based on it's action_points and speed values. When the current actor's action points are greater than zero, they reduce their action points by the cost returned by their on_turn() method. In the case of GreenEnemy it uses the Astar map to find the player and move closer, or attack if it's next to the player. It does that all by code in the on_turn function.

Instead I want to have GreenEnemy (for example) have an AI module which is run to determine its actions, and this AI module will pump out chains of Commands that the Actor will follow.

Let's walk through an example.

GreenEnemy's Turn!

GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is three squares west!

GreenEnemy's AI returns an Array of Commands. It's a one command array!

Player_1's Turn! They move one square east, foolishly putting them into attack range of the GreenEnemy!

GreenEnemy's AI runs, and looks at the portion of the map in it's senses. Using that sensemap, it sees Player_1 is in attack range.

GreenEnemy's AI returns an Array of Commands. It's a one command array!

GreenEnemy attacks Player_1!


Hmm... There's a problem with this example though. The AI is a black box. We're not seeing what goes on in there. I wasn't expecting it to only give out one command at a time, but that makes sense since it runs every turn for the enemy, so the enemy can only do one thing!

So let's look at the AI.

It gathers a sensemap from the GameMap, which is something I havent't implemented yet. Then it analyzes that sensemap with an algorithm that simulates it's thought process. In this case it would be something like Find Enemy? Enemy Near? Attack Enemy! Enemy Far? Approach Enemy! Don't Find Enemy? Random Wander!

That's a very basic AI.

I was thinking I'd have to make "Commands" for the Actors to act on that would be composed into complex actions, but now I'm not so sure. The commands might all just be one simple thing. Let's look at something other than an enemy or the player. Actors includes Items.


Player_1 sees Bone-in Ham!

Bone-in Ham idles, emptying its action points.

Player_1 stands over Bone-in Ham and picks it up!

Bone-in Ham goes to Player_1's inventory, and idles, emptying its action points.

Player_1 uses Bone-in Ham, eating it!

Bone-in Ham uses Feed to increase Player_1's food level! Bone-in Ham also "dies" disappearing from Player_1's inventory!


That's a multi-action right there! The Bone-in Ham just Fed the player AND died in the same turn! So I will have to use arrays of commands sometimes. And what is "Feed" exactly? That's the sort of command I was thinking about before. Like Attack and Move, but less generic. Something unique to food items.

I need to think more about actions. Should they be hard coded or created outside in a file? I think they should probably be hard coded.

6:49pm - I'm time stamping here 'cause I've been thinkin' a while and it's hard to measure otherwise. Anyways I just realized that "Attack" is more complicated than just "Attack". Moves like Approach and Avoid seem simple enough but they might differ too. Let me explain.

When you "Attack" you might do it in different ways. IRL you might punch, kick, chop, bite, whatever. In the game it's probably divided by unarmed and armed attacks, and armed attacks use the values of an equipped Actor, right? So that differs based on what you've got equipped.

On the other hand, maybe it isn't so different, since you're just attacking with whatever you're equipped with, or your base attack, whichever is highest, right?

The Move commands like Approach and Avoid might differ by your means of locomotion, but as long as that's accounted for in the Approach and Avoid commands, that should still work.


6:55pm - So let's think about the AI again for a bit here. I'm thinking that I could compose several 'default' AI programs, like Enemy or NPC or Item, which behave differently, and in the text file you could pick which one your Actor would use, along with setting its stats and appearance.

I'd have to program any unique AIs in code but it would be a lot harder to make an interpreter to allow unique AI programming from a file.


7:00pm - Alright so I've got my idea for the AI and the Commands, now how to code it... I figure when the actor's on_turn method is used it will run its AI program to get the Command array, then run the function in each Command.

That brings me back to implementing the Command pattern in my game, but I think I can do that with no problems.

Now that I've been thinking so hard for almost an hour though, I want to take a break, so I will.



8:19pm - After my break I went to Reddit to find some Battlemaps maybe for my game, but there weren't any suitable ones.

Now I'm feeling upset and discouraged, and I'm not sure what to do. I don't feel like working right now, and really I feel like if I force myself to do work I'm going to do bad work right now. So, I'm going to relax and play a different game or something.

Profile

relee: Picture of Relee Starbreeze, Wizard (Default)
Relee Squirrel

July 2023

S M T W T F S
      1
23456 78
9101112131415
16171819202122
23242526272829
3031     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 28th, 2026 02:19 pm
Powered by Dreamwidth Studios