MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CurrentPilotUpdateMissionStatus

Function CurrentPilotUpdateMissionStatus

Descent3/pilot.cpp:1532–1592  ·  view source on GitHub ↗

updates the current pilot's information (level played, mission played, etc) call after every successful mission completion

Source from the content-addressed store, hash-verified

1530// updates the current pilot's information (level played, mission played, etc)
1531// call after every successful mission completion
1532void CurrentPilotUpdateMissionStatus(bool just_add_data) {
1533 // Don't update if it's a multiplayer game
1534 if (Game_mode & GM_MULTI)
1535 return;
1536 // look for the current mission in the player's data
1537 int index;
1538 tMissionData mission_to_use;
1539
1540 index = Current_pilot.find_mission_data(Current_mission.name);
1541
1542 if (index == -1) {
1543
1544 // this mission doesn't exist for the pilot yet, so add the mission to the pilot
1545 mprintf(0, "PILOT: New Mission being added to mission data (%s)\n", Current_mission.name);
1546 mission_to_use.highest_level = 0;
1547 mission_to_use.finished = false;
1548 mission_to_use.num_restores = 0;
1549 mission_to_use.num_saves = 0;
1550 mission_to_use.ship_permissions = Default_ship_permission;
1551 strcpy(mission_to_use.mission_name, Current_mission.name);
1552
1553 Current_pilot.add_mission_data(&mission_to_use);
1554
1555 index = Current_pilot.find_mission_data(Current_mission.name);
1556
1557 ASSERT(index != -1);
1558
1559 } else {
1560 // this pilot has flown this mission before, just update it
1561 mprintf(0, "PILOT: Updating previously flown mission data (%s)\n", Current_mission.name);
1562
1563 Current_pilot.get_mission_data(index, &mission_to_use);
1564 }
1565
1566 if (!just_add_data) {
1567 // bad place to do this, but this code was added at the last minute. a long term fix requires more files to fix.
1568 int max_level;
1569 for (max_level = 0; max_level < Current_mission.num_levels; max_level++) {
1570 if (Current_mission.levels[max_level].flags & LVLFLAG_FINAL) {
1571 max_level++;
1572 break;
1573 }
1574 }
1575
1576 if (Current_mission.cur_level > mission_to_use.highest_level && !IsCheater &&
1577 Current_mission.cur_level < max_level) { // cheaters don't win
1578 ASSERT(!(Game_mode & GM_MULTI));
1579 mission_to_use.highest_level = Current_mission.cur_level;
1580 mission_to_use.ship_permissions = Players[0].ship_permissions;
1581 }
1582
1583 // if we've reached end of mission, we've finished it.
1584 if (Current_mission.cur_level == max_level) {
1585 mission_to_use.finished = true;
1586 }
1587
1588 Current_pilot.edit_mission_data(index, &mission_to_use);
1589 }

Callers 2

EndLevelFunction · 0.85
menu.cppFile · 0.85

Calls 5

PltWriteFileFunction · 0.85
find_mission_dataMethod · 0.80
add_mission_dataMethod · 0.80
get_mission_dataMethod · 0.80
edit_mission_dataMethod · 0.80

Tested by

no test coverage detected