# Question Control weather

21 Mar 2016 21:49 #5641
Replied by WhiskyTest on topic Control weather
Sounds good! I'll have a dabble as well and see if anything inspired comes up, I haven't tried coding any spells before so this should be interesting

21 Mar 2016 23:04 - 21 Mar 2016 23:05 #5642 by Kyle
Replied by Kyle on topic Control weather
If you're new to coding spells, take a look at the following to help you get started.

First, the definition of the weather_data structure (in structs.h), which is a data structure that defines how weather information is stored.
Code:
struct weather_data { int pressure; /* How is the pressure ( Mb ) */ int change; /* How fast and what way does it change. */ int sky; /* How is the sky. */ int sunlight; /* And how much sun. */ };

Second, the declaration of the global variable weather_info, which is what actually uses the above structure to store the weather information, as it fluctuates in game, which is declared in db.c
Code:
struct weather_data weather_info; /* The infomation about the weather. */

Lastly, for examples on how to manipulate and use this data, check out the weather_change function (which is defined in weather.c).
Code:
void weather_change(void) { int diff; int change; if ((time_info.month >= 9) && (time_info.month <= 16)) diff = (weather_info.pressure > 985 ? -2 : 2); else diff = (weather_info.pressure > 1015 ? -2 : 2); weather_info.change += (dice(1, 4) * diff + dice(2, 6) - dice(2, 6)); weather_info.change = MIN(weather_info.change, 12); weather_info.change = MAX(weather_info.change, -12); weather_info.pressure += weather_info.change; weather_info.pressure = MIN(weather_info.pressure, 1040); weather_info.pressure = MAX(weather_info.pressure, 960); change = 0; switch (weather_info.sky) { case SKY_CLOUDLESS: if (weather_info.pressure < 990) change = 1; else if (weather_info.pressure < 1010) if (dice(1, 4) == 1) change = 1; break; case SKY_CLOUDY: if (weather_info.pressure < 970) change = 2; else if (weather_info.pressure < 990) { if (dice(1, 4) == 1) change = 2; else change = 0; } else if (weather_info.pressure > 1030) if (dice(1, 4) == 1) change = 3; break; case SKY_RAINING: if (weather_info.pressure < 970) { if (dice(1, 4) == 1) change = 4; else change = 0; } else if (weather_info.pressure > 1030) change = 5; else if (weather_info.pressure > 1010) if (dice(1, 4) == 1) change = 5; break; case SKY_LIGHTNING: if (weather_info.pressure > 1010) change = 6; else if (weather_info.pressure > 990) if (dice(1, 4) == 1) change = 6; break; default: change = 0; weather_info.sky = SKY_CLOUDLESS; break; } switch (change) { case 0: break; case 1: send_to_outdoor("The sky starts to get cloudy.\r\n"); weather_info.sky = SKY_CLOUDY; break; case 2: send_to_outdoor("It starts to rain.\r\n"); weather_info.sky = SKY_RAINING; break; case 3: send_to_outdoor("The clouds disappear.\r\n"); weather_info.sky = SKY_CLOUDLESS; break; case 4: send_to_outdoor("Lightning starts to show in the sky.\r\n"); weather_info.sky = SKY_LIGHTNING; break; case 5: send_to_outdoor("The rain stops.\r\n"); weather_info.sky = SKY_CLOUDY; break; case 6: send_to_outdoor("The lightning stops.\r\n"); weather_info.sky = SKY_RAINING; break; default: break; } }

21 Mar 2016 23:06 #5643 by Kyle
Replied by Kyle on topic Control weather
Also, if you're keen I'm more than happy to back off and let you tackle this. But feel free to ask any questions if you get stuck along the way. I'm trying to get back into coding currently, and dialogue is a much more fun way to do it than just sitting reading code in isolation.

21 Mar 2016 23:09 #5644 by JTP
Replied by JTP on topic Control weather
Im sure if the two of you work together, then TBA will soon have a nice control weather spell

22 Mar 2016 20:59 - 22 Mar 2016 21:00 #5667
Replied by WhiskyTest on topic Control weather
Cool lets do it together!
I started familiarizing myself with the related functions, the reason there is no CW spell currently is because the spell routines do not handle arguments.

That is, if you type 'cast "spellname" argument' the functions treat argument as either a target object or character.

So the first changes required would be to allow arguments being passed through to spells that can be 'worse' 'better' and so on. A bigger change than I originally thought but it does expand the possibilities for future spells.

Example:
add char *argument to call_magic, MANUAL_SPELL, and ASPELL definitions.
Code:
int call_magic(struct char_data *caster, struct char_data *cvict, struct obj_data *ovict, int spellnum, int level, int casttype, char *argument) #define MANUAL_SPELL(spellname, argument) spellname(level, caster, cvict, ovict, argument);

Then update each ASPELL to be ASPELL(spell_name, argument)

This works in the brief testing I've done.
But is there a better way to go about this before I get too far in ?

22 Mar 2016 21:20 #5668 by zusuk
Replied by zusuk on topic Control weather
That should not be necessary, there is a global char pointer that holds the argument you use to cast a spell, an example would be the spell locate object.

The variable is:
cast_arg2

Something like that, check out locate object though for an example of the argument being carried in.

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100