summaryrefslogtreecommitdiffhomepage
path: root/Stars45/RadioMessage.cpp
blob: ba0a9154e3e486376ddc94e12894555f70cb1429 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*  Starshatter OpenSource Distribution
    Copyright (c) 1997-2004, Destroyer Studios LLC.
    All Rights Reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name "Destroyer Studios" nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    POSSIBILITY OF SUCH DAMAGE.

    SUBSYSTEM:    Stars.exe
    FILE:         RadioMessage.cpp
    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
    Radio communication message class implementation
*/

#include "MemDebug.h"
#include "RadioMessage.h"
#include "Ship.h"
#include "Text.h"

// +----------------------------------------------------------------------+

RadioMessage::RadioMessage(Ship*    dst, const Ship* s, int a)
: dst_ship(dst), dst_elem(0), sender(s), action(a), channel(0)
{
    if (s)
    channel = s->GetIFF();
}

RadioMessage::RadioMessage(Element* dst, const Ship* s, int a)
: dst_ship(0), dst_elem(dst), sender(s), action(a), channel(0)
{
    if (s)
    channel = s->GetIFF();
}

RadioMessage::RadioMessage(const RadioMessage& rm)
: dst_ship(rm.dst_ship), dst_elem(rm.dst_elem),
sender(rm.sender), action(rm.action), channel(rm.channel),
info(rm.info), location(rm.location)
{
    if (rm.target_list.size() > 0) {
        for (int i = 0; i < rm.target_list.size(); i++) {
            SimObject* obj = rm.target_list.at(i);
            target_list.append(obj);
        }
    }
}

RadioMessage::~RadioMessage()
{ }

// +----------------------------------------------------------------------+

const char*
RadioMessage::ActionName(int a)
{
    if (a == ACK) {
        int coin = rand();
        if (coin < 10000)       return "Acknowledged";
        if (coin < 17000)       return "Roger that";
        if (coin < 20000)       return "Understood";
        if (coin < 22000)       return "Copy that";
        return "Affirmative";
    }

    if (a == DISTRESS) {
        int coin = rand();
        if (coin < 15000)       return "Mayday! Mayday!";
        if (coin < 18000)       return "She's breaking up!";
        if (coin < 21000)       return "Checking out!";
        return "We're going down!";
    }

    if (a == WARN_ACCIDENT) {
        int coin = rand();
        if (coin < 15000)       return "Check your fire!";
        if (coin < 18000)       return "Watch it!";
        if (coin < 21000)       return "Hey! We're on your side!";
        return "Confirm your targets!";
    }

    if (a == WARN_TARGETED) {
        int coin = rand();
        if (coin < 15000)       return "Break off immediately!";
        if (coin < 20000)       return "Buddy spike!";
        return "Abort! Abort!";
    }

    switch (a) {
    case NONE:                 return "";

    case NACK:                 return "Negative, Unable";

    case ATTACK:               return "Engage";
    case ESCORT:               return "Escort";
    case BRACKET:              return "Bracket";
    case IDENTIFY:             return "Identify";

    case COVER_ME:             return "Cover Me";
    case MOVE_PATROL:          return "Vector";
    case SKIP_NAVPOINT:        return "Skip Navpoint";
    case RESUME_MISSION:       return "Resume Mission";
    case RTB:                  return "Return to Base";
    case DOCK_WITH:            return "Dock With";
    case QUANTUM_TO:           return "Jump to";
    case FARCAST_TO:           return "Farcast to";

    case GO_DIAMOND:           return "Goto Diamond Formation";
    case GO_SPREAD:            return "Goto Spread Formation";
    case GO_BOX:               return "Goto Box Formation";
    case GO_TRAIL:             return "Goto Trail Formation";

    case WEP_FREE:             return "Break and Attack";
    case WEP_HOLD:             return "Hold All Weapons";
    case FORM_UP:              return "Return to Formation";
    case SAY_POSITION:         return "Say Your Position";

    case LAUNCH_PROBE:         return "Launch Probe";
    case GO_EMCON1:            return "Goto EMCON 1";
    case GO_EMCON2:            return "Goto EMCON 2";
    case GO_EMCON3:            return "Goto EMCON 3";

    case REQUEST_PICTURE:      return "Request Picture";
    case REQUEST_SUPPORT:      return "Request Support";
    case PICTURE:              return "Picture is clear";

    case CALL_INBOUND:         return "Calling Inbound";
    case CALL_APPROACH:        return "Roger your approach";
    case CALL_CLEARANCE:       return "You have clearance";
    case CALL_FINALS:          return "On final approach";
    case CALL_WAVE_OFF:        return "Wave off - Runway is closed";

    case DECLARE_ROGUE:        return "Prepare to be destroyed!";

    case CALL_ENGAGING:        return "Engaging";
    case FOX_1:                return "Fox One!";
    case FOX_2:                return "Fox Two!";
    case FOX_3:                return "Fox Three!";
    case SPLASH_1:             return "Splash One!";
    case SPLASH_2:             return "Splash Two!";
    case SPLASH_3:             return "Splash Three!";
    case SPLASH_4:             return "Splash Four!";
    case SPLASH_5:             return "Target Destroyed!";
    case SPLASH_6:             return "Enemy Destroyed!";
    case SPLASH_7:             return "Confirmed Kill!";
    case BREAK_ORBIT:          return "Breaking Orbit";
    case MAKE_ORBIT:           return "Heading for Orbit";
    case QUANTUM_JUMP:         return "Going Quantum";

    default:                   return "Unknown";
    }
}

// +----------------------------------------------------------------------+

void
RadioMessage::AddTarget(SimObject* obj)
{
    if (obj && !target_list.contains(obj)) {
        target_list.append(obj);
    }
}