| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "briefing_screens.h" |
| 27 |
|
| 28 |
#include <cdogs/draw/draw.h> |
| 29 |
#include <cdogs/draw/draw_actor.h> |
| 30 |
#include <cdogs/events.h> |
| 31 |
#include <cdogs/files.h> |
| 32 |
#include <cdogs/font.h> |
| 33 |
#include <cdogs/grafx_bg.h> |
| 34 |
#include <cdogs/log.h> |
| 35 |
#include <cdogs/music.h> |
| 36 |
#include <cdogs/objective.h> |
| 37 |
|
| 38 |
#include "animated_counter.h" |
| 39 |
#include "autosave.h" |
| 40 |
#include "loading_screens.h" |
| 41 |
#include "menu_utils.h" |
| 42 |
#include "password.h" |
| 43 |
#include "prep.h" |
| 44 |
#include "prep_equip.h" |
| 45 |
#include "screens_end.h" |
| 46 |
|
| 47 |
static void DrawObjectiveInfo(const Objective *o, const struct vec2i pos); |
| 48 |
|
| 49 |
typedef struct |
| 50 |
{ |
| 51 |
EventWaitResult waitResult; |
| 52 |
CampaignSetting *c; |
| 53 |
GameMode gameMode; |
| 54 |
const CampaignEntry *entry; |
| 55 |
} ScreenCampaignIntroData; |
| 56 |
static void CampaignIntroTerminate(GameLoopData *data); |
| 57 |
static void CampaignIntroOnEnter(GameLoopData *data); |
| 58 |
static void CampaignIntroOnExit(GameLoopData *data); |
| 59 |
static void CampaignIntroInput(GameLoopData *data); |
| 60 |
static GameLoopResult CampaignIntroUpdate(GameLoopData *data, LoopRunner *l); |
| 61 |
static void CampaignIntroDraw(GameLoopData *data); |
| 62 |
GameLoopData *ScreenCampaignIntro( |
| 63 |
CampaignSetting *c, const GameMode gameMode, const CampaignEntry *entry) |
| 64 |
{ |
| 65 |
ScreenCampaignIntroData *data; |
| 66 |
CMALLOC(data, sizeof *data); |
| 67 |
data->c = c; |
| 68 |
data->gameMode = gameMode; |
| 69 |
data->entry = entry; |
| 70 |
return GameLoopDataNew( |
| 71 |
data, CampaignIntroTerminate, CampaignIntroOnEnter, |
| 72 |
CampaignIntroOnExit, CampaignIntroInput, CampaignIntroUpdate, |
| 73 |
CampaignIntroDraw); |
| 74 |
} |
| 75 |
static void CampaignIntroTerminate(GameLoopData *data) |
| 76 |
{ |
| 77 |
ScreenCampaignIntroData *mData = data->Data; |
| 78 |
CFREE(mData); |
| 79 |
} |
| 80 |
static void CampaignIntroOnEnter(GameLoopData *data) |
| 81 |
{ |
| 82 |
ScreenCampaignIntroData *sData = data->Data; |
| 83 |
gCampaign.Entry.Mode = sData->gameMode; |
| 84 |
if (!gCampaign.IsLoaded && !CampaignLoad(&gCampaign, sData->entry)) |
| 85 |
{ |
| 86 |
|
| 87 |
LOG(LM_MAIN, LL_ERROR, "cannot load campaign %s", sData->entry->Info); |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
MusicPlayFromChunk( |
| 92 |
&gSoundDevice.music, MUSIC_MENU, |
| 93 |
&sData->c->CustomSongs[MUSIC_MENU]); |
| 94 |
} |
| 95 |
} |
| 96 |
static void CampaignIntroOnExit(GameLoopData *data) |
| 97 |
{ |
| 98 |
const ScreenCampaignIntroData *sData = data->Data; |
| 99 |
if (sData->waitResult == EVENT_WAIT_CANCEL) |
| 100 |
{ |
| 101 |
CampaignUnload(&gCampaign); |
| 102 |
} |
| 103 |
} |
| 104 |
static void CampaignIntroInput(GameLoopData *data) |
| 105 |
{ |
| 106 |
ScreenCampaignIntroData *sData = data->Data; |
| 107 |
sData->waitResult = EventWaitForAnyKeyOrButton(); |
| 108 |
if (sData->waitResult == EVENT_WAIT_OK) |
| 109 |
{ |
| 110 |
MenuPlaySound(MENU_SOUND_ENTER); |
| 111 |
} |
| 112 |
} |
| 113 |
static GameLoopResult CampaignIntroUpdate(GameLoopData *data, LoopRunner *l) |
| 114 |
{ |
| 115 |
const ScreenCampaignIntroData *sData = data->Data; |
| 116 |
|
| 117 |
if (!gCampaign.IsLoaded || sData->waitResult == EVENT_WAIT_CANCEL) |
| 118 |
{ |
| 119 |
LoopRunnerPop(l); |
| 120 |
} |
| 121 |
else if ( |
| 122 |
!IsIntroNeeded(gCampaign.Entry.Mode) || |
| 123 |
sData->waitResult == EVENT_WAIT_OK) |
| 124 |
{ |
| 125 |
|
| 126 |
LoopRunnerPush( |
| 127 |
l, |
| 128 |
ScreenLoading( |
| 129 |
"Loading campaign...", true, |
| 130 |
NumPlayersSelection(&gGraphicsDevice, &gEventHandlers), true)); |
| 131 |
} |
| 132 |
return UPDATE_RESULT_OK; |
| 133 |
} |
| 134 |
static void CampaignIntroDraw(GameLoopData *data) |
| 135 |
{ |
| 136 |
const ScreenCampaignIntroData *sData = data->Data; |
| 137 |
|
| 138 |
BlitClearBuf(&gGraphicsDevice); |
| 139 |
const int w = gGraphicsDevice.cachedConfig.Res.x; |
| 140 |
const int h = gGraphicsDevice.cachedConfig.Res.y; |
| 141 |
const int y = h / 4; |
| 142 |
|
| 143 |
|
| 144 |
char *buf; |
| 145 |
CMALLOC(buf, strlen(sData->c->Title) + strlen(sData->c->Author) + 16); |
| 146 |
if (strlen(sData->c->Author)) |
| 147 |
{ |
| 148 |
sprintf(buf, "%s by %s", sData->c->Title, sData->c->Author); |
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
strcpy(buf, sData->c->Title); |
| 153 |
} |
| 154 |
FontOpts opts = FontOptsNew(); |
| 155 |
opts.HAlign = ALIGN_CENTER; |
| 156 |
opts.Area = gGraphicsDevice.cachedConfig.Res; |
| 157 |
opts.Pad.y = y - 25; |
| 158 |
FontStrOpt(buf, svec2i_zero(), opts); |
| 159 |
CFREE(buf); |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
if (strlen(sData->c->Description) > 0) |
| 164 |
{ |
| 165 |
CMALLOC(buf, strlen(sData->c->Description) * 2); |
| 166 |
|
| 167 |
FontSplitLines(sData->c->Description, buf, w * 5 / 6); |
| 168 |
FontStr(buf, svec2i(w / 12, y)); |
| 169 |
CFREE(buf); |
| 170 |
} |
| 171 |
|
| 172 |
BlitUpdateFromBuf(&gGraphicsDevice, gGraphicsDevice.screen); |
| 173 |
} |
| 174 |
|
| 175 |
typedef struct |
| 176 |
{ |
| 177 |
char *Title; |
| 178 |
FontOpts TitleOpts; |
| 179 |
char Password[32]; |
| 180 |
FontOpts PasswordOpts; |
| 181 |
int TypewriterCount; |
| 182 |
char *Description; |
| 183 |
char *TypewriterBuf; |
| 184 |
struct vec2i DescriptionPos; |
| 185 |
struct vec2i ObjectiveDescPos; |
| 186 |
struct vec2i ObjectiveInfoPos; |
| 187 |
int ObjectiveHeight; |
| 188 |
CampaignSetting *C; |
| 189 |
const struct MissionOptions *MissionOptions; |
| 190 |
EventWaitResult waitResult; |
| 191 |
} MissionBriefingData; |
| 192 |
static void MissionBriefingTerminate(GameLoopData *data); |
| 193 |
static void MissionBriefingOnEnter(GameLoopData *data); |
| 194 |
static void MissionBriefingOnExit(GameLoopData *data); |
| 195 |
static void MissionBriefingInput(GameLoopData *data); |
| 196 |
static GameLoopResult MissionBriefingUpdate(GameLoopData *data, LoopRunner *l); |
| 197 |
static void MissionBriefingDraw(GameLoopData *data); |
| 198 |
GameLoopData *ScreenMissionBriefing( |
| 199 |
CampaignSetting *c, const struct MissionOptions *m) |
| 200 |
{ |
| 201 |
const int w = gGraphicsDevice.cachedConfig.Res.x; |
| 202 |
const int h = gGraphicsDevice.cachedConfig.Res.y; |
| 203 |
const int y = h / 4; |
| 204 |
MissionBriefingData *mData; |
| 205 |
CCALLOC(mData, sizeof *mData); |
| 206 |
mData->waitResult = EVENT_WAIT_CONTINUE; |
| 207 |
|
| 208 |
|
| 209 |
if (m->missionData->Title) |
| 210 |
{ |
| 211 |
CMALLOC(mData->Title, strlen(m->missionData->Title) + 32); |
| 212 |
sprintf( |
| 213 |
mData->Title, "Mission %d: %s", m->index + 1, |
| 214 |
m->missionData->Title); |
| 215 |
mData->TitleOpts = FontOptsNew(); |
| 216 |
mData->TitleOpts.HAlign = ALIGN_CENTER; |
| 217 |
mData->TitleOpts.Area = gGraphicsDevice.cachedConfig.Res; |
| 218 |
mData->TitleOpts.Pad.y = y - 25; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
if (m->missionData->Description) |
| 223 |
{ |
| 224 |
|
| 225 |
|
| 226 |
CMALLOC( |
| 227 |
mData->Description, strlen(m->missionData->Description) * 2 + 1); |
| 228 |
CCALLOC( |
| 229 |
mData->TypewriterBuf, strlen(m->missionData->Description) * 2 + 1); |
| 230 |
|
| 231 |
FontSplitLines( |
| 232 |
m->missionData->Description, mData->Description, w * 5 / 6); |
| 233 |
mData->DescriptionPos = svec2i(w / 12, y); |
| 234 |
|
| 235 |
|
| 236 |
mData->ObjectiveDescPos = |
| 237 |
svec2i(w / 6, y + FontStrH(mData->Description) + h / 10); |
| 238 |
mData->ObjectiveInfoPos = |
| 239 |
svec2i(w - (w / 6), mData->ObjectiveDescPos.y + FontH()); |
| 240 |
mData->ObjectiveHeight = h / 12; |
| 241 |
} |
| 242 |
mData->C = c; |
| 243 |
mData->MissionOptions = m; |
| 244 |
|
| 245 |
return GameLoopDataNew( |
| 246 |
mData, MissionBriefingTerminate, MissionBriefingOnEnter, |
| 247 |
MissionBriefingOnExit, MissionBriefingInput, MissionBriefingUpdate, |
| 248 |
MissionBriefingDraw); |
| 249 |
} |
| 250 |
static void MissionBriefingTerminate(GameLoopData *data) |
| 251 |
{ |
| 252 |
MissionBriefingData *mData = data->Data; |
| 253 |
|
| 254 |
CFREE(mData->Title); |
| 255 |
CFREE(mData->Description); |
| 256 |
CFREE(mData->TypewriterBuf); |
| 257 |
CFREE(mData); |
| 258 |
} |
| 259 |
static void MissionBriefingOnEnter(GameLoopData *data) |
| 260 |
{ |
| 261 |
MissionBriefingData *mData = data->Data; |
| 262 |
if (IsMissionBriefingNeeded(gCampaign.Entry.Mode, mData->Description)) |
| 263 |
{ |
| 264 |
MusicPlayFromChunk( |
| 265 |
&gSoundDevice.music, MUSIC_BRIEFING, |
| 266 |
&mData->C->CustomSongs[MUSIC_BRIEFING]); |
| 267 |
} |
| 268 |
} |
| 269 |
static void MissionBriefingOnExit(GameLoopData *data) |
| 270 |
{ |
| 271 |
const MissionBriefingData *mData = data->Data; |
| 272 |
|
| 273 |
if (mData->waitResult != EVENT_WAIT_OK) |
| 274 |
{ |
| 275 |
CampaignUnload(&gCampaign); |
| 276 |
} |
| 277 |
} |
| 278 |
static void MissionBriefingInput(GameLoopData *data) |
| 279 |
{ |
| 280 |
MissionBriefingData *mData = data->Data; |
| 281 |
|
| 282 |
int cmds[MAX_LOCAL_PLAYERS]; |
| 283 |
memset(cmds, 0, sizeof cmds); |
| 284 |
GetPlayerCmds(&gEventHandlers, &cmds); |
| 285 |
if (mData->Description) |
| 286 |
{ |
| 287 |
|
| 288 |
for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) |
| 289 |
{ |
| 290 |
if (AnyButton(cmds[i])) |
| 291 |
{ |
| 292 |
|
| 293 |
if (mData->TypewriterCount <= (int)strlen(mData->Description)) |
| 294 |
{ |
| 295 |
strcpy(mData->TypewriterBuf, mData->Description); |
| 296 |
mData->TypewriterCount = (int)strlen(mData->Description); |
| 297 |
return; |
| 298 |
} |
| 299 |
|
| 300 |
mData->waitResult = EVENT_WAIT_OK; |
| 301 |
MenuPlaySound(MENU_SOUND_ENTER); |
| 302 |
} |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
if (EventIsEscape( |
| 307 |
&gEventHandlers, cmds, GetMenuCmd(&gEventHandlers, false))) |
| 308 |
{ |
| 309 |
mData->waitResult = EVENT_WAIT_CANCEL; |
| 310 |
} |
| 311 |
} |
| 312 |
static GameLoopResult MissionBriefingUpdate(GameLoopData *data, LoopRunner *l) |
| 313 |
{ |
| 314 |
MissionBriefingData *mData = data->Data; |
| 315 |
|
| 316 |
if (!IsMissionBriefingNeeded(gCampaign.Entry.Mode, mData->Description)) |
| 317 |
{ |
| 318 |
mData->waitResult = EVENT_WAIT_OK; |
| 319 |
goto bail; |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
if (mData->waitResult != EVENT_WAIT_CONTINUE) |
| 324 |
{ |
| 325 |
goto bail; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
if (mData->TypewriterCount <= (int)strlen(mData->Description)) |
| 330 |
{ |
| 331 |
mData->TypewriterBuf[mData->TypewriterCount] = |
| 332 |
mData->Description[mData->TypewriterCount]; |
| 333 |
mData->TypewriterCount++; |
| 334 |
return UPDATE_RESULT_DRAW; |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
if (gEventHandlers.DemoQuitTimer > 0) |
| 339 |
{ |
| 340 |
mData->waitResult = EVENT_WAIT_OK; |
| 341 |
goto bail; |
| 342 |
} |
| 343 |
|
| 344 |
return UPDATE_RESULT_OK; |
| 345 |
|
| 346 |
bail: |
| 347 |
if (mData->waitResult == EVENT_WAIT_OK) |
| 348 |
{ |
| 349 |
LoopRunnerChange(l, PlayerEquip()); |
| 350 |
} |
| 351 |
else |
| 352 |
{ |
| 353 |
LoopRunnerPop(l); |
| 354 |
} |
| 355 |
return UPDATE_RESULT_OK; |
| 356 |
} |
| 357 |
static void MissionBriefingDraw(GameLoopData *data) |
| 358 |
{ |
| 359 |
const MissionBriefingData *mData = data->Data; |
| 360 |
|
| 361 |
BlitClearBuf(&gGraphicsDevice); |
| 362 |
|
| 363 |
|
| 364 |
FontStrOpt(mData->Title, svec2i_zero(), mData->TitleOpts); |
| 365 |
|
| 366 |
FontStrOpt(mData->Password, svec2i_zero(), mData->PasswordOpts); |
| 367 |
|
| 368 |
FontStr(mData->TypewriterBuf, mData->DescriptionPos); |
| 369 |
|
| 370 |
CA_FOREACH( |
| 371 |
const Objective, o, mData->MissionOptions->missionData->Objectives) |
| 372 |
|
| 373 |
if (o->Required == 0) |
| 374 |
{ |
| 375 |
continue; |
| 376 |
} |
| 377 |
struct vec2i offset = svec2i(0, _ca_index * mData->ObjectiveHeight); |
| 378 |
FontStr(o->Description, svec2i_add(mData->ObjectiveDescPos, offset)); |
| 379 |
|
| 380 |
|
| 381 |
offset.x = -16 * (_ca_index & 1); |
| 382 |
DrawObjectiveInfo(o, svec2i_add(mData->ObjectiveInfoPos, offset)); |
| 383 |
CA_FOREACH_END() |
| 384 |
|
| 385 |
BlitUpdateFromBuf(&gGraphicsDevice, gGraphicsDevice.screen); |
| 386 |
} |
| 387 |
|
| 388 |
#define PERFECT_BONUS 500 |
| 389 |
|
| 390 |
typedef struct |
| 391 |
{ |
| 392 |
const PlayerData *Pd; |
| 393 |
AnimatedCounter Score; |
| 394 |
AnimatedCounter Total; |
| 395 |
AnimatedCounter Time; |
| 396 |
AnimatedCounter TimeTotal; |
| 397 |
AnimatedCounter HealthResurrection; |
| 398 |
AnimatedCounter ButcherNinjaFriendly; |
| 399 |
} PlayerSummaryDrawData; |
| 400 |
typedef struct |
| 401 |
{ |
| 402 |
MenuSystem ms; |
| 403 |
const Campaign *c; |
| 404 |
struct MissionOptions *m; |
| 405 |
bool completed; |
| 406 |
AnimatedCounter AccessBonus; |
| 407 |
AnimatedCounter TimeBonus; |
| 408 |
PlayerSummaryDrawData pDatas[MAX_LOCAL_PLAYERS]; |
| 409 |
} MissionSummaryData; |
| 410 |
static void MissionSummaryTerminate(GameLoopData *data); |
| 411 |
static void MissionSummaryOnEnter(GameLoopData *data); |
| 412 |
static GameLoopResult MissionSummaryUpdate(GameLoopData *data, LoopRunner *l); |
| 413 |
static void MissionSummaryDraw(GameLoopData *data); |
| 414 |
static void MissionSummaryMenuDraw( |
| 415 |
const menu_t *menu, GraphicsDevice *g, const struct vec2i p, |
| 416 |
const struct vec2i size, const void *data); |
| 417 |
GameLoopData *ScreenMissionSummary( |
| 418 |
const Campaign *c, struct MissionOptions *m, const bool completed) |
| 419 |
{ |
| 420 |
MissionSummaryData *mData; |
| 421 |
CCALLOC(mData, sizeof *mData); |
| 422 |
|
| 423 |
const int h = FontH() * 10; |
| 424 |
MenuSystemInit( |
| 425 |
&mData->ms, &gEventHandlers, &gGraphicsDevice, |
| 426 |
svec2i(0, gGraphicsDevice.cachedConfig.Res.y - h), |
| 427 |
svec2i(gGraphicsDevice.cachedConfig.Res.x, h)); |
| 428 |
mData->ms.current = mData->ms.root = |
| 429 |
MenuCreateNormal("", "", MENU_TYPE_NORMAL, 0); |
| 430 |
|
| 431 |
if (completed) |
| 432 |
{ |
| 433 |
MenuAddSubmenu(mData->ms.root, MenuCreateReturn("Continue", 0)); |
| 434 |
} |
| 435 |
else |
| 436 |
{ |
| 437 |
MenuAddSubmenu(mData->ms.root, MenuCreateReturn("Replay mission", 0)); |
| 438 |
MenuAddSubmenu(mData->ms.root, MenuCreateReturn("Back to menu", 1)); |
| 439 |
} |
| 440 |
mData->ms.allowAborts = true; |
| 441 |
MenuAddExitType(&mData->ms, MENU_TYPE_RETURN); |
| 442 |
MenuSystemAddCustomDisplay(&mData->ms, MissionSummaryMenuDraw, mData); |
| 443 |
|
| 444 |
mData->c = c; |
| 445 |
mData->m = m; |
| 446 |
mData->completed = completed; |
| 447 |
|
| 448 |
return GameLoopDataNew( |
| 449 |
mData, MissionSummaryTerminate, MissionSummaryOnEnter, NULL, NULL, |
| 450 |
MissionSummaryUpdate, MissionSummaryDraw); |
| 451 |
} |
| 452 |
static void MissionSummaryTerminate(GameLoopData *data) |
| 453 |
{ |
| 454 |
MissionSummaryData *mData = data->Data; |
| 455 |
|
| 456 |
MenuSystemTerminate(&mData->ms); |
| 457 |
AnimatedCounterTerminate(&mData->AccessBonus); |
| 458 |
AnimatedCounterTerminate(&mData->TimeBonus); |
| 459 |
for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) |
| 460 |
{ |
| 461 |
AnimatedCounterTerminate(&mData->pDatas[i].Score); |
| 462 |
AnimatedCounterTerminate(&mData->pDatas[i].Total); |
| 463 |
AnimatedCounterTerminate(&mData->pDatas[i].HealthResurrection); |
| 464 |
AnimatedCounterTerminate(&mData->pDatas[i].ButcherNinjaFriendly); |
| 465 |
} |
| 466 |
CFREE(mData); |
| 467 |
} |
| 468 |
static bool AreAnySurvived(void); |
| 469 |
static int GetAccessBonus(const struct MissionOptions *m); |
| 470 |
static int GetTimeBonus(const struct MissionOptions *m, int *secondsOut); |
| 471 |
static void ApplyBonuses(PlayerData *p, const int bonus); |
| 472 |
static int GetHealthBonus(const PlayerData *p); |
| 473 |
static int GetResurrectionFee(const PlayerData *p); |
| 474 |
static int GetButcherPenalty(const PlayerData *p); |
| 475 |
static int GetNinjaBonus(const PlayerData *p); |
| 476 |
static int GetFriendlyBonus(const PlayerData *p); |
| 477 |
static void MissionSummaryOnEnter(GameLoopData *data) |
| 478 |
{ |
| 479 |
MissionSummaryData *mData = data->Data; |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
const int accessBonus = GetAccessBonus(mData->m); |
| 484 |
if (AreAnySurvived()) |
| 485 |
{ |
| 486 |
int bonus = 0; |
| 487 |
|
| 488 |
CA_FOREACH(const Objective, o, mData->m->missionData->Objectives) |
| 489 |
if (ObjectiveIsPerfect(o)) |
| 490 |
{ |
| 491 |
bonus += PERFECT_BONUS; |
| 492 |
} |
| 493 |
CA_FOREACH_END() |
| 494 |
bonus += accessBonus; |
| 495 |
bonus += GetTimeBonus(mData->m, NULL); |
| 496 |
|
| 497 |
CA_FOREACH(PlayerData, p, gPlayerDatas) |
| 498 |
ApplyBonuses(p, bonus); |
| 499 |
p->Totals.TimeTicks += mData->m->time; |
| 500 |
CA_FOREACH_END() |
| 501 |
} |
| 502 |
|
| 503 |
if (mData->completed && CanLevelSelect(mData->c->Entry.Mode)) |
| 504 |
{ |
| 505 |
AutosaveAdd( |
| 506 |
&gAutosave, &mData->c->Entry, mData->m->index, |
| 507 |
mData->m->NextMission, &gPlayerDatas); |
| 508 |
AutosaveSave(&gAutosave, GetConfigFilePath(AUTOSAVE_FILE)); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
if (mData->m->missionData->SkipDebrief) |
| 513 |
{ |
| 514 |
return; |
| 515 |
} |
| 516 |
|
| 517 |
if (mData->completed) |
| 518 |
{ |
| 519 |
MusicPlayFromChunk( |
| 520 |
&gSoundDevice.music, MUSIC_END, |
| 521 |
&gCampaign.Setting.CustomSongs[MUSIC_END]); |
| 522 |
} |
| 523 |
else |
| 524 |
{ |
| 525 |
MusicPlayFromChunk( |
| 526 |
&gSoundDevice.music, MUSIC_LOSE, |
| 527 |
&gCampaign.Setting.CustomSongs[MUSIC_LOSE]); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
if (AreAnySurvived()) |
| 532 |
{ |
| 533 |
if (accessBonus > 0) |
| 534 |
{ |
| 535 |
mData->AccessBonus = |
| 536 |
AnimatedCounterNew("Access bonus: ", accessBonus); |
| 537 |
} |
| 538 |
int seconds; |
| 539 |
const int timeBonus = GetTimeBonus(mData->m, &seconds); |
| 540 |
char buf[256]; |
| 541 |
sprintf(buf, "Time bonus: %d secs x 25 = ", seconds); |
| 542 |
mData->TimeBonus = AnimatedCounterNew(buf, timeBonus); |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
int idx = 0; |
| 547 |
CA_FOREACH(PlayerData, pd, gPlayerDatas) |
| 548 |
if (!pd->IsLocal) |
| 549 |
{ |
| 550 |
continue; |
| 551 |
} |
| 552 |
mData->pDatas[idx].Pd = pd; |
| 553 |
mData->pDatas[idx].Score = AnimatedCounterNew("Score: ", pd->Stats.Score); |
| 554 |
mData->pDatas[idx].Total = AnimatedCounterNew("Total: ", pd->Totals.Score); |
| 555 |
mData->pDatas[idx].Time = |
| 556 |
AnimatedCounterNew("Time: ", mData->m->time / FPS_FRAMELIMIT); |
| 557 |
mData->pDatas[idx].TimeTotal = AnimatedCounterNew( |
| 558 |
"Total Time: ", pd->Totals.TimeTicks / FPS_FRAMELIMIT); |
| 559 |
if (pd->survived) |
| 560 |
{ |
| 561 |
const int healthBonus = GetHealthBonus(pd); |
| 562 |
if (healthBonus != 0) |
| 563 |
{ |
| 564 |
mData->pDatas[idx].HealthResurrection = |
| 565 |
AnimatedCounterNew("Health bonus: ", healthBonus); |
| 566 |
} |
| 567 |
const int resurrectionFee = GetResurrectionFee(pd); |
| 568 |
if (resurrectionFee != 0) |
| 569 |
{ |
| 570 |
mData->pDatas[idx].HealthResurrection = |
| 571 |
AnimatedCounterNew("Resurrection fee: ", resurrectionFee); |
| 572 |
} |
| 573 |
|
| 574 |
const int butcherPenalty = GetButcherPenalty(pd); |
| 575 |
if (butcherPenalty != 0) |
| 576 |
{ |
| 577 |
mData->pDatas[idx].ButcherNinjaFriendly = |
| 578 |
AnimatedCounterNew("Butcher penalty: ", butcherPenalty); |
| 579 |
} |
| 580 |
const int ninjaBonus = GetNinjaBonus(pd); |
| 581 |
if (ninjaBonus != 0) |
| 582 |
{ |
| 583 |
mData->pDatas[idx].ButcherNinjaFriendly = |
| 584 |
AnimatedCounterNew("Ninja bonus: ", ninjaBonus); |
| 585 |
} |
| 586 |
const int friendlyBonus = GetFriendlyBonus(pd); |
| 587 |
if (friendlyBonus != 0) |
| 588 |
{ |
| 589 |
mData->pDatas[idx].ButcherNinjaFriendly = |
| 590 |
AnimatedCounterNew("Friendly bonus: ", friendlyBonus); |
| 591 |
} |
| 592 |
} |
| 593 |
idx++; |
| 594 |
CA_FOREACH_END() |
| 595 |
} |
| 596 |
static GameLoopResult MissionSummaryUpdate(GameLoopData *data, LoopRunner *l) |
| 597 |
{ |
| 598 |
MissionSummaryData *mData = data->Data; |
| 599 |
|
| 600 |
GameLoopResult result = MenuUpdate(&mData->ms); |
| 601 |
if (result == UPDATE_RESULT_DRAW) |
| 602 |
{ |
| 603 |
bool done = true; |
| 604 |
done = AnimatedCounterUpdate(&mData->AccessBonus, 1) && done; |
| 605 |
done = AnimatedCounterUpdate(&mData->TimeBonus, 1) && done; |
| 606 |
for (int i = 0; i < MAX_LOCAL_PLAYERS; i++) |
| 607 |
{ |
| 608 |
done = AnimatedCounterUpdate(&mData->pDatas[i].Score, 1) && done; |
| 609 |
done = AnimatedCounterUpdate(&mData->pDatas[i].Total, 1) && done; |
| 610 |
done = AnimatedCounterUpdate(&mData->pDatas[i].Time, 1) && done; |
| 611 |
done = |
| 612 |
AnimatedCounterUpdate(&mData->pDatas[i].TimeTotal, 1) && done; |
| 613 |
done = AnimatedCounterUpdate( |
| 614 |
&mData->pDatas[i].HealthResurrection, 1) && |
| 615 |
done; |
| 616 |
done = AnimatedCounterUpdate( |
| 617 |
&mData->pDatas[i].ButcherNinjaFriendly, 1) && |
| 618 |
done; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
if (done && gEventHandlers.DemoQuitTimer > 0) |
| 623 |
{ |
| 624 |
result = UPDATE_RESULT_OK; |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
if (result == UPDATE_RESULT_OK || mData->m->missionData->SkipDebrief) |
| 629 |
{ |
| 630 |
gCampaign.IsComplete = |
| 631 |
mData->completed && |
| 632 |
mData->m->NextMission >= (int)gCampaign.Setting.Missions.size; |
| 633 |
if (gCampaign.IsComplete) |
| 634 |
{ |
| 635 |
LoopRunnerChange(l, ScreenVictory(&gCampaign)); |
| 636 |
} |
| 637 |
else |
| 638 |
{ |
| 639 |
|
| 640 |
gCampaign.IsQuit = mData->ms.current->u.returnCode == 1; |
| 641 |
LoopRunnerPop(l); |
| 642 |
} |
| 643 |
} |
| 644 |
return result; |
| 645 |
} |
| 646 |
static void MissionSummaryDraw(GameLoopData *data) |
| 647 |
{ |
| 648 |
const MissionSummaryData *mData = data->Data; |
| 649 |
|
| 650 |
MenuDraw(&mData->ms); |
| 651 |
} |
| 652 |
static bool AreAnySurvived(void) |
| 653 |
{ |
| 654 |
CA_FOREACH(const PlayerData, p, gPlayerDatas) |
| 655 |
if (p->survived) |
| 656 |
{ |
| 657 |
return true; |
| 658 |
} |
| 659 |
CA_FOREACH_END() |
| 660 |
return false; |
| 661 |
} |
| 662 |
static int GetAccessBonus(const struct MissionOptions *m) |
| 663 |
{ |
| 664 |
return KeycardCount(m->KeyFlags) * 50; |
| 665 |
} |
| 666 |
static int GetTimeBonus(const struct MissionOptions *m, int *secondsOut) |
| 667 |
{ |
| 668 |
int seconds = 60 + (int)m->missionData->Objectives.size * 30 - |
| 669 |
m->time / FPS_FRAMELIMIT; |
| 670 |
if (seconds < 0) |
| 671 |
{ |
| 672 |
seconds = 0; |
| 673 |
} |
| 674 |
if (secondsOut) |
| 675 |
{ |
| 676 |
*secondsOut = seconds; |
| 677 |
} |
| 678 |
return seconds * 25; |
| 679 |
} |
| 680 |
static void ApplyBonuses(PlayerData *p, const int bonus) |
| 681 |
{ |
| 682 |
|
| 683 |
if (!p->survived) |
| 684 |
{ |
| 685 |
return; |
| 686 |
} |
| 687 |
|
| 688 |
p->Totals.Score += bonus; |
| 689 |
|
| 690 |
|
| 691 |
p->Totals.Score += GetHealthBonus(p); |
| 692 |
p->Totals.Score += GetResurrectionFee(p); |
| 693 |
p->Totals.Score += GetButcherPenalty(p); |
| 694 |
p->Totals.Score += GetNinjaBonus(p); |
| 695 |
p->Totals.Score += GetFriendlyBonus(p); |
| 696 |
} |
| 697 |
static int GetHealthBonus(const PlayerData *p) |
| 698 |
{ |
| 699 |
const int maxHealth = p->Char.maxHealth; |
| 700 |
const int hp = MIN(p->hp, maxHealth); |
| 701 |
return hp > maxHealth - 50 ? (hp + 50 - p->Char.maxHealth) * 10 : 0; |
| 702 |
} |
| 703 |
static int GetResurrectionFee(const PlayerData *p) |
| 704 |
{ |
| 705 |
return p->hp <= 0 ? -500 : 0; |
| 706 |
} |
| 707 |
static int GetButcherPenalty(const PlayerData *p) |
| 708 |
{ |
| 709 |
if (p->Stats.Friendlies > 5 && p->Stats.Friendlies > p->Stats.Kills / 2) |
| 710 |
{ |
| 711 |
return -100 * p->Stats.Friendlies; |
| 712 |
} |
| 713 |
return 0; |
| 714 |
} |
| 715 |
|
| 716 |
static int GetNinjaBonus(const PlayerData *p) |
| 717 |
{ |
| 718 |
if (PlayerGetNumWeapons(p) == 1) |
| 719 |
{ |
| 720 |
const WeaponClass *wc = NULL; |
| 721 |
for (int i = 0; i < MAX_GUNS; i++) |
| 722 |
{ |
| 723 |
if (p->guns[i] != NULL) |
| 724 |
{ |
| 725 |
wc = p->guns[i]; |
| 726 |
break; |
| 727 |
} |
| 728 |
} |
| 729 |
if (wc != NULL && !WeaponClassCanShoot(wc) && |
| 730 |
p->Stats.Friendlies == 0 && p->Stats.Kills > 5) |
| 731 |
{ |
| 732 |
return 50 * p->Stats.Kills; |
| 733 |
} |
| 734 |
} |
| 735 |
return 0; |
| 736 |
} |
| 737 |
static int GetFriendlyBonus(const PlayerData *p) |
| 738 |
{ |
| 739 |
return (p->Stats.Kills == 0 && p->Stats.Friendlies == 0) ? 500 : 0; |
| 740 |
} |
| 741 |
static void DrawPlayerSummary( |
| 742 |
const struct vec2i pos, const struct vec2i size, |
| 743 |
const PlayerSummaryDrawData *data); |
| 744 |
static void MissionSummaryMenuDraw( |
| 745 |
const menu_t *menu, GraphicsDevice *g, const struct vec2i p, |
| 746 |
const struct vec2i size, const void *data) |
| 747 |
{ |
| 748 |
UNUSED(menu); |
| 749 |
UNUSED(p); |
| 750 |
UNUSED(size); |
| 751 |
const MissionSummaryData *mData = data; |
| 752 |
|
| 753 |
const int w = gGraphicsDevice.cachedConfig.Res.x; |
| 754 |
const int h = gGraphicsDevice.cachedConfig.Res.y; |
| 755 |
|
| 756 |
|
| 757 |
struct vec2i pos = svec2i(w / 6, h / 2 + h / 10); |
| 758 |
int idx = 1; |
| 759 |
CA_FOREACH(const Objective, o, mData->m->missionData->Objectives) |
| 760 |
|
| 761 |
if (o->done == 0 && !ObjectiveIsRequired(o)) |
| 762 |
{ |
| 763 |
continue; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
DrawObjectiveInfo(o, svec2i_add(pos, svec2i(-26, FontH()))); |
| 768 |
|
| 769 |
|
| 770 |
char s[100]; |
| 771 |
sprintf( |
| 772 |
s, "Objective %d: %d of %d, %d required", idx, o->done, o->Count, |
| 773 |
o->Required); |
| 774 |
FontOpts opts = FontOptsNew(); |
| 775 |
opts.Area = g->cachedConfig.Res; |
| 776 |
opts.Pad = pos; |
| 777 |
if (!ObjectiveIsRequired(o)) |
| 778 |
{ |
| 779 |
|
| 780 |
opts.Mask = colorPurple; |
| 781 |
} |
| 782 |
FontStrOpt(s, svec2i_zero(), opts); |
| 783 |
|
| 784 |
|
| 785 |
opts = FontOptsNew(); |
| 786 |
opts.HAlign = ALIGN_END; |
| 787 |
opts.Area = g->cachedConfig.Res; |
| 788 |
opts.Pad = pos; |
| 789 |
if (!ObjectiveIsComplete(o)) |
| 790 |
{ |
| 791 |
opts.Mask = colorRed; |
| 792 |
FontStrOpt("Failed", svec2i_zero(), opts); |
| 793 |
} |
| 794 |
else if (ObjectiveIsPerfect(o) && AreAnySurvived()) |
| 795 |
{ |
| 796 |
opts.Mask = colorGreen; |
| 797 |
char buf[16]; |
| 798 |
sprintf(buf, "Perfect: %d", PERFECT_BONUS); |
| 799 |
FontStrOpt(buf, svec2i_zero(), opts); |
| 800 |
} |
| 801 |
else if (ObjectiveIsRequired(o)) |
| 802 |
{ |
| 803 |
FontStrOpt("Done", svec2i_zero(), opts); |
| 804 |
} |
| 805 |
else |
| 806 |
{ |
| 807 |
FontStrOpt("Bonus!", svec2i_zero(), opts); |
| 808 |
} |
| 809 |
|
| 810 |
pos.y += 15; |
| 811 |
idx++; |
| 812 |
CA_FOREACH_END() |
| 813 |
|
| 814 |
|
| 815 |
if (mData->AccessBonus.prefix) |
| 816 |
{ |
| 817 |
AnimatedCounterDraw(&mData->AccessBonus, pos); |
| 818 |
pos.y += FontH() + 1; |
| 819 |
} |
| 820 |
if (mData->TimeBonus.prefix) |
| 821 |
{ |
| 822 |
AnimatedCounterDraw(&mData->TimeBonus, pos); |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
struct vec2i playerSize; |
| 827 |
switch (GetNumPlayers(PLAYER_ANY, false, true)) |
| 828 |
{ |
| 829 |
case 1: |
| 830 |
playerSize = svec2i(w, h / 2); |
| 831 |
DrawPlayerSummary(svec2i_zero(), playerSize, &mData->pDatas[0]); |
| 832 |
break; |
| 833 |
case 2: |
| 834 |
|
| 835 |
playerSize = svec2i(w / 2, h / 2); |
| 836 |
DrawPlayerSummary(svec2i_zero(), playerSize, &mData->pDatas[0]); |
| 837 |
DrawPlayerSummary(svec2i(w / 2, 0), playerSize, &mData->pDatas[1]); |
| 838 |
break; |
| 839 |
case 3: |
| 840 |
case 4: |
| 841 |
|
| 842 |
playerSize = svec2i(w / 2, h / 4); |
| 843 |
DrawPlayerSummary(svec2i_zero(), playerSize, &mData->pDatas[0]); |
| 844 |
DrawPlayerSummary(svec2i(w / 2, 0), playerSize, &mData->pDatas[1]); |
| 845 |
DrawPlayerSummary(svec2i(0, h / 4), playerSize, &mData->pDatas[2]); |
| 846 |
if (idx == 4) |
| 847 |
{ |
| 848 |
DrawPlayerSummary( |
| 849 |
svec2i(w / 2, h / 4), playerSize, &mData->pDatas[3]); |
| 850 |
} |
| 851 |
break; |
| 852 |
default: |
| 853 |
CASSERT(false, "not implemented"); |
| 854 |
break; |
| 855 |
} |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
static void DrawPlayerSummary( |
| 860 |
const struct vec2i pos, const struct vec2i size, |
| 861 |
const PlayerSummaryDrawData *data) |
| 862 |
{ |
| 863 |
char s[50]; |
| 864 |
const int totalTextHeight = FontH() * 7; |
| 865 |
|
| 866 |
struct vec2i textPos = |
| 867 |
svec2i(pos.x + size.x / 2, CENTER_Y(pos, size, totalTextHeight)); |
| 868 |
|
| 869 |
DisplayCharacterAndName( |
| 870 |
svec2i_add(pos, svec2i(size.x / 4, size.y / 2)), &data->Pd->Char, |
| 871 |
DIRECTION_DOWN, data->Pd->name, colorWhite, data->Pd->guns[0]); |
| 872 |
|
| 873 |
if (data->Pd->survived) |
| 874 |
{ |
| 875 |
FontStr("Completed mission", textPos); |
| 876 |
} |
| 877 |
else |
| 878 |
{ |
| 879 |
FontStrMask("Failed mission", textPos, colorRed); |
| 880 |
} |
| 881 |
|
| 882 |
textPos.y += 2 * FontH(); |
| 883 |
AnimatedCounterDraw(&data->Score, textPos); |
| 884 |
textPos.y += FontH(); |
| 885 |
AnimatedCounterDraw(&data->Total, textPos); |
| 886 |
textPos.y += FontH(); |
| 887 |
AnimatedCounterTimeDraw(&data->Time, textPos); |
| 888 |
textPos.y += FontH(); |
| 889 |
AnimatedCounterTimeDraw(&data->TimeTotal, textPos); |
| 890 |
textPos.y += FontH(); |
| 891 |
sprintf( |
| 892 |
s, "Missions: %d", data->Pd->missions + (data->Pd->survived ? 1 : 0)); |
| 893 |
FontStr(s, textPos); |
| 894 |
textPos.y += FontH(); |
| 895 |
|
| 896 |
if (data->HealthResurrection.prefix) |
| 897 |
{ |
| 898 |
AnimatedCounterDraw(&data->HealthResurrection, textPos); |
| 899 |
textPos.y += FontH(); |
| 900 |
} |
| 901 |
if (data->ButcherNinjaFriendly.prefix) |
| 902 |
{ |
| 903 |
AnimatedCounterDraw(&data->ButcherNinjaFriendly, textPos); |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
static void DrawObjectiveInfo(const Objective *o, const struct vec2i pos) |
| 908 |
{ |
| 909 |
const CharacterStore *store = &gCampaign.Setting.characters; |
| 910 |
|
| 911 |
switch (o->Type) |
| 912 |
{ |
| 913 |
case OBJECTIVE_KILL: { |
| 914 |
const Character *cd = CArrayGet( |
| 915 |
&store->OtherChars, CharacterStoreGetSpecialId(store, 0)); |
| 916 |
DrawHead(gGraphicsDevice.gameWindow.renderer, cd, DIRECTION_DOWN, pos); |
| 917 |
} |
| 918 |
break; |
| 919 |
case OBJECTIVE_RESCUE: { |
| 920 |
const Character *cd = CArrayGet( |
| 921 |
&store->OtherChars, CharacterStoreGetPrisonerId(store, 0)); |
| 922 |
DrawHead(gGraphicsDevice.gameWindow.renderer, cd, DIRECTION_DOWN, pos); |
| 923 |
} |
| 924 |
break; |
| 925 |
case OBJECTIVE_COLLECT: { |
| 926 |
struct vec2i drawPos = pos; |
| 927 |
CA_FOREACH(const PickupClass *, pc, o->u.Pickups) |
| 928 |
CPicDraw( |
| 929 |
&gGraphicsDevice, &(*pc)->Pic, |
| 930 |
svec2i_subtract(drawPos, svec2i(-4, -4)), NULL); |
| 931 |
drawPos = svec2i_add(drawPos, svec2i(4, 2)); |
| 932 |
CA_FOREACH_END() |
| 933 |
} |
| 934 |
break; |
| 935 |
case OBJECTIVE_DESTROY: { |
| 936 |
struct vec2i drawPos = pos; |
| 937 |
CA_FOREACH(const MapObject *, mo, o->u.MapObjects) |
| 938 |
struct vec2i picOffset; |
| 939 |
const Pic *p = MapObjectGetPic(*mo, &picOffset); |
| 940 |
PicRender( |
| 941 |
p, gGraphicsDevice.gameWindow.renderer, |
| 942 |
svec2i_add(drawPos, picOffset), colorWhite, 0, svec2_one(), |
| 943 |
SDL_FLIP_NONE, Rect2iZero()); |
| 944 |
drawPos = svec2i_add(drawPos, svec2i(4, 2)); |
| 945 |
CA_FOREACH_END() |
| 946 |
} |
| 947 |
break; |
| 948 |
case OBJECTIVE_INVESTIGATE: |
| 949 |
|
| 950 |
return; |
| 951 |
default: |
| 952 |
CASSERT(false, "Unknown objective type"); |
| 953 |
return; |
| 954 |
} |
| 955 |
} |