Welcome to the Builder Academy

Question Control weather

More
23 Mar 2016 01:11 #5678 by WhiskyTest
Replied by WhiskyTest on topic Control weather
You're correct:
cast_arg2 gets copied to 't'

't' is then checked against get_obj_vis searches or people in room searches.
By the time we get down to cast_spell, which is the next step, 't' has been used to set either tch or tobj, and the function is called like this: cast_spell(ch, tch, tobj, spellnum)

Is it possible to send the value of 't' through to cast_spell via *tch or *tobj?
Something like: cast_spell(ch, tch, (struct obj_data) *t, spellnum) ?

We'd have to do that with call_magic as well.

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

More
23 Mar 2016 07:00 #5679 by zusuk
Replied by zusuk on topic Control weather
Well, if you take a look, nothing overwrites the global variable cast_arg.... So the argument is preserved for usage. Example:
Code:
ASPELL(spell_control_weather) { char arg[MAX_INPUT_LENGTH] = {'\0'}; if (IS_NPC(ch) || !ch->desc) return; one_argument(cast_arg2, arg); /* THIS WILL WORK */ if (is_abbrev(arg, "worsen")) { } else if (is_abbrev(arg, "improve")) { } else { send_to_char(ch, "You need to cast this spell with an argument of either, " "'worsen' or 'improve' in order for it to be a success!\r\n"); return; } }

Sounds like a perfect situation to implement room events (if it hasn't been yet).

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100
The following user(s) said Thank You: WhiskyTest

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

More
23 Mar 2016 07:57 #5680 by WhiskyTest
Replied by WhiskyTest on topic Control weather
Mate that totally worked!
Though I don't fully understand how it can access cast_arg2, I thought you had to send it to the function specifically - this will make me rethink a LOT of my previous code :D

So here is my draft, what do you guys think?
Code:
ASPELL(spell_control_weather) { int change = -1; char arg[MAX_INPUT_LENGTH] = {'\0'}; if (IS_NPC(ch) || !ch->desc) return; /* Control Weather fails if you aren't outside */ if (ROOM_FLAGGED(IN_ROOM(ch), ROOM_INDOORS)) { send_to_char(ch, "Try as you might, you cannot maintain your control of the weather while indoors.\r\n"); act("A crackle of blue energy appears around $n for a brief moment before it fizzes out.", TRUE, ch, 0, 0, TO_ROOM); return; } one_argument(cast_arg2, arg); /* Thanks Zusuk! */ if (is_abbrev(arg, "worse")) { change = 1; /* this will increase weather_info.sky by one, making it worse */ weather_info.change -= dice(1, 6); /* weather_info.change being lower will slightly bias future natural weather shifts towards worse weather */ } else if (is_abbrev(arg, "better")) { change = -1; /* this will decrease weather_info.sky by one, making it better */ weather_info.change += dice(1, 6); /* weather_info.change being higher will slightly bias future natural weather shifts towards better weather */ } else { send_to_char(ch, "You need to cast this spell with an argument of either, " "'worse' or 'better' in order for it to be a success!\r\n"); return; } send_to_char(ch, "You unleash a crackle of blue energy into the atmosphere!\r\n"); act("$n unleashes a crackle of blue energy which dissolves into the air around $m!", TRUE, ch, 0, 0, TO_ROOM); /* Send to Outdoors each cast may be too spammy? */ if (change == -1) send_to_outdoor("The weather seems to be improving.\r\n"); else send_to_outdoor("The weather darkens.\r\n"); /* applies the changes to weather */ weather_info.sky += change; weather_info.sky = MIN(MAX(weather_info.sky, SKY_CLOUDLESS), SKY_LIGHTNING); }

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

More
23 Mar 2016 14:03 - 23 Mar 2016 14:05 #5681 by JTP
Replied by JTP on topic Control weather
How is the testing going ? Can you change weather ?

If you can, then it could be cool if a spell only can be cast in a certant weather type. Ie lightning bolt requires cloudy weather etc.
Last edit: 23 Mar 2016 14:05 by JTP.

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

More
23 Mar 2016 14:19 - 23 Mar 2016 14:49 #5682 by Kyle
Replied by Kyle on topic Control weather

If you can, then it could be cool if a spell only can be cast in a certant weather type. Ie lightning bolt requires cloudy weather etc.


This is the principle behind the call lightning spell for clerics. The idea is that mages can create a lightning bolt so do not need to depend on weather, whereas clerics have to manipulate the existing weather because they do not share any such power.

Though I don't fully understand how it can access cast_arg2, I thought you had to send it to the function specifically - this will make me rethink a LOT of my previous code :D


The fact that cast_arg2 is a global variable is the reason that it can be accessed in any file by any function, so long as the file knows it exists.

Note that while these seems to make things simpler, and might make it seem tempting to make more variable global, it is in general a bad habit to get into, and should only be done in certain circumstances.

Historical Note: Jamdog added the global variable cast_arg2 (there seemed no other reasonable thing to do without adding very ugly code) in 2008 in order to improve upon the what was at the time a very flawed locate_object spell which originally did a poor job of responding to what the caster was actually searching for. It turns out to be a valuable tool in all cases where the argument passed to a spell cannot be converted to an item in the same room as the caster.
Last edit: 23 Mar 2016 14:49 by Kyle.

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

More
24 Mar 2016 13:11 - 24 Mar 2016 13:13 #5684 by JTP
Replied by JTP on topic Control weather
Except call_lightning is just a damage spell, with no checks of weather in the standard tba code.
Code:
case SPELL_CALL_LIGHTNING: dam = dice(7, 8) + 7; break;
Last edit: 24 Mar 2016 13:13 by JTP.

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

Time to create page: 0.239 seconds