|
1 /* |
|
2 Copyright (c) 2023 MCL Software |
|
3 |
|
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), |
|
5 to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
6 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: |
|
7 |
|
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|
9 |
|
10 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
11 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, |
|
12 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. |
|
13 */ |
|
14 |
|
15 #include "missions.h" |
|
16 #include "effects.h" |
|
17 #include "kbdinput.h" |
|
18 |
|
19 Mission* missions; |
|
20 Uint8 currentMission = 0; |
|
21 static int missionInProgress = 0; |
|
22 static char* missionTextDisplayed[900]; |
|
23 static int placesFromLeft = 0; |
|
24 static char* text[200]; |
|
25 |
|
26 bool checkForMissionComplete(Uint8 mission) |
|
27 { |
|
28 bool flag = 0; |
|
29 int occurences = 0; |
|
30 for(int i = 0; i < strlen(missions[mission].requirements); i++) |
|
31 { |
|
32 for(int j = 0; j < sizeof player.objectsStolen; j++) |
|
33 { |
|
34 if(player.objectsStolen[j] == missions[mission].requirements[i]) |
|
35 { |
|
36 flag = 1; |
|
37 } |
|
38 } |
|
39 } |
|
40 |
|
41 return flag; |
|
42 } |
|
43 |
|
44 void initMissions() |
|
45 { |
|
46 missions = malloc(sizeof(Mission) * 6); |
|
47 missions[0].desc = "Steal a soap dispenser"; |
|
48 missions[0].requirements = "S"; |
|
49 missions[0].requiredTools = 0; |
|
50 |
|
51 missions[1].desc = "Steal a soap dispenser and a hand dryer."; |
|
52 missions[1].requirements = "S&"; |
|
53 missions[1].requiredTools = 0; |
|
54 |
|
55 missions[2].desc = "Steal two hand dryers"; |
|
56 missions[2].requirements = "&&"; |
|
57 missions[2].requiredTools = 1; |
|
58 |
|
59 missions[3].desc = "Steal a fire alarm strobe light"; |
|
60 missions[3].requirements = "~"; |
|
61 missions[3].requiredTools = 1; |
|
62 |
|
63 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!"; |
|
64 missions[4].requirements = "T~~"; |
|
65 missions[4].requiredTools = 1; |
|
66 |
|
67 missions[5].desc = "Steal a drinking fountain"; |
|
68 missions[5].requirements = "F"; |
|
69 missions[5].requiredTools = 2; |
|
70 } |
|
71 |
|
72 bool drawMissionScreen() |
|
73 { |
|
74 if(missionInProgress) |
|
75 { |
|
76 if(placesFromLeft != -1) |
|
77 { |
|
78 strncpy(missionTextDisplayed, text, placesFromLeft); |
|
79 placesFromLeft = ISOL_TypingEffect(strlen(text)); |
|
80 } |
|
81 |
|
82 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 180); |
|
83 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); |
|
84 SDL_RenderFillRect(renderer, &(SDL_Rect){0, SCREEN_HEIGHT / 4, SCREEN_WIDTH, SCREEN_HEIGHT - SCREEN_HEIGHT / 2}); |
|
85 FC_SetDefaultColor(font, (SDL_Color){255, 255, 255, 255}); |
|
86 FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3, FC_ALIGN_CENTER, "%s", missionTextDisplayed); |
|
87 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); |
|
88 |
|
89 if(placesFromLeft == -1 && keysHeldDown[40]) |
|
90 { |
|
91 placesFromLeft = 0; |
|
92 missionInProgress = 0; |
|
93 memset(missionTextDisplayed, 0, strlen(missionTextDisplayed)); // Clear the string to prevent future issues |
|
94 player.canMove = true; |
|
95 return 1; |
|
96 } |
|
97 } |
|
98 |
|
99 else |
|
100 { |
|
101 player.canMove = false; |
|
102 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"); |
|
103 missionInProgress = 1; |
|
104 } |
|
105 |
|
106 return 0; |
|
107 } |
|
108 |
|
109 bool drawMissionComplete() |
|
110 { |
|
111 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 180); |
|
112 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); |
|
113 SDL_RenderFillRect(renderer, &(SDL_Rect){0, SCREEN_HEIGHT / 4, SCREEN_WIDTH, SCREEN_HEIGHT - SCREEN_HEIGHT / 2}); |
|
114 FC_SetDefaultColor(font, (SDL_Color){0, 255, 40, 255}); |
|
115 FC_DrawAlign(font, renderer, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, FC_ALIGN_CENTER, "Mission #%i complete!\nPress ENTER to acknowledge.", currentMission + 1); |
|
116 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); |
|
117 |
|
118 if(keysHeldDown[40]) |
|
119 { |
|
120 memset(player.objectsStolen, 0, strlen(player.objectsStolen)); |
|
121 player.leftCampus = false; |
|
122 currentMission += 1; |
|
123 return 1; |
|
124 } |
|
125 |
|
126 return 0; |
|
127 } |
|
128 |
|
129 /* |
|
130 missions[0] = {"S", "Steal a soap dispenser", 0}; |
|
131 missions[1] = {"SS", "Steal a soap dispenser and a ", 0}; |
|
132 missions[2] = {"&&", "Steal two hand dryers", 1}; |
|
133 missions[3] = {"~", "Steal a fire alarm strobe light", 1}; |
|
134 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}; |
|
135 missions[5] = {"F", "Steal a drinking fountain", 2};*/ |
|
136 |
|
137 |
|
138 |