start(); require_once "config.php"; require_once "play_functions.php"; require_once "layout_functions.php"; include_once "cookie_params.inc.php"; browser_check(); $_CURRENT_PAGE_ = "play"; $_CURRENT_SECTION_ = "main"; $DEBUG=0; if (isset($_POST["DEBUG"])) { $DEBUG=$_POST["DEBUG"]; } else { if (isset($_GET["DEBUG"]) ) { $DEBUG=$_GET["DEBUG"]; } else { $DEBUG=0; } } $newgame = 0; if (isset($_GET["newgame"])) { $newgame=$_GET["newgame"]; } if (isset($_POST["input_state"])) { $input_state = $_POST["input_state"]; } else { if (isset($_GET["input_state"])) { $input_state=$_GET["input_state"]; } else { $input_state = 0; } } if (isset($_POST["airway_flag"])) { $airway_flag = $_POST["airway_flag"]; } else { if ( isset ($_GET["airway_flag"])) { $airway_flag=$_GET["airway_flag"]; } else { $airway_flag = ""; } } if (isset($_POST["real_action"])) { $real_action = $_POST["real_action"]; } else { if (isset($_GET["real_action"])) { $real_action=$_GET["real_action"]; } else { $real_action =""; } } if (isset($_GET["finish_game"])) { $finish_game=$_GET["finish_game"]; } else { $finish_game = 0; } $db = new drugsdb; $exit_page_args = array(); if (isset($DEBUG) && $DEBUG) { $DEBUG_BUFFER=""; array_push($exit_page_args,"DEBUG=$DEBUG"); } # check from whence we came # if cookies exist # if referer = play # continue as normal # if referrer = index.php or exit.html # if cookies exist and time < 30 minutes # alert - game already in progress - continue? or start over? # else # start game as usual # if cookies are expired and referrer != index or exit # alert that game has expired - start fresh # # if one of the header redirects gets hit, then when the page returns, # give them the appropriate message otherwise do the above mentioned # cookie and referrer check if ( $newgame ) { $status = $newgame; switch($status) { case ABANDONED: $msg = "The game that was being played has expired.\\n" ."I'll start you out with brand new game\\n"; break; case INACTIVE: $msg = "It appears that there was a game in progress which\\n" . "was abandoned.\\n" . "I'll start you out with a brand new game\\n"; break; case NORMAL: case NEWGAME: default: $msg = ""; } /* here we send a javascript alert to indicate the game restart. - currently that is not a function we want because it seems more confusing to users than helpful */ if ($msg) { $js_alert = "\n"; } } else { if ( cookie_exists($COOKIE_NAMES["playerid"])) { if (strstr($_SERVER["HTTP_REFERER"],"play.html")) { } else { # restart the game array_push($exit_page_args,"newgame=".INACTIVE); redirect("./play.html",$exit_page_args); return; } } else { if (strstr($_SERVER["HTTP_REFERER"],"play.html")) { array_push($exit_page_args,"newgame=".ABANDONED); redirect("./play.html",$exit_page_args); return; } else { array_push($exit_page_args,"newgame=".NEWGAME); redirect("./play.html",$exit_page_args); return; } } } include_once("input_args_verify.inc.php"); # all these cookies are for storing information as the # game progresses. eventually, this info will get stuck # into the database. $playerid_ck = new drug_cookie($COOKIE_NAMES["playerid"]); $actions_ck = new drug_cookie($COOKIE_NAMES["action_effects"]); $real_actions_ck = new drug_cookie($COOKIE_NAMES["actions"]); $symptom_ck = new drug_cookie($COOKIE_NAMES["symptoms"]); $path_ck = new drug_cookie($COOKIE_NAMES["path"]); $airway_ck = new drug_cookie($COOKIE_NAMES["airways"]); $game_in_progress = ( cookie_exists($COOKIE_NAMES["playerid"]) && !$_inargs_verify_result_ ); if ( $_inargs_verify_result_ && (0>=$newgame) ) { $ec = $_inargs_verify_result_ ; print "HEY! $ec"; exit; redirect("error_page.html",array("ec=$ec")); exit; } if ( !$game_in_progress ) { # clear any existing cookies $playerid = $playerid_ck->get(); include "clear_cookies.inc.php"; include "start_game_cookies.inc.php"; } else { # game is in progress # get the player id cookie $playerid=$_COOKIE["ufoplayerid"]; } if (!$playerid) { $ec = NO_PLAYER_ID; redirect("error_page.html",array("ec=$ec")); exit; } # let input_airway be name for input airway flag $input_airway= $airway_flag; ############# # # process input data and get output info # # $input_state_str = $STATUS_TEXT[$input_state]; array_push($exit_page_args,"input_state=$input_state", "airway_flag=$input_airway", "real_action=$real_action"); # check to see if current action is leave $current_action = get_true_action_effect($db,$real_action); $effectid = $current_action["true_action_effect"]; # if we are running in auto mode (finish_game is set if ( $finish_game ) { # do a turn - either 'nothing' or 911 $tmphash = get_leave_action($db); $real_action = $tmphash["id"]; $finish_game = 5; } elseif ( strstr($ACTION_TEXT[$effectid],"leave") ) { # this action is a leave action $finish_game = 1; } $result_hash = get_action_info($db,array("input_state"=>$input_state, "airway_flag"=>$input_airway, "real_action"=>$real_action)); # parse/organize output info $id = $result_hash["id"]; $real_action_str = $result_hash["actionstring"]; $real_action_img = $result_hash["image"]; $true_action_effect = $result_hash["trueactioneffect"]; $true_action_str = $ACTION_TEXT[$true_action_effect]; $action_effect = $result_hash["actioneffect"]; $action_str = $ACTION_TEXT[$action_effect]; $input_airway_str = $AIRWAY_TEXT[$input_airway]; $input_airway_usertext = $AIRWAY_USERTEXT[$input_airway]; $action_was_check = strstr($action_str,"check"); $action_was_check_airway = $action_was_check && strstr($action_str,"airway"); # get the output status and the appropriate image if (!$id) { $ec = NO_VALID_ROWID; array_push($exit_page_args,"ec=$ec", "true_action_effect=$true_action_effect", "action_effect=$action_effect"); redirect("error_page.html",$exit_page_args); exit; } # get text tied to the action if ( $game_in_progress ) { $real_action_verbiage = $result_hash["actionverbiage"]; } else { # game has just started # update path cookie so we know where we started $path_ck->update($id); $real_action_verbiage = get_start_text($db,$input_state); } # get output info for the row id achieved above list($output_str,$output_airway_str) = get_output($db,$id); $output = $STATUS_TEXT[$output_str]; $output_airway = $AIRWAY_TEXT[$output_airway_str]; $output_airway_usertext = $AIRWAY_USERTEXT[$output_airway]; if ( !$output || !$output_str) { $ec = NO_OUTPUT_STATUS; array_push($exit_page_args,"ec=$ec", "true_action_effect=$true_action_effect", "rowid=$id", "action_effect=$action_effect"); redirect("error_page.html",$exit_page_args); exit; } ##################### # # check to see if we have reached an # exit state, and if so, exit appropriately # if ($finish_game) { array_push($exit_page_args,"finish_game=1"); } if ($output_str=="recovered") { array_push($exit_page_args,"xxx=recovered"); redirect("exit.html",$exit_page_args); exit; } if ($output_str=="dead") { array_push($exit_page_args,"xxx=dead"); redirect("exit.html",$exit_page_args); exit; } ######################## # # get and process real symptoms # # cookie is used to look for sticky symptoms like 'blue extremities' if ( cookie_exists($COOKIE_NAMES["symptoms"]) && is_object($symptom_ck) ) { $symptom_history = $symptom_ck->get_urldecoded(); } else { $symptom_history = ""; } $real_symptoms = get_observed_symptoms($db,$id,$symptom_history, ($action_was_check && !$action_was_check_airway)); # check HAS_BLUE_ENTRY then remove it $has_been_blue = isset($real_symptoms["HAS_BEEN_BLUE"]) && $real_symptoms["HAS_BEEN_BLUE"]; unset($real_symptoms["HAS_BEEN_BLUE"]); $real_symptom_ids = get_symptom_ids($real_symptoms); $DEBUG_BUFFER .= "Found real symptoms :
"; $DEBUG_BUFFER .= hash_dump_as_string($real_symptoms,"symptoms:"); $DEBUG_BUFFER .= hash_dump_as_string($real_symptom_ids,"symptom ids:"); # get image $imgurl = get_status_image($db,$input_state,$real_symptom_ids, in_array("blue extremities",$real_symptoms)); if (!$imgurl) { $imgurl = "NONE"; } ##################### # # Game is in progress so update appropriate cookies # # i've taken out the "START" from the cookie, so the # cookies need to be updated with each turn (including the first) # if ( $game_in_progress ) { $qvalues = array(); # build array of cookie names and values to update $update_hash["action_effects"] = $true_action_effect; $update_hash["airways"] = $output_airway; $update_hash["actions"] = $real_action; $update_hash["path"] = $id; $update_hash["symptoms"] = $real_symptom_ids; # update the cookies and update the query values # for the database update foreach ($update_hash as $kk => $vv) { $newcookie = new drug_cookie($COOKIE_NAMES[$kk]); $newval = append_to_cookie($COOKIE_NAMES[$kk],$vv); $newcookie->set($newval); array_push($qvalues, "$kk='$newval'"); } $start_time = get_start_time($db, $playerid); array_push($qvalues,"start_time='$start_time'"); # write new data to player_data in db $query = "update player_data " ."set " . implode(",",$qvalues) ." where id=$playerid"; $db->query($query); $db->errcheck(); unset($update_hash); # } ######################## # # setup 911 cookie # # if 911 is called, set the cookie # if 911 has been called in the past (the cookie is set) # then increment the cookie value which serves as # a counter recording how many turns have transpired. # Do not increment counter if action is a "check" # $ufo911_val = 0; $ufo911_ck = 0; if ( cookie_exists($COOKIE_NAMES["911"]) ) { $ufo911_ck = new drug_cookie($COOKIE_NAMES["911"]); $ufo911_val = 0+$ufo911_ck->get(); # if the action wasn't a check, increment the counter # (if action is check/clear airway, count that as a turn) # if (! $action_was_check && !strstr($action_str,"clear")) { $ufo911_val ++; # } # if it's been more than 2 turns, exit if ($ufo911_val > 3) { array_push($exit_page_args,"xxx=911"); redirect("exit.html",$exit_page_args); exit; } # update the 911 cookie with the new value $ufo911_ck->update($ufo911_val); } elseif ( strstr($action_str,"911")) { $ufo911_ck = new drug_cookie($COOKIE_NAMES["911"]); $ufo911_ck->set(1); } ##################### # # get reflexive symptoms - those which one would see only # if they "checked" something # $refsymptoms = array(); if ( $action_was_check ) { if ( strstr($action_str, "airway") ) { $real_action_img = modify_check_airway_image($real_action_img,$input_airway,$output_airway); array_push($refsymptoms,"
Was: ". $input_airway_usertext, "Now: ". $output_airway_usertext); } if ( strstr($action_str, "resp") || strstr($action_str,"breath") ) { $query = "select * from respiration where rowid=$id"; $db->query($query); $db->errcheck(); $db->next_record(); array_push($refsymptoms,"".$db->get("name").""); } if ( strstr($action_str, "pulse") ) { $query = "select * from pulses where rowid=$id"; $db->query($query); $db->errcheck(); $db->next_record(); array_push($refsymptoms,"".$db->get("name").""); } } # update image based on blueness # if ( in_array("blue extremities",$real_symptoms)) { $real_action_img = preg_replace("!i\/actions\/!","i/actions_blue/",$real_action_img); } # if we haven't exited from the game, and we are in finish_game if ( $finish_game ) { # if we are in finish_game mode - redirect back to this page with # new args $redirectargs = array("input_state=$output", "real_action=$real_action", "finish_game=$finish_game", "airway_flag=$output_airway",rand() ); if ($DEBUG) { array_push($redirectargs,"DEBUG=$DEBUG"); } # - i got it. so the rand() helps fix things here. there is a # caching problem of some kind.. that is, if you call the same # page twice (which happens if the 911 action get's called twice) # then the redirect fails. so leave the random thing in there. redirect("./play.html",$redirectargs); exit; } ##################### # # get all valid action effects # $valid_actions = get_valid_actions($db,$id,$output); ?> <? print $GAME_TITLE . " - [player #".$playerid."]"; ?> "initButtons();")); ?>
">
What you did: Current status: Symptoms: Check status:
<? print $real_action_str; ?> <? print implode(" height=120 width=120 src="">

.

Your check found: ",$refsymptoms); ?>.

Info: 

It was a good idea to call 911. An emergency team is on its way

">
Choose an action:
\n" ." \n"; $ctr = 0; reset($action_buttons); foreach ($action_buttons as $btn_hash) { $act = $btn_hash["id"]; $imgoff = $btn_hash["prefix"] .".gif"; $alttext = $btn_hash["action"]; if (!($ctr % $layout_columns)) { if ($ctr == 0) { print " "; } elseif ($ctr >= $numrows) { print " \n"; } else { print " \n \n"; } } $ctr ++; ?> \n"; ?>
DEBUG MESSAGES
Cookie info: