24 Jan, 2012, arholly wrote in the 1st comment:
Votes: 0
OK, I am looking for suggestions and/or improvements. I'm a relatively new coder but am learning enough to realize there has to be a better way to do things in my "disciplines/powers", the thing is, I'm not exactly sure how. I'm looking at my powers as they are coded and see the same things repeated over and over. Oh, let me not forget to mention I'm using a highly modified ROM codebase, so it's in C.

For example, every one of the powers we have does a power_timer check, which is this.
if(ch->power_timer > 0)
{
send_to_char("Your powers have not rejuvenated yet.\n\r", ch);
return;
}

Could I make this it's own function and just put in a one-line check in each power instead of three or four lines of code? Or, is there a better way?

Likewise, we have another check like this we use a lot:
if(ch->RBPG <= 2)
{
send_to_char("You don't have enough blood for that.\n\r", ch);
return;
}

I'm seeing it done a lot of different ways due to inconsistent coding practices and I'd like to make it cleaner and more efficient code. So, I'm looking for a little guidance and suggestions?

Thanks in advance,
Arholly
24 Jan, 2012, Tyche wrote in the 2nd comment:
Votes: 0
This?

where called…
if (!has_enough_power(ch)) return;

new function
int has_enough_power(CHAR_DATA *ch) {
if (ch->power_timer > 0)
{
send_to_char("Your powers have not rejuvenated yet.\n\r", ch);
return 0;
}
return 1;
}
25 Jan, 2012, andril wrote in the 3rd comment:
Votes: 0
For the blood bit it would depend on if each power had a different cost or not. Either way it would be a very simple modification of what Tyche showed already for the ch->power_timer issue.
0.0/3