Work Post

Jun. 30th, 2021 02:02 am
relee: Picture of Relee Starbreeze, Wizard (Default)
[personal profile] relee
2:02am - Well I spent most of the day in bed napping or just beating the heat, and now it's night and I have to do _something_ right? So I'm going to work on my programming projects, specifically the Roguelike Project.

2:29am - I went to the online book Game Programming Patterns to refresh myself on the Command Pattern and I noticed something was off; the thing I'm doing is subtly different.

The command pattern is somewhat tied to the type of actor it's acting on. That is to say, all the actors that can recieve commands must contain the execution code for every command.

I was hoping to seperate the actors from the execution code, but it occurs to me now that it doesn't make sense. Even the way I was going to do it, it would only work on Actors that had the right properties.

I was thinking I'd make Commands that modified the state of Actors directly, but the Command pattern described in Game Programming Patterns runs a method of the Actor class.

Implementing every possible action an actor can take in a single Actor class, and possibly overriding some of those in subclasses, would make for a very lengthy Actor class!

On the other hand, decoupling the things an actor can do from that actor would make it confusing, what could the actor do? You'd have to go down all the commands and figure it out.

2:34am - Let's put this on hold for a bit and try something else. How many things do Actors need to do?

Well for starts there's the steering behaviors. They work a little different in turn based games but they're still relevant.

Seek, Flee, Arrive, Wander, Pursue, and Evade. I know what those mean, so I won't go into detail, but if you're curious do a search for ai steering behaviors.

Those will do movement, and they're pretty generic. Speaking of Generic, what about "Use"? The Use function on Actor could be blank, and overridden on any 'item' Actors that can be used. Then I can program unique behaviors in the class for each item. Could I then import those unique behaviors from a text file along with the stats for Actors? Hmm...

Maybe, if I load in a list of submethods to call when "Use" is run?

Like in the textfile it would be something like

OnUse: "Heal" "Self" "5"

And that would be a healing potion that heals five hp? But what about something more obtuse, like a wand of fireballs maybe?

OnUse: "Shoot" "Target" "AoE" "3" "Fire" "5"

That would run a shoot function that lets you choose a target, and then at that target it makes an AoE of radius 3 that does 5 Fire damage?

I think I could do that for the player's use okay, but what about a Monster or NPC? It would be hard for them to understand what that was in AI. Maybe if the info in the file also included type, it would work. Like, Food and Potion would be different, but similar, and Wand might be another type.

It does seem pretty overcomplicated for this stage of development, though.

Maybe I will stick to hard coding the Actors for now, instead of putting them in a file.

3:00am - Time is fleeting, but I'm not done yet.

So, I've got the steering behaviors and a generic Use method, what else... Probably some kind of Attack, right? Unarmed Actors can attack, armed Actors can attack, weapon Actors can be attacked with... But what about Ranged attacks? Maybe when an Actor is commanded to Attack, it checks if it's holding something, and compares their stats, then uses the best attack available. If that's the item, it runs the attack command of that item instead of its own? Or do item and weapon Actors never get the Attack command used on them?

I think it should be something like, ranged_attack and melee_attack since they operate differently, and it'll be up to the AI which attack to use. Ahh, I thought of something. What if an Actor is holding a non-item, non-weapon actor? It should still get its turn and be able to attack independantly. So yeah, the attack methods of items and weapons will likely be blank.

Steering Behaviors, Use, Melee Attack, Ranged Attack.

Idle. That's a pretty important behavior too. Use time but do nothing.

Move. Yeah the steering behaviors are more for AI, telling you where to move to, so there should be a generic Move action.

3:20am - That can't be all of them but I'm having trouble thinking of more. o.o;;

Use is a real heavy lifter, especially since I don't intend anything in the game to have more than one functional purpose.

There are a couple other Actor types besides Player, NPC, Monster, Item and Weapon though. I wonder if Weapon is an Item? Anyways the others are Effect, Door and Container.

Effects are things like a wall of blazing fire or a teleporter or a magical spell in the course of operation. That sort of thing. They have a location and behaviors just like the other Actors.

Doors are artificial terrain. They switch between open and shut when used. But I'm not sure that's a "Use" case because they aren't in your inventory.

Containers are things like chests that contain items and are open or shut like a door, but that you can't put in your inventory.

Some items are 'containers' in that other actors can be put inside them. Probably all Actors will have a 'contains' or 'inventory' array that has all of the actors inside of it, but not all of them will be able to contain other Actors. You might find a Bone-in Ham in a Chest but you wouldn't put a sword in your Bone-in Ham. Well, not in game anyways.

So, there's also of course things you can't put into a container because it's too big or it just violates the game rules. Like, you can't pick up a chest and you can't put it in your inventory and you can't carry it with you and keep stuff in it. You can pick up a monster but you can't put it in your inventory. I think the player will have a seperate 'hold' inventory for things in their hands that they can pick up but not put in their pocket or whatever. So will other Actors. Or maybe Hold and Wield are synonymous? Anyways that's for later. Right now I'm trying to come up with generic actions.

Maybe you CAN use items that aren't in your inventory, that would work for doors and chests. But what about locks? I could easily make it so that if you have the key, you unlock the door, but what about closing and relocking it? Maybe that's not allowed in gameplay but it doesn't make a lot of sense. :P

At least you can close it again. Maybe it WILL automatically lock if you close it while holding the key? Hmm. I digress again.

So Use saves the day again, but this talk has revealed other things.

Move, Idle, Use, Melee Attack, Ranged Attack

Pick Up, Drop, Wield, Contain, Remove

We've suddenly doubled our actions.

3:40am - I can scarcely believe I've gone another Work Post doing nothing but research and planning, but here we are. I think I need to go to bed now, I have work tomorrow. I'll keep trying to think of other Actions that Actors can take while I rest.

Feel free to suggest some!

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

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 1st, 2025 01:18 pm
Powered by Dreamwidth Studios