The Dawn Of Time
The Official Forums for the Dawn Of Time Mud Codebase
 
Log in Register FAQ Memberlist Search The Dawn Of Time Forum Index Goto the Official Dawn Website

Porting the spellup global code

 
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Migration/Porting
View previous topic :: View next topic  
Author Message
Pyros



Joined: 05 Mar 2003
Posts: 56

PostPosted: Fri Mar 07, 2003 9:29 am    Post subject: Porting the spellup global code Reply with quote

okay we have a player friendly abuse unfriendly code

Basically you type spellup (name of person) or global
and it refreshes mana health and movement points on everyone
and then casts shield and armor on them at there level so even
if a 100 level imm casts it a level 5 player only gets spelled up
to a level 5 version.

here is the code (please ask for permission before using it yourself)

How will i implement this in DOT

void do_spellup( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *victim;
char arg [ MAX_INPUT_LENGTH ];
int sn,level;
AFFECT_DATA af;

one_argument( argument, arg );

if ( arg[0] == '\0' )
{
send_to_char(AT_WHITE, "Syntax: Spellup global [Spells the world up]\n\rSyntax: Spellup <player>\n\r", ch );
return;
}

if ( !strcmp( arg, "global") )
{
DESCRIPTOR_DATA *d;

for ( d = descriptor_list; d; d = d->next )
{
victim = ( d->original ) ? d->original : d->character;

// Can't cast on people not playing
if ( d->connected != CON_PLAYING || IS_NPC( victim ))
continue;

// Cannot spellup an outcasted player
if ( IS_SET( victim->act, PLR_OUTCAST ) )
continue;


level = victim->level;
if ( level < 20 ) level = 20;
sn = skill_lookup( "shield" );
if ( !is_affected( victim, sn ) )
{
af.type = sn;
af.level = level;
af.duration = 8 + level;
af.location = APPLY_AC;
af.modifier = -30;
af.bitvector = 0;
affect_to_char( victim, &af );
send_to_char(AT_BLUE, "You are surrounded by a force shield.\n\r", victim );
}

sn = skill_lookup( "sanctuary" );
if ( !IS_AFFECTED( victim, AFF_SANCTUARY ) )
{
af.type = sn;
af.level = level;
af.duration = number_fuzzy( level / 8 );
af.location = APPLY_NONE;
af.modifier = 0;
af.bitvector = AFF_SANCTUARY;
affect_to_char( victim, &af );
send_to_char(AT_WHITE, "You are surrounded by a white aura.\n\r", victim );
}

sn = skill_lookup( "armor" );
if ( !is_affected( victim, sn ) )
{
af.type = sn;
af.level = level;
af.duration = 24;
af.location = APPLY_AC;
af.modifier = -25;
af.bitvector = 0;
affect_to_char( victim, &af );
send_to_char(AT_BLUE, "You feel someone protecting you.\n\r", victim );
}

sn = skill_lookup( "haste" );
if (!(( is_affected( victim, sn )) || IS_WWF( victim) || is_race( victim, RACE_ELF ) || IS_AFFECTED(victim, AFF_HASTE)))
{
af.type = sn;
af.level = level;
af.duration = level/4;
af.location = APPLY_DEX;
af.modifier = 1 + (level >= 1Cool + (level >= 25) + (level >= 32);
af.bitvector = AFF_HASTE;
affect_to_char( victim, &af );
send_to_char(C_DEFAULT, "You feel yourself moving more quickly.\n\r", victim );
}


//restore the player
victim->hit = MAX_HIT(victim);
victim->mana = MAX_MANA(victim);
victim->bp = MAX_BP(victim);
victim->move = MAX_MOVE(victim);

}
}
else
{
if ( !( victim = get_char_world( ch, arg ) ) )
{
send_to_char(AT_WHITE, "They aren't here.\n\r", ch );
return;
}

if ( IS_NPC( ch ) )
return;

if ( IS_SET( victim->act, PLR_OUTCAST ) )
{
send_to_char(AT_WHITE, "You cannot spellup an Outcasted player.\n\r", ch );
return;
}

level = victim->level;
if ( level < 20 ) level = 20;
sn = skill_lookup( "shield" );
if ( !is_affected( victim, sn ) )
{
af.type = sn;
af.level = level;
af.duration = 8 + level;
af.location = APPLY_AC;
af.modifier = -30;
af.bitvector = 0;
affect_to_char( victim, &af );
send_to_char(AT_BLUE, "You are surrounded by a force shield.\n\r", victim );
}

sn = skill_lookup( "sanctuary" );
if ( !(IS_AFFECTED( victim, AFF_SANCTUARY ) ) )
{
af.type = sn;
af.level = level;
af.duration = number_fuzzy( level / 8 );
af.location = APPLY_NONE;
af.modifier = 0;
af.bitvector = AFF_SANCTUARY;
affect_to_char( victim, &af );
send_to_char(AT_WHITE, "You are surrounded by a white aura.\n\r", victim );
}

sn = skill_lookup( "armor" );
if ( !is_affected( victim, sn ) )
{
af.type = sn;
af.level = level;
af.duration = 24;
af.location = APPLY_AC;
af.modifier = -25;
af.bitvector = 0;
affect_to_char( victim, &af );
send_to_char(AT_BLUE, "You feel someone protecting you.\n\r", victim );
}

sn = skill_lookup( "haste" );
if (!(( is_affected( victim, sn )) || IS_WWF( victim) || is_race( victim, RACE_ELF ) || IS_AFFECTED(victim, AFF_HASTE)))
{
af.type = sn;
af.level = level;
af.duration = level/4;
af.location = APPLY_DEX;
af.modifier = 1 + (level >= 1Cool + (level >= 25) + (level >= 32);
af.bitvector = AFF_HASTE;
affect_to_char( victim, &af );
send_to_char(C_DEFAULT, "You feel yourself moving more quickly.\n\r", victim );
}


victim->hit = MAX_HIT(victim);
victim->mana = MAX_MANA(victim);
victim->bp = MAX_BP(victim);
victim->move = MAX_MOVE(victim);
}
return;
}


Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ganieda



Joined: 08 Feb 2003
Posts: 297
Location: US

PostPosted: Sat Mar 08, 2003 1:07 am    Post subject: Reply with quote

you could shorten that alot using do_cast() and do_restore(), if you're interested


Back to top
View user's profile Send private message Send e-mail
Pyros



Joined: 05 Mar 2003
Posts: 56

PostPosted: Sat Mar 08, 2003 1:36 am    Post subject: Reply with quote

ganieda wrote:
you could shorten that alot using do_cast() and do_restore(), if you're interested


We have a do_cast and do_restore ??

Smile thankyou i'll go look them up


Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Kalahn
Codebase Developer


Joined: 18 Jan 2003
Posts: 710
Location: New Zealand

PostPosted: Sat Mar 08, 2003 12:27 pm    Post subject: Reply with quote

Also use gsn_haste instead of spell_lookup("haste");
in gsn.h all the gsn (global skill/spell number) are defined.

Pretty much everything is in the format gsn_<spell_or_skill_name>

Dawn uses "\n\r" in place of "\r\n" through out the entire codebase... this is because based on Internet RFC's and existing operating systems, \n\r is wrong. \n = new line in unix, \r = newline on mac, \r\n = new line on DOS. In HTTP/1.1 a new line is defined as CRLF (\r\n) see the official HTTP specification for more details if interested.

Use ch->println("zzz"); in place of send_to_char("zzz\n\r", ch);
Use ch->print("zzz"); in place of send_to_char("zzz", ch);

Dawn uses generally provides more descriptive error messages and attempts to show user the input they provided. Additionally inline colour codes are used instead of things like AT_WHITE... so in the case of something like:
Code:

if ( !( victim = get_char_world( ch, arg ) ) )
{
    send_to_char(AT_WHITE, "They aren't here.\n\r", ch );
    return;
}

I would probably write something like (with dawns style of brace alignment):
Code:

if ( !( victim = get_whovis_player_world( ch, arg ) ) ) {
    ch->printlnf("`WYou can't seem to find any '%s' within the realm.`x", arg);
    return;
}


Notice I also used get_whovis_player_world()... this basically checks all players which ch can see on the wholist... it has the benefit of being more efficient and not casting the spell on mobs. Then again if you want the spell to be used on mobs, then you wouldn't use this.

ch->printlnf() is basically like the standard C libraries printf function only the output goes to ch, and a new line (\r\n) is appended to the output.

Dawn additionally will often return a message to the user of a command when returning for an unexpected user... for example.
Code:
if ( IS_NPC( ch ) )
return;

becomes:
Code:
if ( IS_NPC( ch ) ) {
  ch->println("This spell can only be cast by players sorry.");
  return;
}


Additionally (the list never ends Wink)...
Code:
if ( !strcmp( arg, "global") )


Would become
Code:
if ( !str_cmp( arg, "global") )

str_cmp is the codebase string comparision function which is case insensitive... you could even look at using str_prefix() instead which means you don't have to type the entire word "global".

Code:
if ( arg[0] == '\0' )

is replaced with the much more readible (and safer) macro
Code:
if ( IS_NULLSTR(arg))


Hope this helps, there are probably a lot of other things I would do if porting a snippet like this... then again, typically I find it easier to write something from scratch due to the number of changes generally required.



_________________
Kalahn
Developer of the Dawn of Time Codebase
http://www.dawnoftime.org/
Back to top
View user's profile Send private message Visit poster's website
Pyros



Joined: 05 Mar 2003
Posts: 56

PostPosted: Sat Mar 08, 2003 9:10 pm    Post subject: Reply with quote

It helps alot, actually your right I think I will start from scratch, my main problem is I self taught myself C coding on the eos code base not the best example of code, its going to take awhile to relearn this.

Thankyou for all the excellent help it is apreciated.


Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Migration/Porting All times are GMT + 13 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2005 phpBB Group
Theme created by Vjacheslav Trushkin