Posts Tagged ‘Forgotten Times II’

Eee Issues

January 31, 2011

At one point, I really loved my Eee. I had come to the conclusion that I needed good battery life more than I needed lots of processing power, and so the tradeoff in a netbook made a lot of sense. Unfortunately, my Eee, like the other portable computers I’ve had, didn’t prove equal to the rigors of actually being transported – after spending a year or two being transported in my backback, the screws holding its case together decided to come out. Even worse, after I replaced them, something went wrong with the connection between the battery and the processor. The Eee now works great when it’s plugged in, but turns off the moment you unplug it. The plus side is that this means the data I used to store on it isn’t lost. the minus side is that the specific reason I bought it, good battery life, is now gone. Obviously, this wasn’t good for my programming, since the main time I used to write code was on my bus ride to and from work.

However, all things come to an end, and my current hiatus is no exception. I got a shiny new laptop, and used to it pull together a good deal of the town of Ramu in Forgotten Times 2.

Don’t write functions to return local arrays

December 23, 2009

Consider the following function (taken from Forgotten Times II):

char* CClassicRPGDoc::levelLocationID(int which_level)

char center_location_ID[LABELLENGTH];
int center_location_index = current_location;

char retval[LABELLENGTH];

strcpy(center_location_ID, location_IDs[current_location]);

int counter;
if(which_level > 0)
for(counter = 1; counter <= which_level; counter++)
strcpy(center_location_ID, locations[center_location_index].getTop().getLocationID());
center_location_index = getLocationIndex(center_location_ID);
if(which_level = which_level; counter–)
strcpy(center_location_ID, locations[center_location_index].getBase().getLocationID());
center_location_index = getLocationIndex(center_location_ID);
if(which_level != 0)
strcpy(retval, center_location_ID);
return retval;

The above function is used in the display of multi-level buildings and was causing me no end of grief. For some reason, instead of returning what I expected (i.e., the ID of the specified floor of a building) it was consistently returning the ID of the floor (i.e., the one the character was in). Even worse, its behavior changed when I ran it through the debugger, and when I traced the values of the variables all the way to the end of the function, they looked the way they were supposed to.

The problem, of course, was the statement in bold text. While the retval[] string had the right value all the way to the end of the function, once the function exited, the memory that string had occupied was deallocated. As a result, rather than passing back the string I intended, I was passing back a memory location which, by that time, was being used for something else (apparently for storing the ID of the current floor, though I have no idea why). Very annoying.

While there are a number of ways to solve the problem (including reworking the logic so that the problem didn’t come up in the first place), I chose the one that was easiest for me, and made retval[] a static variable. Not the most artful way of doing it, but, since static variables are maintained between function calls, it did the job. The final results are that the last upload of Forgotten Times II has a reasonably functional implementation of multi-story building display, and that I’ve learned to avoid writing functions to return local arrays.

More progress

October 28, 2009

I finally got the basic layout (i.e., made and placed the buildings and stitched together borders) for the agricultural town in Forgotten Times 2. Wow. That represents an incredible amount of work, and is basically what I’ve been focusing on since my last post back in August.

It’s strange, but people generally seem to overlook the kind of effort I’ve been putting in over the last few months when they think of programming. When I was in law school telling a girl I knew about my efforts to put together a coherent plot for Forgotten Times 1, she remarked that she’d never thought about programming being about plot, rather than about essentially mathematical problem solving. The same sort of thing happened when I told a friend of mine here in Cincinnati about my programs – to get some sense of them, he asked to measure the number of source lines of code I had written in the engines, and completely ignored the data files.

I suppose it’s not that different from thinking of authors on the Internet as “content providers.” However, I still think it’s a mistake. Since I started writing games, judging the program by focusing on the basic mechanics has begun to seem something like judging a fine wine by looking at the bottle. True, the bottle can tell you something (e.g., where the wine came from, year, etc) but it’s what someone put into it that really makes it special.

Man…it’s been a while

August 1, 2009

I can’t believe the last post was two months ago. Actually, I can believe it, because I know why it took me so long. It took me so long because I was working on getting the pathfinding back together in Forgotten Times 2. I say back together, because when I originally wrote the AI, the characters had the power to move between any arbitrary points in an area. However, since then (circa 2003-04) I basically ripped out everyone’s brains and left them standing stationary and waiting for the player to interact with them. Now, since May, I’ve been putting the pathfinding back in to support some new plot segments, and it’s been more than a little difficult. The problem is that I not only ripped out everyone’s brains, I also changed how the software gives commands to the different characters. Circa 2003-04, I figured out how to get from point A to point B as part of the main document class. Since then, I’ve moved the brain power into the characters themselves, leaving the document class to basically store data. While that makes sense from a compartmentalization standpoint, it didn’t work at all from the standpoint of making the AI work, since the data I needed for pathfinding was stored in the form of private members of the document class.

Unsurprisingly, that caused no end of heartache which in the end was resolved with a tremendously ugly (but functional) solution – I duplicated the data I needed as global data. At some point, I’ll rationalize things so that I don’t have duplicate data stored as globals and as private members of the document class. At this point though, I’m just happy that I got things working.