summaryrefslogtreecommitdiffstats
path: root/includes/datas.php
diff options
context:
space:
mode:
authorBlueRaja <BlueRaja.admin@gmail.com>2012-10-01 01:25:48 -0500
committerBlueRaja <BlueRaja.admin@gmail.com>2012-10-01 01:25:48 -0500
commit9da319e2a2bed9ea3fab92b4e6b799bb9eb16632 (patch)
treebe4d2afabc42cfe7bb3c3db461971be90c8649a9 /includes/datas.php
parent499a426f500af74df562612675ebdb44bc465215 (diff)
downloadpathery-9da319e2a2bed9ea3fab92b4e6b799bb9eb16632.tar.xz
Fixed a few bugs with challenges, and added some debugging code (which still needs to be removed)
Diffstat (limited to 'includes/datas.php')
-rw-r--r--includes/datas.php57
1 files changed, 52 insertions, 5 deletions
diff --git a/includes/datas.php b/includes/datas.php
index 676e68b..d1e2618 100644
--- a/includes/datas.php
+++ b/includes/datas.php
@@ -4,6 +4,10 @@
include_once('db.inc.php');
+//FirePHP stuff - TODO: Delete
+require_once('includes/FirePHPCore/FirePHP.class.php');
+//FirePHP stuff - TODO: Delete
+
//Select Stats/Scores.
function topScores($mapid, $top = 5, $bottom = 0) {
$sql = "
@@ -298,8 +302,10 @@ function applyCareerMazesAchievements($userID) {
* @param type $moves The total number of moves in the solution, for all paths
* @param type $paths An array of path-objects, each as returned by routePath().
*/
-function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
+function getCompletedChallenges($userID, $mapID, $solution, $moves, $paths) {
//mapID 5 is the tutorial, and is treated specially
+ $firephp = FirePHP::getInstance(true);
+ $firephp->log("In challenges");
if($mapID == 5) {
if ($moves == 75) {
onCompletedTutorial($userID);
@@ -307,15 +313,31 @@ function checkForCompletedChallenges($userID, $mapID, $solution, $moves, $paths)
return;
}
+ $firephp->log($mapID, "mapID");
+ $firephp->log($userID, "userID");
+
$challengeResultset = loadChallengesForMap($mapID, $userID);
+ $challengesCompleted = array();
while($challenge = mysql_fetch_array($challengeResultset))
{
+ $firephp->log("Checking a challenge");
+ $firephp->log("Checking challenge number" . $challenge['challengeID']);
+ $firephp->log($challenge["dateSolved"], "dateCompleted");
//Skip checking challenges which have already been completed
- if($challenge["dateCompleted"] !== NULL)
- continue;
+ if($challenge["dateSolved"] !== NULL)
+ {
+ $firephp->log('Challenge was already completed');
+ $challengesCompleted[] = $challenge["challengeID"];
+ }
else if(hasChallengeBeenCompleted($challenge, $solution, $moves, $paths))
+ {
+ $firephp->log('Challenge was completed!');
setChallengeCompleted($challenge, $solution, $userID, $moves);
+ $challengesCompleted[] = $challenge["challengeID"];
+ }
}
+
+ return $challengesCompleted;
}
/**
@@ -346,6 +368,7 @@ function onCompletedTutorial($userID) {
* Checks if the given solution meets the requirements for the given challenge
*/
function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
+ $firephp = FirePHP::getInstance(true);
//Check the maze-length
if($challenge['goal'] != 0) {
//Er, "greater than" should really be called "greater than or equal to" :\
@@ -353,6 +376,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
|| ($challenge['inequality'] == "less than" && $moves >= $challenge['goal'])
|| ($challenge['inequality'] == "equal" && $moves != $challenge['goal']))
{
+ $firephp->log("Failed at distance");
return false;
}
}
@@ -364,6 +388,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
$temp = count_chars($solution, 1); //$temp needed due to extreme PHP-stupidity
$numWalls = $temp[ord(",")];
if($numWalls > $challenge['restrictWallCount']) {
+ $firephp->log("Failed at wall-count");
return false;
}
}
@@ -374,8 +399,11 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
$invalidWalls = explode(".", $challenge['restrictWallPlacement']);
foreach($invalidWalls as $invalidWall)
{
- if(strpos($solution,$invalidWall) !== false)
+ $stringToSearchFor = "." . swapXandYCoordinates($invalidWall) . ".";
+ if(strpos($solution,$stringToSearchFor) !== false)
{
+ $firephp->log("Failed at wall-placement: " . $invalidWall);
+ $firephp->log("Solution: " . $solution);
return false;
}
}
@@ -385,12 +413,13 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
if($challenge['restrictTeleportCount'] !== NULL || $challenge['restrictTeleportsUsed'] !== NULL)
{
//Check teleport count
- $usedTeleports = explode(".", getUsedTeleports($paths));
+ $usedTeleports = explode(".", getUsedTeleports($paths)); //TODO: Implement
if($challenge['restrictTeleportCount'] !== NULL)
{
if(count($usedTeleports) !== $challenge['restrictTeleportCount'] &&
($challenge['restrictTeleportCount'] != 0 || $usedTeleports[0] != ""))
{
+ $firephp->log("Failed at teleport count");
return false;
}
}
@@ -405,6 +434,7 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
//Check each path to see if it walks over that teleport
if(strpos($path['path'], $usedTeleport) !== false)
{
+ $firephp->log("Failed at teleports used");
return false;
}
}
@@ -423,7 +453,10 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
}
if(!$usesCorrectStartPoint)
+ {
+ $firephp->log("Failed at start-point");
return false;
+ }
}
//Check end points
@@ -437,14 +470,27 @@ function hasChallengeBeenCompleted($challenge, $solution, $moves, $paths) {
}
if(!$usesCorrectEndPoint)
+ {
+ $firephp->log("Failed at endpoint");
return false;
+ }
}
//All of the restrictions were met, meaning the challenge was completed!
+ $firephp->log("Succeeded!");
return true;
}
/**
+ * Hack, due to positions being stored as x,y in some places and y,x in others
+ */
+function swapXandYCoordinates($position)
+{
+ $coords = explode(",", $position);
+ return $coords[1] . "," . $coords[0];
+}
+
+/**
* Sets the given challenge as completed by the user in the database
*/
function setChallengeCompleted($challenge, $solution, $userID, $moves) {
@@ -884,6 +930,7 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized)
FROM challenges
LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID'
WHERE challenges.mapID = '$mapID' AND challenges.enabled = 1
+ ORDER BY challenges.ordering
";
$result = mysql_query($sql);