| MAIN | NEWS | FAQS | LINKS | ARTICLES | WORKSHOP |
Send Mail To:Steve Register
AOR Work In Progress: Entry 4 - Combat [Steve Register].
   It's that time again. Well let's see, I had just finished the Map
arrays. After I got that to working like I wanted I started working on
the combat. I added a variable to the player structure called mon_id.
This would hold the index of the monster that the player would be
fighting.  In my system when combat first starts, I wanted to  roll 
for initiative. Then once combat was joined no initiative would be 
required. So I needed a way to know which monster I was fighting. 
This would be set to 0 ( no monster ) at the start. Then when a 
monster was engaged I would check the mon_id with the monster map
array. If they didn't match then this was the first time that this 
monster was attacked and initiative would be rolled. The mon_id would 
be set to the monster index. With the next attack mon_id and the map 
would match, so initiative would not be needed. 

   With this done I had to work out how to do the actual combat. If 
the player gets the initiative he goes first. If the monster wins, it 
goes first. What I decided to do was create a routine called pc_combat
and one called mon_combat. Now I had to figure out how to run the 
combat with one combat routine. The way I did this was this was the 
PC's first attack, I would roll for initiative. If the monster won I 
called the mon_combat routine. If the PC won I did nothing. After the 
initiative check is a call to pc_combat and to mon_combat. If this is 
not the first attack then there is a call to pc_combat and then to 
mon_combat.

   The way this works is the player tries to move the PC into the cell 
with a monster. since this is the first attack initiative is rolled. 
The player wins, pc_combat is called then mon_combat is called. 
Depending on the out come, the player attacks again since this is not 
the first attack no initiative is roll and pc_combat is called and 
then mon_combat is called. The attacks alternate between the two 
with the PC going first.

   If the monster had won the initiative, I would have made a call to 
mon_combat and then to pc_combat and mon_combat again. On the second 
attack there would be a call to pc_combat and then mon_combat. In 
effect this would alternate between the two with the monster going 
first. 

   Of course this will change once the monsters start moving and 
fending for themselves.

   With that working I needed to have a way to indicate when the
monster was dead. What's the use of killing a monster if it can attack 
you when it's dead. There were three state that the monsters could be, 
ASLEEP, NEUTRAL, ANGRY. I added a fourth called DEAD.  In the main 
combat routine I did a check on the monsters state to see if it was 
dead. if it was then it didn't get an attack.

   At the same time I was working on the PC combat routine. The first 
thing I did was to add to the player structure so that I could check 
for weapons and such, I created an array called BODY. This array has 
the following elements:  HEAD, NECK, BODY, L_ARM, R_ARM, L_HAND, 
R_HAND, LHF1 (left hand finger 1), LHF2, LHF3, RHF1, RHF2, RHF3, 
HANDS, WAIST, LEGS, FEET.

   When pc_combat is called, I check the L_HAND and R_HAND to see if 
the PC has a weapon. Of course as I write this I can already see 
things that will have to change. If the left and right hand are empty, 
then I assume that the player wants to fight with his bare hands. I 
calculate what is needed to hit the monster based on the armour class 
of the monster and modified by any bonuses of the player. If the hit 
was successful then generate the damge modified by any bonuses and 
subtract them from the hitpoints of the monster. I check the  hp's 
of the monster and if they are equal to 0 or less then change the 
state of the monster to dead.

   This seemed to be working fine. In play testing I noticed that it 
would say that the monster was dead but, the monster would still 
attack and stayed on the screen. Hmmmmm. Then I thought, this must 
be one of those situations where I have to use some of that pointer 
stuff. Luckaly Thomas had a routine that would return a pointer to a 
monster structure for a particular x/y coordinates. I took that and 
change it to return a pointer to a monster structure of a particular 
index. I made the necessary changes to the pc_combat code and it 
worked.

   Next I made changes so that if the monster's state was neutral, it 
would ask if you really wanted to attack the monster. I also made 
changes so that if a neutral monster, or one that was asleep, was 
attack their state would be changed to angry.

   I also made changes to the dungeon creation code. As it was you 
only had the following types of doors, open, closed, and locked. I 
wanted to add stuck, and hidden. I then added a force_door to open 
stuck and locked doors. I also added the other four compass points 
to the movement. I then added the ability to travel between levels. 

   So now I'm thinking, this is almost playable. 

   I wanted to add a few more monsters. The current list only 
contained 4 monsters, so I added another 4 to bring the list up to
8.  The current system of creating monsters seems to depend on the 
level of the dungeon that they were created on. The system that I 
want to use will be based on the level of the player. 

   There seems to be a nasty bug somewhere. Every since I added 
the extra monsters, at no particular time on no particular level, 
when the level scrolls the program bombs out. I have added a 
command to print the level to a file. What I want to do is go to 
a level, save it to a file, walk the complete level, and see if 
it bombs. If it does then look at that level and see if it's 
something in the level creation. If I can't seem to find anything 
this way I'll add the monster map.

   As a side note, when I created the routine to print the level to 
a file, the first time I ran it I had the X and Y swapped. This made 
the map print out in the wrong orientation. No problem I'll just 
swap the X and Y. I make the changes to the for loops and run the 
program again, or at least I thought I had made all the changes. 
Run the program, create the first level, press S to save the level. 
The hard drive light flickers, cool, it's working. Hmmmm, the drive 
light is still flickering. This is odd, it should have been finished 
by now. OH CRAP!! I know what I forgot to do. Hit Cntrl, Alt, Delete. 
Shut down the process. Whew! Open the directory, click on the file, 
181M.  I'm glad I didn't decide to wait and see if it would finish 
on it's own. Can you say, hard drive is full, why of course you can.

   By the time this is posted I should have the AOR home page 
changed to reflect the changes that I have made. If not it will 
be updated shortly. 

   Well now I've got to go see about a bug problem. Hmmm, where did 
I put that can of Raid.

Later

Steve Register

Back to Entry 3 - Map Arrays.
On to Entry 5 - Objects and Inventory.

© Copyright 2001 Steve Register.