| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/TelComCargo.cpp $ |
| 21 | * $Revision: 16 $ |
| 22 | * $Date: 4/23/99 9:25p $ |
| 23 | * $Author: Matt $ |
| 24 | * |
| 25 | * TelCom Cargo implentation |
| 26 | * |
| 27 | * $Log: /DescentIII/main/TelComCargo.cpp $ |
| 28 | * |
| 29 | * 16 4/23/99 9:25p Matt |
| 30 | * Fixed a dereferencing bug that was causing this screen to use totally |
| 31 | * different fonts than the code intended. It now uses the two briefing |
| 32 | * fonts. |
| 33 | * |
| 34 | * 15 4/19/99 3:47a Jeff |
| 35 | * fixed min/max for linux |
| 36 | * |
| 37 | * 14 4/14/99 4:19a Jeff |
| 38 | * more case mismatch fixes in #includes |
| 39 | * |
| 40 | * 13 4/14/99 3:57a Jeff |
| 41 | * fixed case mismatch in #includes |
| 42 | * |
| 43 | * 12 2/20/99 9:22p Jeff |
| 44 | * finished telcom level goals screen. Made it so if you go into the |
| 45 | * telcom from the game it goes to main menu instead of briefings. |
| 46 | * |
| 47 | * 11 2/01/99 9:17a Matt |
| 48 | * Fixed compile warning |
| 49 | * |
| 50 | * 10 1/30/99 4:42p Jeff |
| 51 | * primative ship status |
| 52 | * |
| 53 | * 9 1/29/99 7:13p Jeff |
| 54 | * localization |
| 55 | * |
| 56 | * 8 10/12/98 8:32p Jeff |
| 57 | * changed the way focus is handled |
| 58 | * |
| 59 | * 7 10/08/98 4:23p Kevin |
| 60 | * Changed code to comply with memory library usage. Always use mem_malloc |
| 61 | * , mem_free and mem_strdup |
| 62 | * |
| 63 | * 6 8/28/98 12:57p Jeff |
| 64 | * added sounds and some key functionality |
| 65 | * |
| 66 | * 5 8/27/98 2:51p Jeff |
| 67 | * New TelCom finally checked in |
| 68 | * |
| 69 | * 4 7/11/98 9:17p Jeff |
| 70 | * looking much better. Most of the functionality is now done. |
| 71 | * |
| 72 | * 3 7/10/98 7:49p Jeff |
| 73 | * |
| 74 | * 2 7/08/98 8:06p Jeff |
| 75 | * Initial creation of TelComCargo |
| 76 | * |
| 77 | * $NoKeywords: $ |
| 78 | */ |
| 79 | |
| 80 | #include "TelComCargo.h" |
| 81 | #include <stdlib.h> |
| 82 | #include <string.h> |
| 83 | #include <ctype.h> |
| 84 | |
| 85 | #include "cfile.h" |
| 86 | #include "pserror.h" |
| 87 | #include "ddio.h" |
| 88 | #include "bitmap.h" |
| 89 | |
| 90 | #include "TelCom.h" |
| 91 | #include "renderer.h" |
| 92 | #include "game.h" |
| 93 | #include "mem.h" |
| 94 | #include "stringtable.h" |
| 95 | #include "Inventory.h" |
| 96 | #include "player.h" |
| 97 | #include "gametexture.h" |
| 98 | #include "textaux.h" |
| 99 | #include "TelComEfxStructs.h" |
| 100 | #include "TelComEffects.h" |
| 101 | #include "weapon.h" |
| 102 | #include "hlsoundlib.h" |
| 103 | |
| 104 | #include <algorithm> |
| 105 | |
| 106 | #define TCBACK_BUTTON_X 500 |
| 107 | #define TCBACK_BUTTON_Y 350 |
| 108 | #define TCFORW_BUTTON_X 532 |
| 109 | #define TCFORW_BUTTON_Y 350 |
| 110 | |
| 111 | #define LIT_TITLE 0 |
| 112 | #define LIT_VALUE 1 |
| 113 | |
| 114 | #define LID_NONE -1 |
| 115 | #define LID_SHIELDS 0 |
| 116 | #define LID_ENERGY 1 |
| 117 | #define LID_PRIMARIES 2 |
| 118 | #define LID_SECONDARIES 3 |
| 119 | #define LID_COUNTERMEASURES 4 |
| 120 | #define LID_INVENTORY 5 |
| 121 | |
| 122 | struct tLineInfo { |
| 123 | uint8_t type; |
| 124 | const char *name; |
| 125 | int id; |
| 126 | }; |
| 127 | |
| 128 | tLineInfo StatusLines[] = { |
| 129 | {LIT_TITLE, "Ship Status", LID_NONE}, {LIT_VALUE, "Shields", LID_SHIELDS}, |
| 130 | {LIT_VALUE, "Energy", LID_ENERGY}, {LIT_TITLE, "Primaries", LID_PRIMARIES}, |
| 131 | {LIT_TITLE, "Secondaries", LID_SECONDARIES}, {LIT_TITLE, "Counter Measures", LID_COUNTERMEASURES}, |
| 132 | {LIT_TITLE, "Inventory", LID_INVENTORY}}; |
| 133 | |
| 134 | #define NUM_LINES (sizeof(StatusLines) / sizeof(tLineInfo)) |
| 135 | #define TITLE_X 30 + TCminx |
| 136 | #define VALUE_X 400 + TCminx |
| 137 | static int TCminx, TCmaxx, TCminy, TCmaxy; |
| 138 | #define SM_FONT BRIEFING_FONT |
| 139 | #define BG_FONT BIG_BRIEFING_FONT |
| 140 | |
| 141 | // Returns true if the player has this weapon (this fuction should be moved) |
| 142 | bool TCCPlayerHasWeapon(int weapon_index) { |
| 143 | if (Players[Player_num].weapon_flags & HAS_FLAG(weapon_index)) |
| 144 | return true; |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | int TCCargoCreateLine(int id, int y, const char *title, int type) { |
| 149 | // char buffer[100]; |
| 150 | int small_height = grfont_GetHeight(SM_FONT); |
| 151 | int big_height = grfont_GetHeight(BG_FONT); |
| 152 | |
| 153 | switch (id) { |
| 154 | case LID_NONE: |
| 155 | return y; |
| 156 | |
| 157 | case LID_SHIELDS: { |
| 158 | grtext_SetFont(SM_FONT); |
| 159 | |
| 160 | float shields = Player_object->shields; |
| 161 | shields = std::max<float>(shields, 0); |
| 162 | int perc = (int)((shields / INITIAL_SHIELDS) * 100.0f); |
| 163 | grtext_Printf(TITLE_X, y, title); |
| 164 | grtext_Printf(VALUE_X, y, "%d%c", perc, '%'); |
| 165 | y += small_height; |
| 166 | |
| 167 | } break; |
| 168 | |
| 169 | case LID_ENERGY: { |
| 170 | grtext_SetFont(SM_FONT); |
| 171 | |
| 172 | float energy = Players[Player_num].energy; |
| 173 | energy = std::max<float>(energy, 0); |
| 174 | int perc = (int)((energy / INITIAL_ENERGY) * 100.0f); |
| 175 | grtext_Printf(TITLE_X, y, title); |
| 176 | grtext_Printf(VALUE_X, y, "%d%c", perc, '%'); |
| 177 | y += small_height; |
| 178 | |
| 179 | } break; |
| 180 | |
| 181 | case LID_PRIMARIES: { |
| 182 | grtext_SetFont(SM_FONT); |
| 183 | int prim_start = PRIMARY_INDEX; |
| 184 | int prim_end = (PRIMARY_INDEX < SECONDARY_INDEX) ? SECONDARY_INDEX : MAX_STATIC_WEAPONS; |
| 185 | int weap_index; |
| 186 | weapon *weap; |
| 187 | |
| 188 | ASSERT(prim_start >= 0); |
| 189 | ASSERT(prim_end <= MAX_STATIC_WEAPONS); |
| 190 | ASSERT(prim_start < prim_end); |
| 191 | |
| 192 | for (weap_index = prim_start; weap_index < prim_end; weap_index++) { |
| 193 | if (TCCPlayerHasWeapon(weap_index)) { |
| 194 | weap = &Weapons[weap_index]; |
| 195 | grtext_Printf(TITLE_X, y, Static_weapon_names[weap_index]); |
| 196 | y += small_height; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | } break; |
| 201 | |
| 202 | case LID_SECONDARIES: { |
| 203 | grtext_SetFont(SM_FONT); |
| 204 | int sec_start = SECONDARY_INDEX; |
| 205 | int sec_end = (SECONDARY_INDEX < PRIMARY_INDEX) ? PRIMARY_INDEX : MAX_STATIC_WEAPONS; |
| 206 | int weap_index; |
| 207 | weapon *weap; |
| 208 | |
| 209 | ASSERT(sec_start >= 0); |
| 210 | ASSERT(sec_end <= MAX_STATIC_WEAPONS); |
| 211 | ASSERT(sec_start < sec_end); |
| 212 | |
| 213 | for (weap_index = sec_start; weap_index < sec_end; weap_index++) { |
| 214 | if (TCCPlayerHasWeapon(weap_index)) { |
| 215 | weap = &Weapons[weap_index]; |
| 216 | grtext_Printf(TITLE_X, y, Static_weapon_names[weap_index]); |
| 217 | y += small_height; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | } break; |
| 222 | |
| 223 | case LID_COUNTERMEASURES: |
| 224 | break; |
| 225 | |
| 226 | case LID_INVENTORY: |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | return y; |
| 231 | } |
| 232 | |
| 233 | void TCCargoButtonCallback(int efxnum) { |
| 234 | // tccargo_button_pressed = efxnum; |
| 235 | } |
| 236 | |
| 237 | void TCCargoRenderCallback(void) { |
| 238 | grtext_SetFont(BRIEFING_FONT); |
| 239 | grtext_SetAlpha(255); |
| 240 | rend_SetOverlayType(OT_NONE); |
| 241 | rend_SetLighting(LS_NONE); |
| 242 | rend_SetColorModel(CM_MONO); |
| 243 | rend_SetZBufferState(0); |
| 244 | rend_SetAlphaType(AT_CONSTANT + AT_TEXTURE); |
| 245 | rend_SetAlphaValue(255); |
| 246 | rend_SetZBufferState(0); |
| 247 | // update inventory rendering |
| 248 | |
| 249 | int y = TCminy; |
| 250 | int id; |
| 251 | grtext_SetAlpha(255); |
| 252 | grtext_SetColor(GR_WHITE); |
| 253 | |
| 254 | for (int i = 0; i < NUM_LINES; i++) { |
| 255 | id = StatusLines[i].id; |
| 256 | |
| 257 | y = TCCargoCreateLine(id, y, StatusLines[i].name, StatusLines[i].type); |
| 258 | } |
| 259 | |
| 260 | grtext_Flush(); |
| 261 | |
| 262 | rend_SetZBufferState(1); |
| 263 | } |
| 264 | |
| 265 | // This is the function called by TelCom |
| 266 | // return true if TelCom should exit to TelCom Main Menu |
| 267 | // return false if you should exit out of TelCom completly |
| 268 | bool TelComCargo(tTelComInfo *tcs) { |
| 269 | // int efxmap[2]; |
| 270 | bool done = false; |
| 271 | |
| 272 | TelcomStartScreen(0); |
| 273 | |
| 274 | TCBKGDESC backg; |
| 275 | backg.color = BACKGROUND_COLOR; |
| 276 | backg.caps = TCBGD_COLOR; |
| 277 | backg.type = TC_BACK_STATIC; |
| 278 | CreateBackgroundEffect(&backg, MONITOR_MAIN, 0); |
| 279 | CreateBackgroundEffect(&backg, MONITOR_TOP, 0); |
| 280 | |
| 281 | // Setup On-Screen buttons |
| 282 | /* |
| 283 | TCBUTTONDESC buttdesc; |
| 284 | strcpy(buttdesc.filename,BACK_BUTTON); |
| 285 | strcpy(buttdesc.flash_filename,BACK_BUTTON_GLOW); |
| 286 | buttdesc.sibling_id = buttdesc.parent_id = -1; |
| 287 | buttdesc.internal = TCCargoButtonCallback; |
| 288 | buttdesc.flash_time = 0; |
| 289 | buttdesc.button_type = BUTT_INTERNAL; |
| 290 | buttdesc.flasher = true; |
| 291 | buttdesc.click_type = CLICKTYPE_CLICKUP; |
| 292 | buttdesc.osflags = OBF_GLOW; |
| 293 | buttdesc.x = TCBACK_BUTTON_X; |
| 294 | buttdesc.y = TCBACK_BUTTON_Y; |
| 295 | buttdesc.tab_stop = true; //these buttons can have focus |
| 296 | efxmap[0] = CreateButtonEffect(&buttdesc,MONITOR_MAIN,0); |
| 297 | strcpy(buttdesc.filename,FORW_BUTTON); |
| 298 | strcpy(buttdesc.flash_filename,FORW_BUTTON_GLOW); |
| 299 | buttdesc.x = TCFORW_BUTTON_X; |
| 300 | buttdesc.y = TCFORW_BUTTON_Y; |
| 301 | efxmap[1] = CreateButtonEffect(&buttdesc,MONITOR_MAIN,0); |
| 302 | */ |
| 303 | |
| 304 | TCminx = tcs->Monitor_coords[MONITOR_MAIN].left + 20; |
| 305 | TCminy = tcs->Monitor_coords[MONITOR_MAIN].top + 10; |
| 306 | TCmaxy = tcs->Monitor_coords[MONITOR_MAIN].bottom - 10; |
| 307 | TCmaxx = tcs->Monitor_coords[MONITOR_MAIN].right - 20; |
| 308 | |
| 309 | TCTEXTDESC textdesc; |
| 310 | textdesc.type = TC_TEXT_STATIC; |
| 311 | textdesc.font = BBRIEF_FONT_INDEX; |
| 312 | textdesc.caps = TCTD_TEXTBOX | TCTD_COLOR | TCTD_FONT; |
| 313 | textdesc.textbox.left = 75; |
| 314 | textdesc.textbox.right = 380; |
| 315 | textdesc.textbox.top = 2; |
| 316 | textdesc.textbox.bottom = 50; |
| 317 | textdesc.color = GR_RGB(255, 255, 255); |
| 318 | |
| 319 | CreateTextEffect(&textdesc, TXT_TCCARGO, MONITOR_TOP, 0); |
| 320 | TelcomEndScreen(); |
| 321 | TelcomRenderSetScreen(0); |
| 322 | |
| 323 | TelcomRenderSetCallback(TCCargoRenderCallback); |
| 324 | |
| 325 | while (!done) { |
| 326 | Sound_system.BeginSoundFrame(Telcom_called_from_game); |
| 327 | |
| 328 | if (tcs->state != TCS_POWERON || tcs->current_status != TS_CARGO) { |
| 329 | // we're done with the loop |
| 330 | done = true; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | if(tccargo_button_pressed!=-1){ |
| 335 | if(tccargo_button_pressed==efxmap[0]) |
| 336 | curr_cargo_page = &Regular; |
| 337 | else |
| 338 | if(tccargo_button_pressed==efxmap[1]) |
| 339 | curr_cargo_page = &CounterMeasures; |
| 340 | tccargo_button_pressed = -1; |
| 341 | } |
| 342 | */ |
| 343 | |
| 344 | // Process all waiting events for the TelCom (we may only want to handle this once a frame!) |
| 345 | TelComHandleAllEvents(&Telcom_system); |
| 346 | |
| 347 | TelcomRenderScreen(); |
| 348 | Descent->defer(); |
| 349 | if (KEY_STATE(KEY_ESC)) |
| 350 | Telcom_system.state = TCS_POWEROFF; |
| 351 | |
| 352 | Sound_system.EndSoundFrame(); |
| 353 | } |
| 354 | |
| 355 | DestroyAllScreens(); |
| 356 | TelcomRenderSetScreen(DUMMY_SCREEN); |
| 357 | TelcomRenderSetCallback(NULL); |
| 358 | |
| 359 | return true; |
| 360 | } |