Friday, January 27, 2012

Don't turn your monsters into mans!

I spent the last few days working on the [fight2] subroutine and gee, it takes a lot of lines of code to add an enemy to a fight!  The whole thing weighs in at nearly 500 lines, probably only 50 of which are the code for the 1 on 1 fight.  But did it all went fine, right?  Nope.

When i had everything complete and was trial running the code the second monster was not doing any damage and in some cases was actually adding damage instead of subtracting!  I scoured the code for hours and everything looked fine but still the problem.  Well, eventually i found the problem but not before posting on the justBasic forum again, asking for help.

The variable that determines the damage that the number 2 enemy does is called mon2dam and through-out the code the variable was written correctly but he still wasn't doing damage.  It wasn't till i was editing my post in the forum that i noticed what was causing the trouble.  As the subroutine was taken out of context i'd listed a bunch of arbitrary variables at the beginning to define the monsters parameters.  These were things like: mon1ski, mon1sta, mon2ski, man2dam, etc.

See the problem?  I'd typoed the mon into a man and as a result, when the program went to check his damage value it couldn'f find one so gave it a value of 0 by default.  Fixed the typo and problem solved, everything working as it should.  Yay.  I'm done now, right?

Wrong.  I still want to add more to the fight subroutine (It's really just one long sub which handles all the enemies and shuffles off the left overs to other parts as some die) so that it can handle a three way.  A fourway really, with three enemies attacking the player.  Why?  Because goblins are shite.  One on one they get slaughtered and it's only in numbers that they might pose a threat and probably only in numbers that they would even dare attack a human armed with anything more serious than a garden hoe.

In fact i think i should even add a modifier to the sub so it will offer the poor little buggers an advantage for fighting in groups.  A simple +1 skill each, for each monster in the group and it might even give them a chance at doing some damage before they get butchered.  As they die the bonus will diminish and it would only require adding a +1 or +2 in a few different bits of the code, specifically the part that determines their attack value, to make it work.

That will be easy.  Coding the [fight3] segment will be less so.  Having done the [fight2] part i know what to do but it will take a while and a lot of code.  The number of different outcomes increases drastically with more opponents, no more player hits vs. monster hits.  Now it's player hit/miss x monster1 hit/mis x monster2 hit/miss x monster 3 hit/miss.  And what if the player kills the second monster first?  So many permutations...

No comments:

Post a Comment