Wednesday, August 31, 2005

Still playing with Lua

Currently I'm working on functions that mess with strings and will hopefully in the future help my npcs have interesting things to say. This lead me to a problem where I didn't want to use references in Lua through gamedev.net I found the solution. If anyone else has a similar problem here's the clone code I'm using:


function Clone(t)
if type(t) ~= "table" then return t end
local b = {}
table.foreach(t, function(k,v) b[k]= Clone(v) end)
return b
end


This is ever so slighly modified from something I grabbed out of the Lua mailing list. The basic problem was I wanted to have a copy of the varaible rather that editing its reference. I wanted the lua argument to be constant, remain unchanged, through out the function.

As always my bookmarks have grown. I watched the first video at MIT for the linear algebra course. Yes a free online maths course in Linear Algebra - perfect for writing 3D games. Cool no? Maybe because this guy is a better a lecturer or I was watching out of free will - but for the first time - matrix vector multiplication has stuck with me. Previously I just memorized the method for exams and promptly forgot it as soon as they were over. Anyway I intend to keep checking them out! They're very good I recommend them!

That's how it's going, my weekends going to be busy but maybe Sunday I'll be able to get some game time.

Sunday, August 28, 2005

This weekend I have been mainly tinkering with Lua

... I also wanted to do some graphics stuff with the old engine but it hasn't come to pass. I know I'm stalling so I need to get on it.

My handy lua functions are

Maybe

Takes a function and chance[0-1] and may or may not run said function.

OneOf

Takes a list of function and randomly runs out of them.

This kind of stuff would be tricky in C#, its not too easy in Lua but it has nice first order functions so it's possible. I'll be using these functions all over the place to add variation to my game.

I also wrote the documentation first :D which is novel for me :) I did it in a natural docs style too as I like that commenting style. Although there's no native support for lua a config file seems pretty easy to set up. (I've yet to download the binary though, just adopted the style.)

Saturday, August 27, 2005

Agent AI

I recently posted the following, explaining some of my ideas about Agent AI:

I think there are two seperate sorts of plot here.

One emerges from NPC interactions. This is the kind of story that happens in everyday life - i.e. sweeping epic story arcs are going to be rather rare while the more mundane "someone stole my phone but I never found out who, so I bought a new one" are going to be rather more common.

The other is were the plot is pregenerated (or generated on the fly from prewritten chunks or complicated rules) and some mechanism attempts to force or entice the player to enter it. These tend to be much more story like - things you'd read in books or see in films. A great wizard looking to guide a young champion, managing to overthrow a kingdom ... that sort of thing.

I see no reason why both can't be put to work in a game. I've already done some work on the second method which I don't really intend to revisit until I'm implementing it in my game. I'm happy with it for now, limited as it is.

The first method - interesting situations developing from NPCs - well, I've had a few thoughts about how this could be done, recently. I'll just run through the idea quickly here.

In Ultima Online there was a log file. You could open the log file and see, say, the last 100 notable events that had occured. It might read:

[code]
Mary says "Hello"
Jack says "You stole my armour!"
Jack attacks Mary
The guards are called
Jack is killed
Mary says "Newb"
The Ghost of Jack says "ooOOOOoooooOOooo"
...
[/code]

This log file was unique to what your character saw. Maybe you can guess where I'm going with this :D

Each NPC is given a log file that's modelled as a queue and takes in event data types. I would define events as:

[code]
event (e.g. "It's Dinner Time")
actor event (e.g. "YOU have left the city of Murag")
actor event actor (e.g. "PETE attacks JEFF")
[/code]

Next you decide what in your world counts as an event. You might have dusk, dawn, seeing characters, characters talking, characters stealing, characters dying etc.

Eveything the NPC saw (or heard?) would then be pushed into it's personal event queue (potenitally removing the oldest event). So you have a list of events and we'll call this list "current events".

Along with this "current events" list the NPC will also have long term events. These are different for each NPC and can be generated randomly. Long term events include such things as:

[code]
NPC_X is immediate family
I am a werewolf
I hate bad people
etc
[/code]

Now you have these two [i]knowledge bases[/i]. If you've done some University AI you've probably covered expert systems. Well that's where I'm going. For an expert system you need a knowledge base, a rule set and an inference engine.

The rule set should be different for each character but generally similar rules will apply to certain NPCs. Guards will have certain rules, as will peasants, criminals and the like.

Rules are generally if-then statements.

[code]
if (NPC1 attack NPC2) and is_immediate_family(NPC1) then
Attack(NPC2)
[/code]

You have to be careful with such rules. Imagine if NPC2 here, is also immediate family! Rules may modify the rule base, current knowledge might get promoted to long term knowledge - this should also be done through rules such as

[code]
1. if (NPC1 killed NPC2) and is_immediate_family(NPC2) then
AddLongTermKnowledge(NPC1 killed family)

2. if(see(NPC1) and killed_family(NPC1))
Attack(NPC1)
[/code]

From simply rules like these quite complicated behaviour can be built up - and it's quite emergent!

(You would have to have a amazing amount of rules to get a "kindly wizard adopts an orphan boy because he knows he has a special gift that will come in useful to overthrow the evil kingdom that he's foreseen coming".)

The last thing you need is an inference engine which is pretty easy to write (as in there's plently of literature out there) but you probably want to write it in such a way that it can be queried over a number of frames (as in frame per second) depending on the drain on the CPU. Each NPC on screen (at minimum) is going to have to queried semi-regularly)

I think once you've got the rules done then interesting things will start happening. Possible there should be global rules too.

if guard attacks criminal it's okay
if NPC does some illegal he's a criminal

I intend to create the above system but not any time soon. (I'm still working on the graphics bit of my game) I think versions could work with extremely basic rule sets too.

Also the "current events" list might want events to be prioritzed. Leaving a city might be quite low - forgotten quickly. Someone becoming a criminal might be quite high takes a while to forget.


I posted it a Gamedev.net and the post can be found here.

Wednesday, August 24, 2005

JET lag

I think I've nearly got over my jet lag.

I picked up Joseph Campbell's "The Hero with A Thousand Faces" this always seem to be recommended concerning plot generation and "plot" in general.

I'm working on a few handy functions in Lua at the moment but that's it. The weekend I'll probably get into the hard core stuff maybe putting in some of the documentation stuff too.

Tuesday, August 23, 2005

Back

I'm back bt jet-lagged probably won't be too much until the weekend.

Sunday, August 07, 2005

Grahhhh II

So I have black lines.

The black lines appear with 8 tiles inbetween. They appear in at tile boundaries. They're always the thinnest the can be 1 pixel. Edting my tiles bitmap so they show they're boundaries it's clear the tiles also overlap! They only appear horizontally.

Black lines between tiles and overlapping change as the camera moves. My camera's has a perspective projection.

I've spent a lot of time hunting down various culprits. After a bit the bullet and changed the camera to Orthographic mode -> they remained (;_;). When I went in fullscreen mode it showed a one black line gap between every tile. At least we're getting some consistancy!

So I thought maybe it's my tile layout algorithm. (even though tile X,Ys are changed rarely - and black lines seem to appear depending on the camera. I think it's two problems that are together producing one result. One is the perspective projection the other is inaccurate tile positioning.)

Therefore I add 0.001 to the tiles Y position. Now I get big thick meaty lines between map boundaries but lines between tiles seem to have dissapeared - looks like I'm finally chasing down a solution.

(I was also worried they could be cracks or T-junctions which would have really made me cry!)

Okay they're gone. Now and again I can spy tile underlap but it's not a big problem. In both resolutions I have lovely tiling again with craziness. I also changed the camera to orthographic mode while I was at it. Now I've pushed past this road block I can trundle on again.

I always thought a really useful resource would be if some one went through all the adventures ever made and formalized all the puzzles and solutions. These abstract rules could then be used to bolster procedural content. Well there's the basic makings of something like that over at the Interactive Fiction Wiki. Of course it's extremely early days at the moment.

Friday, August 05, 2005

Godamn Windowed Mode

Fullscreen the game looks and plays so great and thats even without the loading code being fully correct. I've modified my anchor code in a way that I find hard to visualize graphical which extremely unsual for me, I find it hard to think abstractly without a visual model that I can "see" in my head.

It's basically a heuristic for when to buffer maps depending on what the players doing at a given moment. If he's not charging off but wandering around then maps are less likely to be loaded.

Windowed mode sucks arse I'm not even close to finding out why it's not good yet. I think it's going to be a long day. The projects getting mammoth as well. I've found the best way to develop is to have VS.net open and Snipper Compiler. In snippet compiler I write out a few functions run some tests in the Main function and then when I'm happy patch them in.

Running around in full screen mode I can just see the potential of my game. I want to create a world around the character and have him wandering through towns. I could do this but I must must must get windowed mode working first.

Also switching between fullscreen and windowed mode during the game really fecks things up. Not a major problem but something that would be nice to fix.

You may or may not be able to tell but today I've taken time off to wrestle with my code. Also school is boring as hell at the moment so I want a break from it.

*Console now can be called while playing and be seen ... at least the text can. Where the background has gone to is anyones guess.

*Am I any closer? Not really . . . there's both overlap and underlap so that's exciting. Also I've created a very nice debug function that attempts to tell me where the tiles are. It gives absolutely crazy results so there must be something else. Still how lua links up to the console is great. Really easy.

*I'll probably hack more at it tomorrow. I'll get it done eventually!

Wednesday, August 03, 2005

Gaaaah

Last weekend I got nothing at all done.
I'm thinking about taking this friday off so I'll be able to sort out my program this weekend.

Today I freshed up the very first tutorial. The code is prettier now and entirely compatible with the current version of DirectX.

Also this week I've been half heartly playing with regions and quadtrees. I also made a console based combat thing to see how I might do the combat in game. Oh yes I also setup something basic with C++ and SDL. "Why? Why?" you might cry. Well if I want to get a game programming job at some point I guess I should have a few C++ programs that I didn't write at University.

Also check out My Bookmarks. They're only related to game programming so there's only good stuff in there. Yes I do link back to myself a tiny bit but I find myself to be a valuble resource .... to myself. There's a sentence mouthful. The bookmarks should grow as time goes on as well - fun for everyone.

(Here's a tip too, if you're using Firefox, then you should get the scapbook extension. It's great. Well great for me because it gives me stuff to read when I'm offline and bored at school :D. For my bookmarks I use the scrapbooked tag for anythig I've added to my scapbook)

If other people having interesting del.icio.us bookmarks please drop them as a comment and I'll check them out. I like to read short articles about one interesting thing - you know - rather than the monstrous rambling things I tend to write :D