Debian Codegraph @

src/mission.cpp

raw symbols SCIP
1 #include <stdio.h>
2 #include "mission.h"
3
4
5 // This function checks to see what our missions status should be. It
6 // returns MISSION_STARTED, MISSION_SUCCESS or MISSION_FAILED
7 // The old_status should also be one of these, indicating what our
8 // status was before this function was called.
9 // For example "my_mission = Mission_Status(Subs, my_mission);"
10 int Mission_Status(Submarine *all_subs, int old_status)
11 {
12 Submarine *current_sub;
13 int found;
14
15 // if the mission already failed it is too late to save it
16 if (old_status == MISSION_FAILED)
17 return MISSION_FAILED;
18
19 if (! all_subs)
20 return MISSION_FAILED;
21
22 // go through each sub and check its status
23 current_sub = all_subs;
24 found = FALSE;
25 while ( (current_sub) && (! found) )
26 {
27 if (current_sub->mission_status == MISSION_NONE)
28 {
29 #ifdef DEBUG
30 printf("Moving to next ship that might have a mission.\n");
31 #endif
32 current_sub = current_sub->next;
33 }
34 else
35 {
36 #ifdef DEBUG
37 printf("Found ship that still has a mission.\n");
38 #endif
39 found = TRUE;
40 }
41 }
42
43 // mission not complete
44 if (found)
45 return MISSION_STARTED;
46 return MISSION_SUCCESS;
47 }
48
49
50
51 int Check_Find(Submarine *all_subs)
52 {
53 Submarine *player, *current_sub;
54 int signal_strength;
55
56 if (! all_subs)
57 return FALSE;
58
59 player = all_subs;
60 current_sub = all_subs->next;
61 while (current_sub)
62 {
63 // we are supposed to be found?
64 if (current_sub->mission_status == MISSION_FIND)
65 {
66 #ifdef DEBUG
67 printf("This ship wants to be found.\n");
68 #endif
69 signal_strength = player->Can_Detect(current_sub);
70 // we can hear you
71 if (signal_strength == CONTACT_SOLID)
72 {
73 #ifdef DEBUG
74 printf("This ship has a contact level of %d\n", signal_strength);
75 #endif
76 current_sub->mission_status = MISSION_NONE;
77 }
78 }
79 current_sub = current_sub->next;
80 }
81
82 return TRUE;
83 }
84
85
86
87 // This function checks to see if the mission depends on
88 // any ships remaining alive for a given amount of time.
89 // Any ships which have the MISSION_ALIVE flag set will
90 // have their timer reduced. If the timer hits zero (0)
91 // then we change the mission flag to be MISSION_NONE.
92 // This function returns TRUE if everything goes normally
93 // or FALSE if we encounter an error.
94 int Check_Alive(Submarine *all_subs)
95 {
96 Submarine *current;
97
98 if (! all_subs)
99 return FALSE;
100
101 current = all_subs;
102 while (current)
103 {
104 if (current->mission_status == MISSION_ALIVE)
105 {
106 current->mission_timer--;
107 if (current->mission_timer < 1)
108 current->mission_status = MISSION_NONE;
109 }
110 current = current->next;
111 }
112
113 return TRUE;
114 }