Thursday, March 7, 2013

code restructuring: technique

Before I talk about the restructuring of the technique code, I want to extend a big thank you to Finland, which is the source of the majority of my blog views, per capita (USA wins out in overall quantity).  In honor of your Finnish dedication, I will add a new comestible to my variant: lutefisk (please let me know if this is the wrong term in Finland).

My current thought is that it will behave similarly to royal jelly, but when eaten, will give the message: "This tastes like the worst thing you've ever tasted!"  I may change the message for the case when confused by a potion of booze, as I once read a guide to eating lutefisk online, and the first step was "get so drunk that you can't taste it."

...

Moving on, I'm almost done with restructuring the technique code.  Instead of a long switch statement, I'm using a function pointer for each technique.  This will allow for the potential of techniques having more than one effect, as the new tech struct can have a linked list of function pointers, where each function is called in serial.

For example, say we want a technique that deals cold damage and stuns the target monster, and a technique that deals fire damage and stuns the target monster.  The two techniques can share the stun code, so the first would have a linked list containing two function pointers, one to fire damage technique code, and one to stun technique code, whereas the second would have a pointer to cold damage technique code and a function pointer to the same stun code as 'fire-stun'.

Why restructure?  Part of the reason is because of shit like this:


A closer look:



This unreachable break statement appears all over tech.c.  My guess is that someone made the mistake early, when writing tech.c, then copy and pasted the mistake in several more places.  It doesn't make the game not function, but it's ugly.

With the new system I'm implementing, there could also be hybrid/random techniques that randomly select from a couple of the technique function pointers (they'd have to be compatible... combining bless and raise zombies doesn't make any sense).  These random/hybrid techniques could potentially be granted as sacrifice gifts, which would add an interesting dynamic to sacrificing.

As a next step, I'm going to take on the scroll/potions/spell effects... i.e., the type of stuff that can be broken up pretty easily.  Once again, the new structuring will allow for craziness like scrolls/potions/spells with multiple effects, etc, if I, or someone else, decides to add that in the future.

The point of all this is to make the code much more loosely coupled to make expanding and modifying the game easier.

9 comments:

  1. Make sure that when Valkyries eat lutefisk it says "This lutefisk is delicious!"

    ReplyDelete
  2. Thanks for lutefisk idea, I am adding it to hallucination objects.

    EDIT: Your CAPTCHA is evil, ugly and irritating.

    ReplyDelete
  3. Cool thanks... also, what's the captcha thing? How do I change it?

    ReplyDelete
  4. I was working on shk.c And noticed
    A Script that Prohibits Non-human characters Access
    To the Black Market. Did you put that there?
    And if so, How come?
    Every Time Someone Post's A CAPTCHA comes up to prevent Spam-bots from Posting Ad's
    Your's is a Re-CAPTCHA (look it up) That is Queing
    Photo's of House Address Numbers , Which Are Hard
    For People in The 30 to 40 and up Range to Read.

    ReplyDelete
  5. I didn't touch shk.c as far as I know, and certainly wouldn't prohibit a certain race from entering on purpose... what line in shk.c is it?

    I'll look into the captcha stuff.. that bothers the hell of out me too. I can never read them.

    ReplyDelete
  6. That wasn't me. To my surprise, that's in the original slashem code... unless the slashem code in the Arch User Repository is different.

    ReplyDelete