Itsy's Janky Code Blog

... sit down, kick back and relax, and talk about anything that doesn't belong on one of the other forums.
Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Jul 17, 2022 2:15 pm

Jomin wrote:
Fri Jun 10, 2022 9:28 pm
Regarding this function:

Code: Select all

char * return_clan_acronym(char * clan_name_string) {

    #define MAX_ACRO_LENGTH 10 // note 1

    char acronym[MAX_ACRO_LENGTH]; //note 2
    int words = 1;
    int i = 0;

    while (*(clan_name_string + i) != '\0') { //note 3
        if (*(clan_name_string + i) == ' ') { // note 4
            words++; // note 5
        }
        i++; // note 6
    }

    if (words >= MAX_ACRO_LENGTH) {
        return "ERROR: Max Length Exceeded.\n";
    }
    else {
        printf("%s has %i words.\n", clan_name_string, words);
    }

    return "Illian Companions";

}
  • If you define this function before you use it - i.e. list it above the main(...) one then you do not have to declare it first in this trivial test code...
  • You really ought to remove a space around the '*'s that are used to indicate pointer types, either make them butt up against the type declaration (the char) or the variable/function identifier (e.g. the clan_name_string) - leaving it floating in mid-air is just asking for it to be forgotten somewhere - which can have nasty effects!
  • as a C "string" is actually a C "array" of "char" type variables - so instead of explicitly showing the pointer arithmetic as "*(clan_name_string + i)" you can be slightly more terse, and conform to what normal{!?} C coders are likely to use as "clan_name_string[ i ]" which means exactly the same IIRC...
  • try and "#define" things right at the top of the file where someone else deciphering your code in the far future would generally expect to find such definitions - the thing you are defining will not exist in the file before the point in the file where it is defined and if someone adds some code that uses that which you define before there they literally won't have anything to play with - as the preprocessor will just remove the identifier and replace it with nothing. Whilst this is desirable in some situations - particularly in "header" files where some conditions such as the "Operating System the code is being compiled for" requires such behaviour otherwise such things can lead to gnashing of teeth and wailing.
  • an "anti-pattern" I've learn of in the last year or so is that having an "else" part of an "if" after code that always does a "return" if the test is "true" is redundant - and can lead to unnecessary levels of indentation in the source code; e.g. see: https://stackoverflow.com/a/46875487/4805858
I had a big reassuring answer to each point raised here and then I realised I was editing your post not quoting it and now I just don't have it in me to type it all out again :(

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Jul 31, 2022 12:50 pm

Further to the aforementioned stalking ability for Gray Men:

Decided to go and actually deal with the whole clear-the-pointers-to-and-from-our-victims thing, before I completely lost track of what we were doing. Did that, and also added stalking data to imm-level stat en route.

Prior to this, brought stalking branch back up to date with master and resolved conflicts. All conflicts totally Aureus' fault. Of course.

Booted up the virtual machine and was pleased to see a compilation with no errors. Started the game itself. SEGFAULT. Unbelievable. I can't believe Vampa would betray me this way.

A quick backtrace reveals we're segfaulting in my new function to clear the stalking pointers. But that's only called during character extraction... Then it occurs to me that the Guardian does some stuff during boot up. Should we be following stalking pointers for mobs? Indeed not: those pointers are stored in a PC-only struct. So attempting to follow them for NPCs... Well, that would touch memory we're not allowed to...aka a segfault. Anyway, a quick NPC check gets added to that function, and everything seems to work.

Checking the behaviour of anything involving log offs is tricky in the testmud. The act of quitting crashes it, because it expects to find rent databases. But purging the character out works fine. So I think it's okay.

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Jul 31, 2022 6:30 pm

Also:

Added ability to cancel your stalking target with any abbreviation of stalk "none". Probably doesn't much matter, but seems like the right thing to do. Wrote up precis of the whole numbers situation for consultation with other, wiser minds, ones less devoted to chaos.

Prykor
Posts: 180
Joined: Thu Jan 06, 2022 8:56 pm

Re: Itsy's Janky Code Blog

Post by Prykor » Sun Jul 31, 2022 10:46 pm

Itesh wrote:
Sun Jul 31, 2022 12:50 pm
Further to the aforementioned stalking ability for Gray Men:

Decided to go and actually deal with the whole clear-the-pointers-to-and-from-our-victims thing, before I completely lost track of what we were doing. Did that, and also added stalking data to imm-level stat en route.
If you don't mind (or are allowed) sharing, what are the goals for the stalking telemetry and imm-level stats? Is this preventative debug sort of logs, or something for imms to use to keep in check if it seems like one specific char is being targeted by all the greymen regularly and spread the great lord's love more evenly?
Or perhaps to make stalking higher ranking clan folks easier?

Itesh wrote:
Sun Jul 31, 2022 12:50 pm
A quick backtrace reveals we're segfaulting in my new function to clear the stalking pointers. But that's only called during character extraction... Then it occurs to me that the Guardian does some stuff during boot up. Should we be following stalking pointers for mobs?
before you answer your own questions, it would help make grey smoblords better at killing smobs, so there is absolutely a use case for it!
Itesh wrote:
Sun Jul 31, 2022 12:50 pm
Indeed not: those pointers are stored in a PC-only struct. So attempting to follow them for NPCs... Well, that would touch memory we're not allowed to...aka a segfault. Anyway, a quick NPC check gets added to that function, and everything seems to work.
So, you'll need to restructure things for the grey smoblord concept to work....
Itesh wrote:
Sun Jul 31, 2022 12:50 pm
Checking the behaviour of anything involving log offs is tricky in the testmud. The act of quitting crashes it, because it expects to find rent databases. But purging the character out works fine. So I think it's okay.
I'm surprised the testmud doesn't have a large set of pseudo-filled chars in it, from Aureustestone to Zuntestninetynine, and with rents maxed out with random eq and such on each to make extra sure that you can test literally everything.

It's always interesting to read through these blogs! thanks for sharing, and I'm looking forward to seeing the results of the greyman project!

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Mon Aug 01, 2022 4:07 am

If you don't mind (or are allowed) sharing, what are the goals for the stalking telemetry and imm-level stats? Is this preventative debug sort of logs, or something for imms to use to keep in check if it seems like one specific char is being targeted by all the greymen regularly and spread the great lord's love more evenly?
Or perhaps to make stalking higher ranking clan folks easier?
Ah. We're talking at cross purposes here, I'm afraid. You can type stat to see some stuff about yourself. I can type a slightly different stat command to see, well, literally everything about you. Including for instance, who you're following and who's following you. And now, who you're stalking. So it's not really a case of telemetry, although I can see a case for adding a show stalking command that lists out the Gray Men and their targets - but since their numbers are likely to always be small, it's probably not worth the effort.
before you answer your own questions, it would help make grey smoblords better at killing smobs, so there is absolutely a use case for it!
You can't stalk mobs :P The Dark One doesn't care about them! (Quite close to what the error message actually says)
I'm surprised the testmud doesn't have a large set of pseudo-filled chars in it, from Aureustestone to Zuntestninetynine, and with rents maxed out with random eq and such on each to make extra sure that you can test literally everything.
It contains the zone file of Caemlyn inner city and one series of mobs. It doesn't even have horses. I have a file on my desktop called 'janky testraken' from where I had to cobble one together :lol:

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Mon Aug 01, 2022 9:41 am

Worked on target switching for Gray Men. Currently, Fades and Warders can target switch, provided they're switching to someone who is engaged on them. I abandoned that limitation for Gray Men, since they are limited to switching to their stalking targets. I added a chance to fail - by generating a number from 0 to 2 + stalk count, and requiring it to be positive. That means you'll have from a 2 in 3 to a 7 in 8 chance of this working against your designated target. And now, to compile and test!
HP:Healthy MV:Full >
*Testtwo* arrives from a puff of smoke.

* HP:Healthy MV:Full >
*Testthree* arrives from a puff of smoke.

* HP:Healthy MV:Fresh > stalk testthree
You start to prey on Testthree.
DEBUG: Victim- Testthree Count- 0

+
You settle Testthree's routines in your mind, committing his habits and routines to memory.

* HP:Healthy MV:Fresh > kill testtwo
Wimpy reset to: 179 hit points.
You barely hit *Testtwo*'s body.
*Testtwo* panics, and attempts to flee!

* HP:Healthy MV:Fresh - Testtwo: Scratched >
*Testtwo* tries to hit you, but you dodge the attack.
You barely tickle *Testtwo*'s head with your hit.

* HP:Healthy MV:Fresh - Testtwo: Scratched >
*Testtwo* barely hits your body.
You hit *Testtwo*'s left arm.

* HP:Scratched MV:Fresh - Testtwo: Scratched > kill testthree
*Testtwo* tries to hit you, but you deflect the blow.
You hit *Testtwo*'s body hard.

* HP:Scratched MV:Fresh - Testtwo: Scratched >
Your blood sings as you lunge at your victim!

* HP:Scratched MV:Fresh - Testthree: Healthy >
*Testtwo* tickles your right arm with his hit.
You hit *Testthree*'s right arm.

*Testthree* panics, and attempts to flee!

* HP:Scratched MV:Fresh - Testthree: Scratched >
*Testthree* barely tickles your left foot with his hit.
*Testtwo* tries to hit you, but you dodge the attack.
You hit *Testthree*'s body hard.
So that basically works.

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Mon Aug 01, 2022 9:59 am

Also added stalk damage versus stalking target only, to the tune of 1dstalking count. And the important question here really is, can the mud roll 1d0 without absolutely shitting itself? And I'm about to find out.

Edit: The MUD can totally roll dice with zero sides.

Alison
Posts: 795
Joined: Mon Mar 30, 2015 3:09 am
Location: South Africa
Contact:

Re: Itsy's Janky Code Blog

Post by Alison » Wed Aug 03, 2022 7:32 am

Dude.

I have adhd. Get distracted by squirrels.

But damnn. This is some impressive coding. Problem solving 2.0.

I dont understand half of the stuff you talking about and i have dipped my toes into a lot of programming languages. Suffice it to say have just one
question that pops up. Do you guys write the coding in a sandbox then transfer it to the live mud or write it on the live mud?

Also also
Hugs to you all. This is like the only game that always drags me back. Just when i think im done.

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Wed Aug 03, 2022 10:40 am

We test in a virtual machine running an isolated copy of the MUD; it's not multiplayer, which is problematic occasionally, and has a very limited set of world/mob/object files. We submit code updates, which are reviewed by the other coders (which is to say Aureus notifies me when I domestic rooster it up, and I look at his go and go 'buh?') and then if and Flash approves it, he merges that code into the actual MUD and recompiles and it kicks in next boot. Alternatively, when one of us loses patience and forces a boot.

Itesh
Posts: 828
Joined: Sat Feb 14, 2015 4:59 am

Re: Itsy's Janky Code Blog

Post by Itesh » Wed Aug 03, 2022 10:41 am

What did I do today? Well. I'm glad you asked.

When I added the stalking pointers to the memory structures of characters, I added them to a place that only actual PCs have, not mobs. And for this reason, I have spent time going through EVERY SINGLE use of the stalking code adding NPC checks to avoid the crashes caused by mobs attempting to access something that does not exist for them.

Fun times.

Could I have made it exist for mobs in the first place?

...yep.

Post Reply