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 » Fri Aug 05, 2022 7:17 am

The baby has just gone to sleep, and the Elder Spawn is at drama camp thing for the rest of the day, so today I'm going to be doing Housekeeping coding.

Auto-Cleanup for Clan Lists
First submitted in November 2020, this code automatically rank 0s players who haven't logged in for a set amount of time, thus removing from us a huge administrative burden and one, that if I'm honest, we typically do inconsistently. Due to a certain amount of mission creep, it also decouncils inactive people, and, with certain buffers, de-ranks people who aren't maintaining their quest points. No, I can't remember offhand what the buffer is.

Code: Select all

  0,  //0
  0,  // 1
  2,  // 2  
  2,  // 3  
  5,  // 4  
  10, // 5  
  15, // 6  
  30, // 7  
  30, // 8  
  30, // 9 
  0,  // 10
...although I suppose I could look it up. And something more scaled up for Chosen clans, which I'm really not looking up.
This turned out to be a lie wrote:something more scaled up for Chosen clans

Anyway, this is very old at this point, even though it works: I suspect Flash is a little reluctant to implement something that might shag up the boot phase the first time it's run, which is fair enough. It works for me and Aureus, but we don't have one hundred and fifty thousand player files to iterate through.

There's nothing actually wrong with it per se, it's just way behind the master version of the game at this point so conflicts have crept in; the bast majority of the changes are in the clan file, and we tend to do a lot of work there. All I can really say about this job is, I resolve the conflicts. It's kind of a pain. And now I want to test it again to be sure I haven't broken anything vital - annoying in its own way since it involves manually creating notes folders and logging in to set ranks on inactive chars and then rebooting and ugh. But probably worthwhile.
Encouraging wrote:Fri Aug 5 11:39:44 2022 :: Cleaning up clan lists.
Fri Aug 5 11:39:44 2022 :: Boot db -- DONE.
So it's nice that it still doesn't die, but obviously that's without actually doing anything, so I log in quickly and do this:
* I105 HP:Healthy MV:Fresh > whois testfour
Testfour the Elder Wisdom is a level 30 Wisdom Master Dark Council trolloc hunter.
Last login from 127.0.0.1 (localhost.localdomain), on Thu Nov 7 20:18:53 2019
Crucially the point here is that he hasn't been on in forever. His rank should be adjusted to, er... four? His master flag and council flag should be removed, and his rank set to 0. And he should acquire some notes about that in his notes file, which after some jiggling I have finally managed to open a folder for in the right place. And so to reboot.
Welp, Still Looks Fine to Me wrote:* I105 HP:Healthy MV:Fresh > whois testfour
Testfour the Beaked Trolloc is a level 30 Wisdom Master trolloc hunter.
Last login from 127.0.0.1 (localhost.localdomain), on Thu Nov 7 20:18:53 2019
Last attempt from 0.0.0.0 (not logged in yet since 4.2b), on Thu Jan 1 01:00:00 1970

Testfour has no unread mail.


* I105 HP:Healthy MV:Fresh > show me dem notes for testfour
1. Itesh (100) Fri Aug 05 2022
beep
2. the Guardian (100) Fri Aug 05 2022
INACTIVE: Rank 0, was 7
3. the Guardian (100) Fri Aug 05 2022
INACTIVE: COUNCIL OFF
This took an irritating amount of time, but I'm glad it still works.

Annoyingly, this doesn't test the qp thing, so I'm to clan myself real quick, fiddle with some ranks and reboot. This doesn't work. And I'm going to assume it's because I'm an Imm, because that's always a Thing, and try again with Testone real quick.
Inactive
Testfour (1)
Rank 1 Apprentice
Rank 2 Student
Rank 3 Herbalist
Rank 4 Healer
Testone (1)
Rank 5 Wisdom
Rank 6 Senior Wisdom
Itesh (1)
Rank 7 Elder Wisdom
Rank 8 High Wisdom
Rank 9 Grand Wisdom

3 total members.
Huh?? is the current Tradition of Home and Hearth.

* I105 HP:Healthy MV:Fresh > about those notes testone
1. the Guardian (100) Fri Aug 05 2022
AUTO DERANK: 7 -> 4
So we're done here, basically. Moving on!

List out Armor Command for Imms
Basically a copy of the one that already exists for weapons. Flash wants a direct reference to a struct member replaced with a more consistent macro. Here's a shitty example:

Instead of:
the_world->europe->british_isles->great_britain_and_northern_ireland->england->the_goddamn_shire->people[ch]

This:
GET_LOCATION(ch)

...which is fair enough. I make the change on the test machine, it fails compilation, I take a random stab in the dark at resolving that, it compiles and spits out this, so, huzzah.
* I105 HP:Healthy MV:Fresh > /show armor
0. a BAD THING that was a helm - TURN IT IN [ 1019] Cond: 0/0 DB: 0, PB: 0, Mvs: 0 Abs: 0.0, Wt:3.0 ARMOR TAKE HEAD
1. a rimmed pot-like crimson helmet [ 1021] Cond: 16000/16000 DB: -1, PB: -2, Mvs: 0 Abs: 35.0, Wt:7.0 ARMOR TAKE HEAD
2. a red-painted breastplate [ 1022] Cond: 23000/23000 DB: -1, PB: -15, Mvs: -10 Abs: 65.0, Wt:22.0 ARMOR TAKE BODY
Taking a Moment to Review Aureus' Work
It's all terrible, obviously, so I knock him down to 102 and revoke his access.

Object Stats on Examine
Aureus has suggested I write out the data instead of presenting it in the... way... I have done. Okay fine I can't remember how I did it, shut up.

But also, the Spawn awakes. So, bye!

Elapsed time: Maybe 1.5 hours.

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

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Sep 25, 2022 9:53 am

This is going to be one of those that I write partially in retrospect, since I didn't do it at the time.

Extract Lights
Feneon suggested to me that lights should just be deleted when they burn out, which seemed like a fantastic idea to me - who hates juggling burnt-out lanterns? ME. Then I learnt it was Korsik's idea, so I just THREW THE WHOLE THING IN THE BIN.

...but seriously: I basically just searched the codebase for the phrase that lights use when they burn out. Turns out, there's a function that just updates all worn LIGHTs on tic, so I could add two lines there - one to echo the message, and one to extract the object - and we were basically done.

I had briefly had some concern that this would delete the streetlamps, but it turns out that A: all the streelights are LAMPs, not LIGHTs, and B: the update only touches LIGHTs that are HELD. So this was basically super easy.

I didn't initially echo the discard message to the room because, frankly, I didn't think anyone else would care enough about third-party ligfht-management, but Flash requested one last night while merging other code and astonishingly I got that message in time to do it before he left, so, it got merged and it's live in game.

Rest (aka restmote)
Cards on the table, stole this idea from another MUD. Basically, the idea is this: typing rest with an argument sends that argument as an argument and places you in POSITION_RESTING, rather than the default message. Which is neat for roleplay.

It turns out, and I had forgotten this, that rest already takes an argument, because you can rest on CHAIR objects. But that's basically pointless, no-one does it, and you can still do it with 'sit', so I just commented out all the sitting stuff, and replaced it with sending the argument to the emote command.
Observe that it works wrote:Testone has entered the game.

* I105 HP:Healthy SP:Bursting MV:Fresh >
Testone sits down and rests.

* I105 HP:Healthy SP:Bursting MV:Fresh >
Testone stops resting, and clambers on his feet.

* I105 HP:Healthy SP:Bursting MV:Fresh >
Testone sinks to the floor wearily.

* I105 HP:Healthy SP:Bursting MV:Fresh > l
End of a Short Hallway
You arrive at the end of a hallway. The hall is less elegantly decorated here
and the door to the south looks a little worn. From under the southern door
you can smell something that gets your stomach rumbling.
[ obvious exits: E S ]
Testone the Gray Man is resting here.
Watcherlog
Going to try and bust out that final clan abbreviator now - there will be a hierarchy of rules, to whit:

1: If a clan name is one-word and doesn't have an apostrophe in it, just remove all the vowels excluding the first
-- Gleeman -> Glmn
-- Wisdom -> Wsdm
-- Illuminator -> Illmntr

2: If a clan name has an apostrophe in it and the letter after that apostrophe is NOT a space, take the leading letter and every letter that follows an apostrophe and cap them:
-- Morat'raken -> MR
-- Morat'torm -> MT
-- Tel'aran'Rhiod -> TAR (not that that's a clan name, obviously

3: As above, but the letter after the apostrophe IS a space, skip that space and take the first letter of each word and cap it
-- Kandori Merchants' Guild -> KMG

4: Anything else, just take the first letter of each word and don't change the case:
-- Children of the Light -> CotL
-- Deathwatch Guard -> DG
-- Hand of the Light -> HotL
-- Defenders of the S -> DotS

This is going to be annoyingly complex, but I'll try and do some pseudocode to show roughly how it'll go.

We're going to have to loop through twice - we can't count words without looping through once, and then the second loop will deal with the characters.

Variables:
WORDS = 1
NAME = what we're looping through
ABBREV = where we're sending letters

First loop:

Code: Select all

LOOP through NAME where i is individual character
    IF i == ' ' 
        WORDS = WORDS + 1
We start words on 1. If we encounter a space, that's the start of a new word. This is quick and dirty and assumes that no-one has banjaxed a clan name.

Second and Infinitely Worse Loop:

Code: Select all

LOOP through NAME where i is individual character
    IF WORDS == 1
        IF i is a VOWEL
            SKIP IT
    ELSE ([i]oh god[/i])
        IF i == '\'' AND (i+1) != ' '
           COPY upper(i) to abbrev
        IF i == ' '
...okay, you know what? Trying this in pseudocode has made me lose the will to live. I'm just going to go try and code it.

Fibbo
Posts: 2
Joined: Fri Jul 22, 2022 1:18 am

Re: Itsy's Janky Code Blog

Post by Fibbo » Mon Sep 26, 2022 6:04 pm

Itesh, I teach computer science (in java) to high schoolers in the US. I think I'm going to have them read your Janky Code Blog as an assignment about what life is really like as a programmer! Love reading these!

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

Re: Itsy's Janky Code Blog

Post by Itesh » Wed Jun 28, 2023 12:28 pm

Well, it seems like a long time since I did one of these - 9 months, enough time to gestate a child (not why I've been absent) - so now seems like a suitable time to somehow get back into it.

In fact, this may not actually be a code blog at all, so much as a blog about attempting to get back into the stream of things after a 9-month absence, the sum total of my contributions being slightly gnostic pronouncements in the Staff discord and occasional judgements about Serious Business.

Plus, doing this will take my mind off how ill I feel, so there's that.

The first thing I do is, genuinely, find my last blog post. That's how I know it's been 9 months, and not because I have any real idea when the last time I did anything productive was. I see that I made lights auto-extract when they burn out. Fantastic. I'd utterly forgotten. And I see that there are issues with the Watcher Log, still, which I don't *think* Aureus has fixed, although I suspect that will become clear later. I move on.

I have 54 private messages. That's not representative of a 9 month stretch; I've definitely deleted everything in my inbox a few times. The vast majority of these messages are not actually -to- me, just the Immortal or Staff group in general, and by and large I'm able to delete them based on the contents of the subject line - forum access, rank requests, apologies for rule breaking, that kind of thing. It's all almost certainly all dealt with already by my less-dung colleagues. Get in the bin.

There are precisey three reports of semi-code related bugs, which I mark aside to look into, and one immortal application from, oops, a month and a half ago. Which is a surprise, actually, because no-one ever applies any more, and if anything is going to shut the game down it'll be that. Or Flash dying.

A little judicious pruning and there are seven things to deal with - the aforementioned bugs and application, a message with such an ambiguous subject line I have no idea what it actually is, and something that looks like and enforcement issue and Fen's reply to it, which is unlikely to concern me but which I do actually want to read.

This really isn't a code blog, is it.

One of the bug reports is a classic: player has provided log with very little commentary, trusting that I will see the obvious problem. I won't. So that's dealt with, in a way. I make a note to talk to Aureus about it.

What I thought might have been an enforcement issue with reply from Fen is actually just a mobol problem, so I immediately delete it.

There's a Gray Man issue with their speech; this is actually a mobol problem 90% of the time, but I actually will look into that one and immediately go to do so. If it -isn't- a mobol problem - in the sense of mobol in game, rather than the code that powers mobol - then there's nothing we can do about it because we don't have the code for mobol. So fingers crossed.

Did not cross those fingers hard enough:
change race myrddraal
Ok.

Invisibility removed.

'dodge
You hiss 'dodge'

A slobbering trolloc frowns.
A slobbering trolloc says 'I require a crafting token, Itesh'

change race grayman
Must be one of None,Two Rivers,Trolloc,Andor,the Malkieri
Diaspora,Tarabon,Cairhien,Tear,Murandy,Amadicia,Shienar,Arafel,Kandor,Saldaea,Illian,Ghealdan,Arad
Doman,Mayene,Altara,Seandar,Kirendad,Shon Kifar,Rampore,Tzura,Noren M'Shar,Aiel,Ogier,Beaked
Trolloc,Bearish Trolloc,Boarheaded Trolloc,Ramshorned Trolloc,Wolfish
Trolloc,Dreadlord,Myrddraal,Gray Man.

change race gray man
Ok.

'dodge
You drone 'dodge'

emote says dodge
You emote: Itesh says dodge

A slobbering trolloc frowns.
A slobbering trolloc says 'I require a crafting token, Itesh'
Now this is a weird one, because drones were added to the words that mobol could hear by Flash about three years ago. I make a note to mail him and check this, because again: we don't have the code for mobol. In fact, I'll lost my notes, so I just do it now. In a reply to the mail from 2020.

Next up, sonic boom apparently making a follower autoflee without actually doing that or damaging them, or something.. I ask for a log from the followers PoV, which is totally not just treading water before I have to look at the code, shut up. YOUR FACE IS TREADING WATER.

Next up, player reports bug, changes mind in next email. Fantastic, result.

Imm app: Aureus has replied to the player confirming receipt and also posted it in the right actual place. So there's jobs I don't need to do. I read the app, and to be honest the first thing I'm looking for here is whether any of the listed players are, well... just arseholes. You can't be an Imm, if you are, really. I realise that people often think of Imms as arseholes, but consider how bad it would be if they really were!

I recognise none of the names except the first - which I think is daft, but that's okay - so that's a good sign. The player has taken a punctuation-optional approach to this one, which is the bold choice of a maverick, maybe. Clearly, it is TIME TO SHAKE THINGS UP.

I skim the rest and render judgement in two pithy lines of Itsyspeak. If the person that wrote that is reading this, don't assume I rated it badly just because I'm not going on about it here!

And then I delete it from my mailbox, which now contains only legit code problems.

Next up: what in the hell is going on in code land?

And actually, I'll save that for next time. I still feel pretty rough.

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

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Jul 02, 2023 10:38 am

Part 2 of catching up with things. It's not going to be a good part, because I only have about 45 minutes before lunch with family, and the children are being awful - but there's time for some groundworl at least.

I start VSC and immediately abandon it - it's been a while, so it's going to need to think about its life choices for a while and percolate some updates.

While it does that, I head over to GitHub so see what's in my approval queue; surprisingly, only three things!

1: A fix to hunting which astonishingly I actually understand, and therefore approve.

2: Something where I have changes requested because I still don't think 'Vacuous' is a good rank title, so I just ignore that - wiser, more game-owny minds than mine will decide.

3: A fix-up and finish of Saladin's exit blocking code, for mobs only. Which I approve because it needs testing live and I'm interested in seeing that.

A quick on my active branches; I prune a few, and what remains is - and to be clear, this is just random things I happen to have been working on - this load of nonsense:

1: autodraw - set a keyword for which weapon to draw first. Not sure this works. Maybe! I vaguely recall that it was fine, and so now I suppose I should check that that's *still* the case with all the more recent changes.

2: Watcher Log: does work, kinda, but not finished. Aureus was going to finish that but there's no reason I should actually laze out of that one.

3: Stalk: like 90% finished. Needs to clear stalking pointers on character death/extraction. Aside from that, it's fine.

4: Warrantspardons: can't even remember what this is, so I go and look. Oh yes! This is the one that gave justice clan members a warrant and pardon command seperate from mobol. This *was* working, and then mysteriously broke in a way that I cannot fathom. Tricky.

5: Non-binary pronouns. A simple change that is yet weirdly still in the queue. A mystery. I could go and made Myrddraal always "it", though, which would probably be appropriate.

6: Gmanpatch: a bunch of patches for Grey Men. I actually just need to delete this and start again, it's too far out of date and I never made much progress with it.

7: Pet name: Can't remember, off hand. Turns out it adds a name command for you to name your pets. Don't think it was broken. Need to check though. List increases in length.

8: Healingkit branch. I delete it. I am committed to actually making functional healing kits for wisdoms, but as I recall no actual work has been done in this branch, so it's an easy prune. I quickly check what's in it and change my mind about deletion, as I've made a bunch of plans. Sigh. Longer list.

9: Aielogiermoves: okay this one gets binned, it was dumb and arbitrary.

Finally, 10: warrior skills: I don't delete it, because I wrote a bunch of templates into it, but this one is mostly just cloud storage for some stuff. This branch is never going to be merged.

The next step is working out which of these actually work, and then merging master back onto them to bring them up to date with the main game before I submit them for approval. Yay!

By which I mean, "Oh god I'm so tired".

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

Re: Itsy's Janky Code Blog

Post by Itesh » Sun Jul 02, 2023 3:32 pm

I spend a fraught few minutes working out how to merge all the changes from the master branch into whatever branch I'm working from in VS code; this is something I periodically forget how to do, and frankly I think the terminology that Git uses for anything is *spectacularly* poorly chosen, so it's not completely obvious when you're doing the right thing.

Having merged 103 commits from master into the autodraw branch, I boot up the test mud and check whether this nonsense actually works, after quickly scanning the changed code.

Original:

Code: Select all

HEY HAVE YOU FOUND A WEAPON?
	draw that dung, yo
New Code:

Code: Select all

HEY HAVE YOU FOUND A WEAPON?
	OKAY BUT FOR REALS IS THERE A DRAW KEYWORD?
		Draw that keyword dung, yo
	NAH MUSH
		okay well just draw whatever then
...and then the actual setting of the keyword is handled via the change command, just like email or wimpy or whatever. So let's see if that works.

...wait, is the branch where I had to manually create sheaths in the object files? Oh NO.

Testing:
o I105 HP:Healthy MV:Full - the Caemlyn cityguard: Scratched >
The Caemlyn cityguard tries to hit you, but you deflect the blow.

o I105 HP:Healthy MV:Full - the Caemlyn cityguard: Scratched >
The Caemlyn cityguard hits your head very hard.
You draw a plain, slightly curved blade from a jewel-encrusted scabbard with a flash of steel.
You slice the Caemlyn cityguard's left foot.
We're wearing a sheath. We have NOT set a draw keyword. Autodrawing still works. So far so good.

Interlude: Itesh sends an illegal character to the terminal, forcing him to lose link forever. A terminal window is closed and re-opened. Love telnet.
o I105 HP:Healthy MV:Fresh > change
Fields: autotrack, description, email, passphrase, mood, race, class, sex, spam, title, wimpy.

o I105 HP:Healthy MV:Fresh > change autodraw dagger
You will try and draw 'dagger' first.
Note: need to add autodraw to the suggested fields.
* I105 HP:Healthy MV:Fresh > she
You sheath a plain, slightly curved blade into a jewel-encrusted scabbard.

* I105 HP:Healthy MV:Fresh > kick guard
Your boots need polishing again -- blood all over...

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden hits your right leg very hard.

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden hits your body extremely hard.
You try to hit an elite Lion Warden, but he deflects the blow.

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden hits your body hard.
You try to hit an elite Lion Warden, but he deflects the blow.

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden tries to hit you, but you deflect the blow.
You try to hit an elite Lion Warden, but he deflects the blow.
So here's an issue: if you set a keyword that you don't have, you never draw what you *do* have in its absence. which would be fine if you were getting a message, e.g. "You search for a dagger to draw but find nothing!"
* I105 HP:Healthy MV:Fresh > say in this example, I have a plain blade in the scabbard on my back, which would normally be drawn first.
Ok.

* I105 HP:Healthy MV:Fresh > change autodraw rapier
You will try and draw 'rapier' first.


* I105 HP:Healthy MV:Fresh > kick guard
You miss your kick at an elite Lion Warden's groin, much to his relief...

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Healthy >
An elite Lion Warden tries to hit you, but you deflect the blow.

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Healthy >
An elite Lion Warden hits your right foot hard.
You draw a ruby-worked rapier from a jewel-encrusted scabbard with a flash of steel.
You try to pierce an elite Lion Warden, but he deflects the blow.
Huzzah! The actual meat of this, drawing a weapon in preference, works just fine. We just need a few tweaks:

1: Should probably display your autodraw preference in stat, or something.
2: An error message if you are in combat trying to draw a weapon you simply do not have, rather than endlessly wielding nothing.
3: Need to add 'autodraw' to the suggested fields in the change dialog. And also, is there a change helpfile?

It could go in as it is, but the changes above will make it a lot less user-unfriendly. To work!

I fix points 1 and 3 first, and those are trivial and I want to make sure they work before I do anything more complex.
* I105 HP:Healthy MV:Fresh > change
Fields: autotrack, autodraw, description, email, passphrase, mood, race, class, sex, spam, title, wimpy.
While copying this data I press Ctrl + C, which once again causes the terminal to crash. I reconnect.
* I105 HP:Healthy MV:Fresh > change autodraw dagger
You will try and draw 'dagger' first.

* I105 HP:Healthy MV:Fresh > stat
You are a 158 year old male none hunter.
Your height is 5 feet, 7 inches, and you weigh 148.0 lbs.
You are carrying 0.0 lbs and wearing 0.0 lbs, peanuts.
Your base abilities are: Str:19 Int:16 Wil:16 Dex:17 Con:17.
Offensive bonus: 71, Dodging bonus: 83, Parrying bonus: 28
Your mood is: Wimpy. You will flee below: 500 Hit Points
Autodraw: You will attempt to wield 'dagger' first.
Your armor absorbs about 0% on average.

You are subjected to the following effects:

* I105 HP:Healthy MV:Fresh > change autodraw
You will try and draw '' first.

* I105 HP:Healthy MV:Fresh > stat
You are a 158 year old male none hunter.
Your height is 5 feet, 7 inches, and you weigh 148.0 lbs.
You are carrying 0.0 lbs and wearing 0.0 lbs, peanuts.
Your base abilities are: Str:19 Int:16 Wil:16 Dex:17 Con:17.
Offensive bonus: 71, Dodging bonus: 83, Parrying bonus: 28
Your mood is: Wimpy. You will flee below: 500 Hit Points
Autodraw: You will attempt to wield '' first.
Your armor absorbs about 0% on average.

You are subjected to the following effects:

* I105 HP:Healthy MV:Fresh >
Stat displays just fine, but when you use no argument it's clearly saving something, so I need to go back and properly set that to NULL in the absence of an arg string. So I guess that's point 4, now.

A quick look at the code reveals that while I did set a max length for the string, I never set a minimum, and that seems like a sensible thing to do. And also possible to make it respond to 'none', or something like that. Arbitrarily I set 3 as the absolutely minimum length. Anything less and it clears. And really I should do a constant for that, so I do. Urgh. It's not a *total* rewrite, I guess. And this still isn't the complicated bit!

Obviously I test again, because I am paranoid about breaking things:
* I105 HP:Healthy MV:Fresh > stat
You are a 158 year old male none hunter.
Your height is 5 feet, 7 inches, and you weigh 148.0 lbs.
You are carrying 0.0 lbs and wearing 0.0 lbs, peanuts.
Your base abilities are: Str:19 Int:16 Wil:16 Dex:17 Con:17.
Offensive bonus: 71, Dodging bonus: 83, Parrying bonus: 28
Your mood is: Wimpy. You will flee below: 500 Hit Points
Your armor absorbs about 0% on average.

You are subjected to the following effects:

* I105 HP:Healthy MV:Fresh > change autodraw dagger
You will try and draw 'dagger' first.

* I105 HP:Healthy MV:Fresh > stat
You are a 158 year old male none hunter.
Your height is 5 feet, 7 inches, and you weigh 148.0 lbs.
You are carrying 0.0 lbs and wearing 0.0 lbs, peanuts.
Your base abilities are: Str:19 Int:16 Wil:16 Dex:17 Con:17.
Offensive bonus: 71, Dodging bonus: 83, Parrying bonus: 28
Your mood is: Wimpy. You will flee below: 500 Hit Points
Autodraw: You will attempt to wield 'dagger' first.
Your armor absorbs about 0% on average.

You are subjected to the following effects:

* I105 HP:Healthy MV:Fresh > change autodraw none
Autodraw preference cleared.

* I105 HP:Healthy MV:Fresh > stat
You are a 158 year old male none hunter.
Your height is 5 feet, 7 inches, and you weigh 148.0 lbs.
You are carrying 0.0 lbs and wearing 0.0 lbs, peanuts.
Your base abilities are: Str:19 Int:16 Wil:16 Dex:17 Con:17.
Offensive bonus: 71, Dodging bonus: 83, Parrying bonus: 28
Your mood is: Wimpy. You will flee below: 500 Hit Points
Your armor absorbs about 0% on average.

You are subjected to the following effects:
Clearing the preference is fine.
I105 HP:Healthy MV:Fresh > change autodraw ax
Your autodraw keyword must be at least 3 and no more than 10 characters long.
This is also fine, and my decades-long quest to rid the world of the stupid American spelling of 'axe' is finally bearing fruit.

In a sudden moment of paranoia I am relieved to discover that Past Itesh did actually free this memory during character extract. Which is good, because Present Itesh is a chortlesnorfling idiot.

I load seven cats in RK for no apparent reasons.

I think my brain has gone again.

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

Re: Itsy's Janky Code Blog

Post by Itesh » Mon Jul 03, 2023 5:28 am

The final problem with Autodraw: If you don't have thing you're trying to draw - eg, you've set it to dagger but you only have swords - you don't actually draw *anything*. So what we want to do is try and draw whatever you've set once and if it fails, default to just drawing whatever you can.

First things first, we need to somehow search your stuff for keywords matching what your setting - now, I'm pretty sure the game already does this with the standard draw command, so into the live game to actually find that out!

===
* I104 R:16199 S:Field >
You sheath a dagger into a dark, hooded cloak.

* I104 R:16199 S:Field >
draw sword
You don't seem to have a sheathed weapon.

* I104 R:16199 S:Field >
dra
You try to quietly draw a dagger from a dark, hooded cloak.
===

So yes - as you can see, the game actually does search for explicit weapons. It doesn't tell you that during its error messages, but that's fine. So I can nick that code and move it into the section that deals with autodrawing (probably).

Mudlet crashes. Then VSC crashes. Then my desktop generally crashes. Notepad seems fine though, big win. 10/10.

Right, let's brain this out.

Current autodraw code says, more or less:

Code: Select all

Found a sheath?
	If autodraw keyword set
		draw the autodraw keyword
	else
		just draw generally
This isn't working, because we get stuck on the first IF - we're just constantly testing that. What it needs to say is something closer to

Code: Select all

Found a sheath?
	If autodraw keyword set AND worn eq contains a weapon whose keywords match the autodraw keyword
		draw that
	else
		just draw anything
So that sounds like a shitter to write, but remember, the code for drawing a weapon by keyword already exists in standard draw - this should just be a slightly complex copy paste job.

It might be slightly clearer to abstract this concept out to a boolean function - something like:

_bool weapon_keyword_in_worn_EQ

... then you could write an if line like

Code: Select all

if (GET_AUTODRAW_KEY(ch) && weapon_keyword_in_worn_EQ(ch, arg))
{
	do the thing;
}
So anyway, I do that, and then attempt a compile and frankly, I am fully expecting errors at this point.

...I only have to fix three things before it compiles - an int I didn't declare that I need, and two I didn't declare that I don't need and simply delete.

===
Your mood is: Wimpy. You will flee below: 250 Hit Points
Autodraw: You will attempt to wield 'dagger' first.
Your armor absorbs about 0% on average.

You are subjected to the following effects:

* I105 HP:Healthy MV:Fresh > kick guard
Your boots need polishing again -- blood all over...

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden hits your body very hard.

* I105 HP:Healthy MV:Fresh - an elite Lion Warden: Scratched >
An elite Lion Warden hits your left leg hard.
You draw a plain, slightly curved blade from a jewel-encrusted scabbard with a flash of steel.
You slice an elite Lion Warden's body extremely hard.
===

so far so good, we don't have a dagger so the sword gets drawn instead. Now to quickly check that when we do have something set that's correct it does actually draw the right thing first.


===
In this example, the plain blade is the default first weapon (tested off camera)

I105 HP:Healthy MV:Fresh > change autodraw rapier
You will try and draw 'rapier' first.

o I105 HP:Healthy MV:Fresh > kick warden
Your beautiful full-circle kick misses an elite Lion Warden by a mile.

o I105 HP:Healthy MV:Fresh - an elite Lion Warden: Healthy >
An elite Lion Warden hits your right foot extremely hard.

o I105 HP:Healthy MV:Fresh - an elite Lion Warden: Healthy >
An elite Lion Warden hits your head very hard.
An elite Lion Warden tries to hit you, but you deflect the blow.
You draw a ruby-worked rapier from a jewel-encrusted scabbard with a flash of steel.
You pierce an elite Lion Warden's left foot extremely hard.
===

And with that, I am, astonishingly, done.

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

Re: Itsy's Janky Code Blog

Post by Prykor » Wed Jul 19, 2023 6:17 pm

I'm glad to see some more of this! Thanks, Itesh.
Itesh wrote:
Mon Jul 03, 2023 5:28 am
This isn't working, because we get stuck on the first IF
Why then, do you need the if? draw already checks whether you are wielding a weapon, so you just do both! a little extra spam informing the player that they are already wielding a weapon won't hurt, even if it is somewhat less efficient in the intended use case... Maybe an if statement to check if you are wielding something before the default draw, the intended use case is kinda important I guess.
Itesh wrote:
Mon Jul 03, 2023 5:28 am
And with that, I am, astonishingly, done.
I'm very much looking forward to being able to wear weapon sheaths, sit down/rest (auto-sheath), and then drawing something other than my scalping dagger when I next enter combat!

It would also save trouble setting up a correct sheath order with the scalping dagger in the pack for my multi-weapon set ups.

Post Reply