Water in the Desert? (Attn. Big Guys!!!)

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).

Pages

AuthorTopic: Water in the Desert? (Attn. Big Guys!!!)
Off With Their Heads
Member # 4045
Profile Homepage #25
Using other people's code is perfectly fine (and in fact preferred, wherever possible), as long as you give credit to the original authors. In a similar fashion, I "borrow" graphics incessantly, and the readme for my scenario will have a long chunk crediting each artist who created the graphics I'm using.

Here's the newest version. This seems to work, as far as I can tell. I think I'll post it in the Codex, too.

// Dehydration v1.2
// dehydration.txt
// Original version by Dahak.
// Revised thoroughly by Kelandon (tomwatts@berkeley.edu).
//
// This general script checks if the party has a special item, water, and does
// increasing amounts of damage to the party if they don't have it. This
// simulates thirst, as in a desert.
//
// This script should probably go in the scenario script and be run in the
// START_STATE, as depicted below.
//
// This script uses three SDFs. The default SDFs to use are (250,0), (250,1),
// and (250,2). If you want to use others, replace the values in the variables
// section. Several other values are editable, too.

variables;

// How many turns since the party last had water.
short last_drank;

// ALL OF THE FOLLOWING VARIABLES CAN BE EDITED TO SUIT WHATEVER YOUR SCENARIO'S
// SPECIFIC NEEDS ARE. CHANGE THEIR VALUES TO WHATEVER YOU LIKE.

// Change the following variable to whatever special item the water is.
short water = 0;

// Change the following variables to the coordinates of the SDFs keeping track
// of the time between water checks. This works by using the SDFs as a two-digit
// base-256 number. That is, the first SDF set to 5 and the second set to 2
// means that 2 * 256 + 5 (equalling 517) turns have passed since the last water
// check.
short sdf_x = 250;
short sdf_y1 = 0;
short sdf_y2 = 1;

// Change the following variables to the coordinates of the SDF keeping track
// of how many consecutive times the party has failed a water check.
short thirst_sdf_x = 0;
short thirst_sdf_y = 2;

// Change the following variable if you want the party to dehydrate slower or
// faster. This is the number of turns between each water check. NOTE: This can
// reasonably go up as high as sixty-five thousand. Any more than that, and you
// will need to add more SDFs to keep track of the ticks in between water
// checks.
short dehyd_speed = 500;

// Change the following variable if you want the party to die of dehydration
// slower or faster. This times dehyd_speed equals the number of turns without
// water after which the party will automatically die.
short dead_of_thirst = 8;

beginstate START_STATE;

// Figure out how many turns it has been since the party drank water and save
// that in last_drank.
last_drank = (get_flag(sdf_x,sdf_y2) * 256) + get_flag(sdf_x,sdf_y1);

// Check if enough time has passed since the last water check. If so, proceed.
if (last_drank >= dehyd_speed) {

// If the party has water, drink it.
if(has_special_item(water)) {
print_str("You drink some water.");
change_spec_item(water,-1);

// Reset all flags and counters.
set_flag(thirst_sdf_x,thirst_sdf_y,0);
set_flag(sdf_x,sdf_y2,0);
set_flag(sdf_x,sdf_y1,0);
}

// If the party doesn't have water, do other things.
else {
// Damage them based on how long they've been thirsty (recorded in the
// variable thirst_turns).
inc_flag(thirst_sdf_x,thirst_sdf_y,1);
damage_char(1000,(10 * get_flag(thirst_sdf_x,thirst_sdf_y)) + get_ran(1,0,9),4);
print_str ("You're thirsty!");

// Reset flags.
set_flag(sdf_x,sdf_y2,0);
set_flag(sdf_x,sdf_y1,0);

// Warn them if they're dying.
if (get_flag(thirst_sdf_x,thirst_sdf_y) == dead_of_thirst - 1)
print_str_color("YOU ARE NEAR DEATH. YOU NEED WATER.",1);

// If they are too thirsty, kill them.
if (get_flag(thirst_sdf_x,thirst_sdf_y) == dead_of_thirst) {
message_dialog("You die of thirst!","");
kill_char(1000,2,0);
}
}
}

// Increment the SDFs keeping track of time. This works differently outdoors
// because although ten ticks pass for every step, the START_STATE is only
// called once per step.
if (get_flag(sdf_x,sdf_y1) < 255 - (9 * is_outdoor()))
inc_flag(sdf_x,sdf_y1,1 + (9 * is_outdoor()));
else {
inc_flag(sdf_x,sdf_y2,1);
set_flag(sdf_x,sdf_y1,0);
}

break;


--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Infiltrator
Member # 148
Profile #26
A very nice and concise script Keladon.

EDIT:
And no, I did not guess that the variables would reset. It mentions/alludes to that fact in the BoA Docs.

[ Wednesday, August 18, 2004 16:09: Message edited by: Dahak ]

--------------------
My ego is bigger than yours.
Posts: 480 | Registered: Thursday, October 11 2001 07:00
Warrior
Member # 1250
Profile #27
Okay... when it comes to modifying this for my own purposes, I have a couple of small, dumb questions... a tick is one step, outdoors, unless there's some call like set_ticks_forward, or something similar, correct?

I had another question about the SDFs in the script, but I think I can answer that one myself...

EDIT: I was poking around in the code, and I'm going to have to add a bit... Where you put change_spec_item(water,-1), I'm adding, after that, change_spec_item(empty,1), and adding the appropriate short variable. Ideally, this will be a circular process, with the chance to fill empty water bags at watering holes, towns, et cetera. Let me know if you have any ideas on that... although filling will be far easier a code than dehydration.

[ Thursday, August 19, 2004 04:00: Message edited by: Guardian of Eternity ]
Posts: 93 | Registered: Saturday, June 1 2002 07:00
Off With Their Heads
Member # 4045
Profile Homepage #28
Oh, I forgot about that part, the empty water flasks. Yeah, that sounds like it would work just fine.

A tick is one step in town mode. I think it's a full turn in combat. One step in the outdoors is ten ticks, though. Everywhere but the outdoors, the START_STATE gets called once per tick, but outdoors, it only gets called once every ten ticks, which is the reason for the rather bizarre way of keeping track of time down at the bottom of that code.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00

Pages