[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Prefix Prompt Help
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Prefix Prompt Help

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Drach   (3 posts)  [Biography] bio
Date Tue 17 Aug 2010 05:05 AM (UTC)

Amended on Tue 17 Aug 2010 05:37 AM (UTC) by Drach

Message
Hey all,

I've been reading these forums off and on now for years. I recently started mucking around with the Rom2.4b6 codebase yet again and am looking for some assistance on setting up a prefix-prompt that will occur only during combat.

I've come to think that the best way to accomplish this is doing so within the send_to_char functions:


void send_to_char (const char *txt, CHAR_DATA * ch)
{
    const char *point;
    char *point2;
    char buf[MAX_STRING_LENGTH * 4];
    int skip = 0;

    buf[0] = '\0';

    point2 = buf;
    if (txt && ch->desc)
    {
        if (IS_SET (ch->act, PLR_COLOUR))
        {
            for (point = txt; *point; point++)
            {
                if (*point == '{')
                {
                    point++;
                    skip = colour (*point, ch, point2);
                    while (skip-- > 0)
                        ++point2;
                    continue;
                }
                *point2 = *point;
                *++point2 = '\0';
            }
            *point2 = '\0';
            write_to_buffer (ch->desc, buf, point2 - buf);
        }
        else
        {
            for (point = txt; *point; point++)
            {
                if (*point == '{')
                {
                    point++;
                    continue;
                }
                *point2 = *point;
                *++point2 = '\0';
            }
            *point2 = '\0';
            write_to_buffer (ch->desc, buf, point2 - buf);
        }
    }
    return;
}


The issue I'm having is this is a bit above my RUSTY programming expertise. I ripped out all the base Rom combat systems and implemented a weapon speed-type approach; fast weapons are causing a lot of prompt-redrawing spam, unfortunately. Here's an example over about 6 seconds:

Quote:

<546/546 hp 220/220 m 460/460 mv 60000/1000 xp>
Your slash hits Monster for 139 damage.
Your slash hits Monster for 152 damage.


<546/546 hp 220/220 m 460/460 mv 60000/1000 xp>
Your slash hits Monster for 135 damage.
Your slash hits Monster for 161 damage.

Testing tells you, 'testtest'.
<546/546 hp 220/220 m 460/460 mv 60000/1000 xp>
Monster's slice hits you for 5 damage.

<546/546 hp 220/220 m 460/460 mv 60000/1000 xp>
Your slash hits Monster for 142 damage.



What I'd like to do is, whenever a character is in combat, have the following prompt enabled instead:

Quote:

[100% 100%] Your slash hits Monster for 139 damage.

[100% 100%] Your slash hits Monster for 152 damage.

[100% 100%] Your slash hits Monster for 135 damage.

[100% 100%] Your slash hits Monster for 161 damage.

[100% 100%] Testing tells you, 'testtest'.

[100% 100%] Monster's slice hits you for 5 damage.

[100% 100%] Your slash hits Monster for 142 damage.


For argument's sake, the 100%s represent the character's and victim's health respectively.

Any help would be greatly appreciated - I would love to avoid having to drop in show_battleprompt(ch,victim) function calls all over the place :)
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Tue 17 Aug 2010 03:27 PM (UTC)
Message
Well, the first thing you need to do is test if the character is fighting. With SMAUG, that's as simple as testing ch->fighting, if I remember correctly. Then, you need to build up whatever data you want in a temporary string, write that to the character's buffer, and then do the normal send_to_char logic where you write the rest to the buffer.

Note that in some cases this might be wrong, because send_to_char is not necessarily an entire line. You can, in principle, write one line with several send calls. In that case you will print the prefix prompt too often.

Finally, in the function that normally sends the prompt, just abort the send if the character is in combat.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Drach   (3 posts)  [Biography] bio
Date Reply #2 on Tue 17 Aug 2010 05:24 PM (UTC)
Message
Rom is definitely the same way as ch->fighting, so that's good!

Your idea of building up a temporary string gave me an idea; I think if I hijack the main send_to_char() and rewrite it to basically be a show_battleprompt().

I can then combine the new string with the passed string and send it over to a send_to_char_new() where everything behaves as normal once again!

I'll give it a whirl tonight and see how it pans out - thanks so much for sparking the idea =)
[Go to top] top

Posted by Drach   (3 posts)  [Biography] bio
Date Reply #3 on Tue 17 Aug 2010 11:11 PM (UTC)

Amended on Wed 18 Aug 2010 12:41 AM (UTC) by Drach

Message
David Haley said:

Note that in some cases this might be wrong, because send_to_char is not necessarily an entire line. You can, in principle, write one line with several send calls. In that case you will print the prefix prompt too often.


Great foresight on this matter - this is going to end up being way more work than just dropping in a show_battleprompt() function throughout the applicable areas in the code.

EDIT: I hate giving up so I muscled through it! By sifting through lots of code and changing send_to_char()'s that did not have \n\r's into sprintfs & strcats I've modified it so this now works!

Quote:

The monster has a custom flag that processes damage but just doesn't take any - it's my combat test monster :)

[519hp 220hp] Your slash hits Monster for 153 damage.
[519hp 220hp] Your slash hits Monster for 145 damage.

[519hp 220hp] Monster's slice hits you for 11 damage.

[508hp 220hp] Your slash hits Monster for 132 damage.

[508hp 220hp] Monster's slice hits you for 17 damage.

[491hp 220hp] Your slash hits Monster for 135 damage.


Minor issue with health not updating until the next attack but I'm sure that's just an issue in fight.c with the damage messaging occurring before the damage is dealt.

I also shamelessly duplicated Morgenes @ Aladara's bust_a_prompt into bust_a_battleprompt.

I'm now calling it from void send_to_char():


...

    if (txt && ch->desc)
    {
        if (ch->fighting != NULL && IS_SET(ch->comm,COMM_BATTLEPROMPT))
            bust_a_battleprompt(ch);

        if (IS_SET (ch->act, PLR_COLOUR))
...


and void act();


...

        if (type == TO_NOTVICT && (to == ch || to == vch))
            continue;

        if (to->fighting != NULL && IS_SET(to->comm,COMM_BATTLEPROMPT))
            bust_a_battleprompt(to);

        point = buf;
        str = format;
...


Hopefully I don't run into problems later! Thanks again for responding!
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Wed 18 Aug 2010 03:53 PM (UTC)
Message
Nice :-) Glad that you got it worked out.

Drach said:
Minor issue with health not updating until the next attack but I'm sure that's just an issue in fight.c with the damage messaging occurring before the damage is dealt.

Yes, that's exactly what is happening. When you print the status information, you are sending to the character how much damage was dealt before doing it. They do it that way because you want to make sure that everybody is still alive to get the damage text before actually applying it; otherwise, you could end up with people being killed without seeing what killed them.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


4,413 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]