Welcome to the Builder Academy

Question How to add damage bonus to happyhour

More
23 Mar 2018 17:31 #7768 by Nero
Looking to add damage bonus to happyhour but need some general guidance on where to start on this.
I started with utils.c and added:
Code:
int adjust_damage(struct char_data *ch, struct char_data *victim, int dam, int attacktype, bool critical_hit) { int vict_resist = get_capped_resistance(victim, convert_damage_type_to_resistance(attacktype)); //DAMAGE INCREASORS GO HERE if (critical_hit) dam *= 2.0; /* * Include a damage multiplier if victim isn't ready to fight: * * Position sitting 1.33 x normal * Position resting 1.66 x normal * Position meditating 2.00 x normal * Position sleeping 2.33 x normal * Position stunned 2.66 x normal * Position incapac 3.00 x normal * Position paralyzed 3.00 x normal * Position mortally 3.33 x normal * * Note, this is a hack because it depends on the particular * values of the POSITION_XXX constants. */ if (!IS_NPC(victim) || (AFF_FLAGGED(ch, AFF_CHARM)) && HAPPY_DMG >= .0001) dam = ((1 * HAPPY_DMG) / 100);

I also added it to act.other.c where I keep the code for happyhour.
I am however getting this error:
Code:
act.other.c: In function `show_happyhour': act.other.c:1576: error: `happydmg' undeclared (first use in this function) act.other.c:1576: error: (Each undeclared identifier is reported only once act.other.c:1576: error: for each function it appears in.) act.other.c:1576: error: `HAPPY_DMG' undeclared (first use in this function) act.other.c: In function `do_happyhour': act.other.c:1623: error: `HAPPY_DMG' undeclared (first use in this function) act.other.c:1679: warning: format argument is not a pointer (arg 15) act.other.c:1679: warning: too few arguments for format act.other.c:1681:2: warning: no newline at end of file make[1]: *** [act.other.o] Error 1 make[1]: Leaving directory `/cygdrive/e/apoc/cwe/src' make: *** [all] Error 2

Any help would be nice if anyone has any advice on how to get this damage bonus working!

Thanks!

Please Log in or Create an account to join the conversation.

More
23 Mar 2018 18:11 - 23 Mar 2018 18:13 #7769 by Papaya Pete
At a glance, it looks like there are some variables that are undeclared: HAPPY_DAM and happydmg.

Personally, I would actually do this work over in the damage() function found in fight.c. Well, actually, you could make your below function anywhere, but I would just call it over in damage(). For example...
Code:
int damage(struct char_data *ch, struct char_data *victim, int dam, int attacktype) { long local_gold = 0, happy_gold = 0; char local_buf[256]; struct char_data *tmp_char; struct obj_data *corpse_obj; if (GET_POS(victim) <= POS_DEAD) { /* This is "normal"-ish now with delayed extraction. -gg 3/15/2001 */ if (PLR_FLAGGED(victim, PLR_NOTDEADYET) || MOB_FLAGGED(victim, MOB_NOTDEADYET)) return (-1); log("SYSERR: Attempt to damage corpse/loot '%s' in room #%d by '%s'.", GET_NAME(victim), GET_ROOM_VNUM(IN_ROOM(victim)), GET_NAME(ch)); die(victim, ch); return (-1); /* -je, 7/7/92 */ } /* peaceful rooms */ if (ch->nr != real_mobile(DG_CASTER_PROXY) && ch != victim && ROOM_FLAGGED(IN_ROOM(ch), ROOM_PEACEFUL)) { send_to_char(ch, "This room just has such a peaceful, easy feeling...\r\n"); return (0); } /* shopkeeper and MOB_NOKILL protection */ if (!ok_damage_shopkeeper(ch, victim) || MOB_FLAGGED(victim, MOB_NOKILL)) { send_to_char(ch, "Why would you want to do that??\r\n"); return (0); } /* You can't damage an immortal! */ if (!IS_NPC(victim) && ((GET_LEVEL(victim) >= LVL_IMMORT) && PRF_FLAGGED(victim, PRF_NOHASSLE))) dam = 0; if (victim != ch) { /* Start the attacker fighting the victim */ if (GET_POS(ch) > POS_STUNNED && (FIGHTING(ch) == NULL)) set_fighting(ch, victim); /* Start the victim fighting the attacker */ if (GET_POS(victim) > POS_STUNNED && (FIGHTING(victim) == NULL)) { set_fighting(victim, ch); if (MOB_FLAGGED(victim, MOB_MEMORY) && !IS_NPC(ch)) remember(victim, ch); } } /* If you attack a pet, it hates your guts */ if (victim->master == ch) stop_follower(victim); /* If the attacker is invisible, he becomes visible */ if (AFF_FLAGGED(ch, AFF_INVISIBLE) || AFF_FLAGGED(ch, AFF_HIDE)) appear(ch); /* Call that beautiful bean footage(), I mean, adjust_damage() function here */ /* Cut damage in half if victim has sanct, to a minimum 1 */ if (AFF_FLAGGED(victim, AFF_SANCTUARY) && dam >= 2) dam /= 2; /* Check for PK if this is not a PK MUD */ if (!CONFIG_PK_ALLOWED) { check_killer(ch, victim); if (PLR_FLAGGED(ch, PLR_KILLER) && (ch != victim)) dam = 0; } /* Set the maximum damage per round and subtract the hit points */ dam = MAX(MIN(dam, 100), 0); GET_HIT(victim) -= dam;

This is just the beginning of the damage() function, I haven't added anything to it regarding this topic (except the comment). You could add a call to your adjust_damage() function before damage is halved due to target having sanctuary on.

What does your happyhour() function look like? For an idea on how to check to see if it is happy hour (and to call your function), take a look over at where experience is gained and see how it checks for happy hour.
Last edit: 23 Mar 2018 18:13 by Papaya Pete.

Please Log in or Create an account to join the conversation.

More
23 Mar 2018 18:32 - 24 Mar 2018 01:53 #7770 by lacrc
Yeah I agree with Papaya Pete, you should probably add the increase in damage in fight.c.
edit: looking at the comments, ajust_damage() is called at hit()? That should be fine! :)

On the other hand, a little more specific about the variable errors:
For 'happydmg' I think you need to declare a string in show_happyhour() in act.other.c, right at the beginning, along with the other ones:
Code:
char happyexp[80], happygold[80], happyqp[80], happydmg[80];
Keep in mind that the 80 is the size of the string so declare it bigger if you need more space.

The other variable is a macro, but you might need more than just the one is in your warnings, in utils.h look for:
Code:
/* Happy-hour defines */
And you'll see that there's three macros defined for each happy hour.
I think you need to add the following:
- These macros check if it's currently on (you can use them instead of manually checking the value yourself):
Code:
#define IS_HAPPYQP (happy_data.qp_rate > 0) #define IS_HAPPYEXP (happy_data.exp_rate > 0) #define IS_HAPPYGOLD (happy_data.gold_rate > 0) #define IS_HAPPYDMG (happy_data.dmg_rate > 0)
- These to get the current rate of the bonuses:
Code:
#define HAPPY_EXP happy_data.exp_rate #define HAPPY_GOLD happy_data.gold_rate #define HAPPY_QP happy_data.qp_rate #define HAPPY_DMG happy_data.dmg_rate
- And this is a general one that checks if there's any happyhour bonus currently on:
Code:
#define IS_HAPPYHOUR ((IS_HAPPYEXP || IS_HAPPYGOLD || IS_HAPPYQP || IS_HAPPYDMG) && (HAPPY_TIME > 0))

You're also gonna need to add the "Damage" rate to the happy_data structure. For that you need two more changes.
In db.c look for:
Code:
struct happyhour happy_data = {0, 0, 0, 0};
and change it to add another 'happy' variable:
Code:
struct happyhour happy_data = {0, 0, 0, 0, 0};

And in structs.h look for:
Code:
/** Happy Hour Data */ struct happyhour { int qp_rate; int exp_rate; int gold_rate; int ticks_left; };
And add the damage rate:
Code:
/** Happy Hour Data */ struct happyhour { int qp_rate; int exp_rate; int gold_rate; int dmg_rate; /* I don't the position here matters, but it makes more sense to come before ticks :) */ int ticks_left; };

I **THINK** that should do it. Again, I'm kinda new here so sorry if I said some bs! heh.
Let me know if you need more help.
Last edit: 24 Mar 2018 01:53 by lacrc.

Please Log in or Create an account to join the conversation.

More
24 Mar 2018 02:26 #7780 by Nero
Thanks, I performed all the suggestions above however I am running into a problem.
It seems the damage bonus has pushed itself down into the time remaining. Also, after setting the happyhour to default and then trying to do happyhour show again, it crashes the game:

Current Happy Hour!
+0% to Experience per kill
+0% to Gold gained per kill
+0% to Questpoints per quest
Time Remaining: +0% to Damage per kill
5363331(null) hours 5363331(null) mins 5363331(null) secs


Code:
/* Only Imms get here, so check args */ two_arguments(argument, arg, val); if (is_abbrev(arg, "experience")) { num = MIN(MAX((atoi(val)), 0), 1000); HAPPY_EXP = num; send_to_char(ch, "Happy Hour Exp rate set to +%d%%\r\n", HAPPY_EXP); } else if ((is_abbrev(arg, "gold")) || (is_abbrev(arg, "coins"))) { num = MIN(MAX((atoi(val)), 0), 1000); HAPPY_GOLD = num; send_to_char(ch, "Happy Hour Gold rate set to +%d%%\r\n", HAPPY_GOLD); } else if ((is_abbrev(arg, "damage")) || (is_abbrev(arg, "dmg"))) { num = MIN(MAX((atoi(val)), 0), 1000); HAPPY_DMG = num; send_to_char(ch, "Happy Hour Damage rate set to +%d%%\r\n", HAPPY_DMG); } else if ((is_abbrev(arg, "time")) || (is_abbrev(arg, "ticks"))) { num = MIN(MAX((atoi(val)), 0), 1000); if (HAPPY_TIME && !num) game_info("Happyhour has been stopped!"); else if (!HAPPY_TIME && num) game_info("A Happyhour has started! Type happyhour to see the current bonuses!"); HAPPY_TIME = num; send_to_char(ch, "Happy Hour Time set to %d ticks (%d hours %d mins and %d secs)\r\n", HAPPY_TIME, (HAPPY_TIME*SECS_PER_MUD_HOUR)/3600, ((HAPPY_TIME*SECS_PER_MUD_HOUR)%3600) / 60, (HAPPY_TIME*SECS_PER_MUD_HOUR)%60 ); } else if ((is_abbrev(arg, "qp")) || (is_abbrev(arg, "questpoints"))) { num = MIN(MAX((atoi(val)), 0), 1000); HAPPY_QP = num; send_to_char(ch, "Happy Hour Questpoints rate set to +%d%%\r\n", HAPPY_QP); } else if (is_abbrev(arg, "show")) { show_happyhour(ch); } else if (is_abbrev(arg, "default")) { HAPPY_EXP = 100; HAPPY_GOLD = 50; HAPPY_QP = 50; HAPPY_DMG = 50; HAPPY_TIME = 48; game_info("A Happyhour has started! Type happyhour to see the current bonuses!"); } else { send_to_char(ch, "Usage: %shappyhour %s- show usage (this info)\r\n" " %shappyhour show %s- display current settings (what mortals see)\r\n" " %shappyhour time <ticks> %s- set happyhour time and start timer\r\n" " %shappyhour qp <num> %s- set qp percentage gain\r\n" " %shappyhour exp <num> %s- set exp percentage gain\r\n" " %shappyhour gold <num> %s- set gold percentage gain\r\n" " happyhour dmg <num> - set dmg percentage gain\r\n" " happyhour default - sets a default setting for happyhour\r\n\r\n" "Configure the happyhour settings and start a happyhour.\r\n" "Currently 1 tick IRL = 75 seconds\r\n" "If no number is specified, 0 (off) is assumed.\r\nThe command happyhour time 0 will therefore stop the happyhour timer.\r\n", CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), CCYEL(ch, C_NRM), CCNRM(ch, C_NRM), (3600 / SECS_PER_MUD_HOUR) ); } }

Please Log in or Create an account to join the conversation.

More
24 Mar 2018 05:28 #7781 by Nero
Thanks I was able to get this to work! :)

Please Log in or Create an account to join the conversation.

More
24 Mar 2018 12:43 - 24 Mar 2018 13:31 #7785 by lacrc
Cool! Nice that you got it working!

Thinking about it, I think I forgot about the changes in show_happyhour() right? Sorry about that! :P
In case anyone need these in the future, you gotta change the following lines in show_happyhour() in act.other.c:
Right after:
Code:
sprintf(happyexp, "%s+%d%%%s to Experience per kill\r\n", CCYEL(ch, C_NRM), HAPPY_EXP, CCNRM(ch, C_NRM));
add the line that will show the damage bonus:
Code:
sprintf(happydmg, "%s+%d%%%s to Damage\r\n", CCYEL(ch, C_NRM), HAPPY_DMG, CCNRM(ch, C_NRM));
Then add it to the bonus list for showing bonus. First add an extra %s at the beginning here:
Code:
"%s%s%sTime Remaining: %s%d%s hours %s%d%s mins %s%d%s secs\r\n",
Like this:
Code:
"%s%s%s%sTime Remaining: %s%d%s hours %s%d%s mins %s%d%s secs\r\n",
Then after:
Code:
(IS_HAPPYQP || (GET_LEVEL(ch) >= LVL_GOD)) ? happyqp : "",
Add:
Code:
(IS_HAPPYDMG || (GET_LEVEL(ch) >= LVL_GOD)) ? happydmg: "",
And I **think** you'll be good to go! :)

I'll also attach a patch to this post.
Have a good one!

(For those getting the patch, please double check the damage bonus in fight.c, didn't get to actually testing it)

Attachment happy_damage.patch.txt not found

Attachments:
Last edit: 24 Mar 2018 13:31 by lacrc.
The following user(s) said Thank You: thomas

Please Log in or Create an account to join the conversation.

Time to create page: 0.225 seconds