/*
Copyright (c) 2023 MCL Software
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "missions.h"
#include "effects.h"
#include "kbdinput.h"
Mission* missions;
Uint8 currentMission = 0;
static int missionInProgress = 0;
static char* missionTextDisplayed[900];
static int placesFromLeft = 0;
static char* text[200];
bool checkForMissionComplete(Uint8 mission)
{
bool flag = 0;
int occurences = 0;
for(int i = 0; i < strlen(missions[mission].requirements); i++)
{
for(int j = 0; j < sizeof player.objectsStolen; j++)
{
if(player.objectsStolen[j] == missions[mission].requirements[i])
{
flag = 1;
}
}
}
return flag;
}
void initMissions()
{
missions = malloc(sizeof(Mission) * 6);
missions[0].desc = "Steal a soap dispenser";
missions[0].requirements = "S";
missions[0].requiredTools = 0;
missions[1].desc = "Steal a soap dispenser and a hand dryer.";
missions[1].requirements = "S&";
missions[1].requiredTools = 0;
missions[2].desc = "Steal two hand dryers";
missions[2].requirements = "&&";
missions[2].requiredTools = 1;
missions[3].desc = "Steal a fire alarm strobe light";
missions[3].requirements = "~";
missions[3].requiredTools = 1;
missions[4].desc = "Steal a fire alarm pull station* and two strobe lights\n\n*Removing the pull station will likely set off the fire alarm system!";
missions[4].requirements = "T~~";
missions[4].requiredTools = 1;
missions[5].desc = "Steal a drinking fountain";
missions[5].requirements = "F";
missions[5].requiredTools = 2;
}
bool drawMissionScreen()
{
if(missionInProgress)
{
if(placesFromLeft != -1)
{
strncpy(missionTextDisplayed, text, placesFromLeft);
placesFromLeft = ISOL_TypingEffect(strlen(text));
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 180);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(renderer, &(SDL_Rect){0, SCREEN_HEIGHT / 4, SCREEN_WIDTH, SCREEN_HEIGHT - SCREEN_HEIGHT / 2});
FC_SetDefaultColor(font, (SDL_Color){255, 255, 255, 255});
FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3, FC_ALIGN_CENTER, "%s", missionTextDisplayed);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
if(placesFromLeft == -1 && keysHeldDown[40])
{
placesFromLeft = 0;
missionInProgress = 0;
memset(missionTextDisplayed, 0, strlen(missionTextDisplayed)); // Clear the string to prevent future issues
player.canMove = true;
return 1;
}
}
else
{
player.canMove = false;
sprintf(text, "MISSION #%i\n%s\nTools required: %s\nPress ENTER to proceed. ", currentMission + 1, missions[currentMission].desc, missions[currentMission].requiredTools == 0 ? "None" : missions[currentMission].requiredTools == 1 ? "Screwdriver" : "Screwdriver and wrench");
missionInProgress = 1;
}
return 0;
}
bool drawMissionComplete()
{
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 180);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(renderer, &(SDL_Rect){0, SCREEN_HEIGHT / 4, SCREEN_WIDTH, SCREEN_HEIGHT - SCREEN_HEIGHT / 2});
FC_SetDefaultColor(font, (SDL_Color){0, 255, 40, 255});
FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, FC_ALIGN_CENTER, "Mission #%i complete!\nPress ENTER to acknowledge.", currentMission + 1);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
if(keysHeldDown[40])
{
memset(player.objectsStolen, 0, strlen(player.objectsStolen));
player.leftCampus = false;
currentMission += 1;
return 1;
}
return 0;
}
/*
missions[0] = {"S", "Steal a soap dispenser", 0};
missions[1] = {"SS", "Steal a soap dispenser and a ", 0};
missions[2] = {"&&", "Steal two hand dryers", 1};
missions[3] = {"~", "Steal a fire alarm strobe light", 1};
missions[4] = {"T~~", "Steal a fire alarm pull station* and two strobe lights\n\n*Removing the pull station will likely set off the fire alarm system!", 1};
missions[5] = {"F", "Steal a drinking fountain", 2};*/