-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathcomms_ship.lua
218 lines (196 loc) · 8.58 KB
/
comms_ship.lua
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
--- Basic ship comms.
--
-- Simple ship comms that allows setting orders if friendly.
-- Default script for any `CpuShip`.
--
-- @script comms_ship
-- NOTE this could be imported
local MISSILE_TYPES = {"Homing", "Nuke", "Mine", "EMP", "HVLI"}
--- Main menu of communication.
--
-- Uses one of `commsShipFriendly`, `commsShipNeutral`, `commsShipEnemy`.
--
-- @tparam PlayerSpaceship comms_source
-- @tparam SpaceStation comms_target
function commsShipMainMenu(comms_source, comms_target)
if comms_target.comms_data == nil then
comms_target.comms_data = {friendlyness = random(0.0, 100.0)}
end
if comms_source:isFriendly(comms_target) then
return commsShipFriendly(comms_source, comms_target)
end
if comms_source:isEnemy(comms_target) and comms_target:isFriendOrFoeIdentifiedBy(comms_source) then
return commsShipEnemy(comms_source, comms_target)
end
return commsShipNeutral(comms_source, comms_target)
end
--- Handle friendly communication.
--
-- @tparam PlayerSpaceship comms_source
-- @tparam SpaceStation comms_target
function commsShipFriendly(comms_source, comms_target)
local comms_data = comms_target.comms_data
if comms_data.friendlyness < 20 then
setCommsMessage(_("shipAssist-comms", "What do you want?"))
else
setCommsMessage(_("shipAssist-comms", "Sir, how can we assist?"))
end
addCommsReply(
_("shipAssist-comms", "Defend a waypoint"),
function(comms_source, comms_target)
if comms_source:getWaypointCount() == 0 then
setCommsMessage(_("shipAssist-comms", "No waypoints set. Please set a waypoint first."))
addCommsReply(_("Back"), commsShipMainMenu)
else
setCommsMessage(_("shipAssist-comms", "Which waypoint should we defend?"))
for n = 1, comms_source:getWaypointCount() do
addCommsReply(
string.format(_("shipAssist-comms", "Defend %s"), formatWaypoint(n)),
function(comms_source, comms_target)
x, y = comms_source:getWaypoint(n)
comms_target:orderDefendLocation(x, y)
setCommsMessage(string.format(_("shipAssist-comms", "We are heading to assist at %s."), formatWaypoint(n)))
addCommsReply(_("Back"), commsShipMainMenu)
end
)
end
end
end
)
if comms_data.friendlyness > 0.2 then
addCommsReply(
_("shipAssist-comms", "Assist me"),
function(comms_source, comms_target)
setCommsMessage(_("shipAssist-comms", "Heading toward you to assist."))
comms_target:orderDefendTarget(comms_source)
addCommsReply(_("Back"), commsShipMainMenu)
end
)
end
addCommsReply(
_("shipAssist-comms", "Report status"),
function(comms_source, comms_target)
setCommsMessage(getStatusReport(comms_target))
addCommsReply(_("Back"), commsShipMainMenu)
end
)
for idx, obj in ipairs(comms_target:getObjectsInRange(5000)) do
if obj.components.docking_bay ~= nil and not comms_target:isEnemy(obj) then
addCommsReply(
string.format(_("shipAssist-comms", "Dock at %s"), obj:getCallSign()),
function(comms_source, comms_target)
setCommsMessage(string.format(_("shipAssist-comms", "Docking at %s."), obj:getCallSign()))
comms_target:orderDock(obj)
addCommsReply(_("Back"), commsShipMainMenu)
end
)
end
end
return true
end
--- Handle enemy communication.
--
-- @tparam PlayerSpaceship comms_source
-- @tparam SpaceStation comms_target
function commsShipEnemy(comms_source, comms_target)
local comms_data = comms_target.comms_data
if comms_data.friendlyness > 50 then
local faction = comms_target:getFaction()
local message
local taunt_option = _("shipEnemy-comms", "We will see to your destruction!")
local taunt_success_reply = _("shipEnemy-comms", "Your bloodline will end here!")
local taunt_failed_reply = _("shipEnemy-comms", "Your feeble threats are meaningless.")
if faction == "Kraylor" then
message = _("shipEnemy-comms", [[Ktzzzsss.
You will DIEEee weaklingsss!]])
elseif faction == "Arlenians" then
message = _("shipEnemy-comms", [[We wish you no harm, but will harm you if we must.
End of transmission.]])
elseif faction == "Exuari" then
message = _("shipEnemy-comms", "Stay out of our way, or your death will amuse us extremely!")
elseif faction == "Ghosts" then
message = _("shipEnemy-comms", [[One zero one.
No binary communication detected. Switching to universal speech.
Generating appropriate response for target from human language archives.
:Do not cross us.:
Communication halted.]])
taunt_option = _("shipEnemy-comms", "EXECUTE: SELFDESTRUCT")
taunt_success_reply = _("shipEnemy-comms", "Rogue command received. Targeting source.")
taunt_failed_reply = _("shipEnemy-comms", "External command ignored.")
elseif faction == "Ktlitans" then
message = _("shipEnemy-comms", [[The hive suffers no threats. Opposition to any of us is opposition to us all.
Stand down or prepare to donate your corpses toward our nutrition.]])
taunt_option = _("shipEnemy-comms", "<Transmits 'The Itsy-Bitsy Spider' on all wavelengths>")
taunt_success_reply = _("shipEnemy-comms", "We do not need permission to pluck apart such an insignificant threat.")
taunt_failed_reply = _("shipEnemy-comms", "The hive has greater priorities than exterminating pests.")
else
message = _("shipEnemy-comms", "Mind your own business!")
end
setCommsMessage(message)
comms_data.friendlyness = comms_data.friendlyness - random(0, 10)
addCommsReply(
taunt_option,
function(comms_source, comms_target)
if random(0, 100) < 30 then
comms_target:orderAttack(comms_source)
setCommsMessage(taunt_success_reply)
else
setCommsMessage(taunt_failed_reply)
end
end
)
return true
end
return false
end
--- Handle neutral communication.
--
-- @tparam PlayerSpaceship comms_source
-- @tparam SpaceStation comms_target
function commsShipNeutral(comms_source, comms_target)
local message
if comms_target.comms_data.friendlyness > 50 then
message = _("ship-comms", [[Sorry, we have no time to chat with you.
We are on an important mission.]])
else
message = _("ship-comms", [[We have nothing for you.
Good day.]])
end
setCommsMessage(message)
return true
end
--- Return status report of ship.
--
-- Hull, Shields, Missiles.
--
-- @tparam ShipTemplateBasedObject ship the ship
-- @treturn string the report
function getStatusReport(ship)
local msg = string.format(_("shipAssist-comms", "Hull: %d%%\n"), math.floor(ship:getHull() / ship:getHullMax() * 100))
local shields = ship:getShieldCount()
if shields == 1 then
msg = msg .. string.format(_("shipAssist-comms", "Shield: %d%%\n"), math.floor(ship:getShieldLevel(0) / ship:getShieldMax(0) * 100))
elseif shields == 2 then
msg = msg .. string.format(_("shipAssist-comms", "Front Shield: %d%%\n"), math.floor(ship:getShieldLevel(0) / ship:getShieldMax(0) * 100))
msg = msg .. string.format(_("shipAssist-comms", "Rear Shield: %d%%\n"), math.floor(ship:getShieldLevel(1) / ship:getShieldMax(1) * 100))
else
for n = 0, shields - 1 do
msg = msg .. string.format(_("shipAssist-comms", "Shield %d: %d%%\n"), n, math.floor(ship:getShieldLevel(n) / ship:getShieldMax(n) * 100))
end
end
for i, missile_type in ipairs(MISSILE_TYPES) do
if ship:getWeaponStorageMax(missile_type) > 0 then
msg = msg .. string.format(_("shipAssist-comms", "%s Missiles: %d/%d\n"), missile_type, math.floor(ship:getWeaponStorage(missile_type)), math.floor(ship:getWeaponStorageMax(missile_type)))
end
end
return msg
end
--- Format integer i as "WP i".
--
-- @tparam integer i the index of the waypoint
-- @treturn string "WP i"
function formatWaypoint(i)
return string.format(_("shipAssist-comms", "WP %d"), i)
end
-- `comms_source` and `comms_target` are global in comms script.
commsShipMainMenu(comms_source, comms_target)