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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
|
/*
* Copyright (C) Volition, Inc. 1999. All rights reserved.
*
* All source code herein is the property of Volition, Inc. You may not sell
* or otherwise commercially exploit the source or things you created based on the
* source.
*
*/
#include "radar/radar.h"
#include "radar/radarorb.h"
#include "graphics/font.h"
#include "bmpman/bmpman.h"
#include "object/object.h"
#include "jumpnode/jumpnode.h"
#include "ship/ship.h"
#include "playerman/player.h"
#include "weapon/weapon.h"
#include "io/timer.h"
#include "hud/hud.h"
#include "hud/hudconfig.h"
#include "ship/subsysdamage.h"
#include "gamesnd/gamesnd.h"
#include "network/multi.h"
#include "weapon/emp.h"
#include "freespace2/freespace.h"
#include "localization/localize.h"
#include "ship/awacs.h"
#include "radar/radarsetup.h"
#include "iff_defs/iff_defs.h"
#include "globalincs/linklist.h"
int Radar_static_looping = -1;
rcol Radar_color_rgb[MAX_RADAR_COLORS][MAX_RADAR_LEVELS] =
{
// homing missile (yellow)
{
{ 0x40, 0x40, 0x00 }, // dim
{ 0x7f, 0x7f, 0x00 }, // bright
},
// navbuoy or cargo (gray)
{
{ 0x40, 0x40, 0x40 }, // dim
{ 0x7f, 0x7f, 0x7f }, // bright
},
// warping ship (blue)
{
{ 0x00, 0x00, 0x7f }, // dim
{ 0x00, 0x00, 0xff }, // bright
},
// jump node (gray)
{
{ 0x40, 0x40, 0x40 }, // dim
{ 0x7f, 0x7f, 0x7f }, // bright
},
// tagged (yellow)
{
{ 0x7f, 0x7f, 0x00 }, // dim
{ 0xff, 0xff, 0x00 }, // bright
},
};
int radar_target_id_flags = 0;
color Radar_colors[MAX_RADAR_COLORS][MAX_RADAR_LEVELS];
blip Blip_bright_list[MAX_BLIP_TYPES]; // linked list of bright blips
blip Blip_dim_list[MAX_BLIP_TYPES]; // linked list of dim blips
blip Blips[MAX_BLIPS]; // blips pool
int N_blips; // next blip index to take from pool
float Radar_bright_range; // range at which we start dimming the radar blips
int Radar_calc_bright_dist_timer; // timestamp at which we recalc Radar_bright_range
extern int radar_iff_color[5][2][4];
int See_all = 0;
DCF_BOOL(see_all, See_all)
static const char radar_default_filenames[2][16]=
{
"radar1","2_radar1"
};
void radar_stuff_blip_info(object *objp, int is_bright, color **blip_color, int *blip_type)
{
ship *shipp = NULL;
switch(objp->type)
{
case OBJ_SHIP:
shipp = &Ships[objp->instance];
if (shipp->flags & SF_ARRIVING_STAGE_1)
{
*blip_color = &Radar_colors[RCOL_WARPING_SHIP][is_bright];
*blip_type = BLIP_TYPE_WARPING_SHIP;
}
else if (ship_is_tagged(objp))
{
*blip_color = &Radar_colors[RCOL_TAGGED][is_bright];
*blip_type = BLIP_TYPE_TAGGED_SHIP;
}
else if (Ship_info[shipp->ship_info_index].flags & (SIF_NAVBUOY|SIF_CARGO))
{
*blip_color = &Radar_colors[RCOL_NAVBUOY_CARGO][is_bright];
*blip_type = BLIP_TYPE_NAVBUOY_CARGO;
}
else
{
*blip_color = iff_get_color_by_team_and_object(shipp->team, Player_ship->team, is_bright, objp);
*blip_type = BLIP_TYPE_NORMAL_SHIP;
}
break;
case OBJ_WEAPON:
if ((Weapons[objp->instance].lssm_stage == 2) || (Weapons[objp->instance].lssm_stage == 4))
{
*blip_color = &Radar_colors[RCOL_WARPING_SHIP][is_bright];
*blip_type = BLIP_TYPE_WARPING_SHIP;
}
else
{
*blip_color = &Radar_colors[RCOL_BOMB][is_bright];
*blip_type = BLIP_TYPE_BOMB;
}
break;
case OBJ_JUMP_NODE:
*blip_color = &Radar_colors[RCOL_JUMP_NODE][is_bright];
*blip_type = BLIP_TYPE_JUMP_NODE;
break;
default:
Error(LOCATION, "Illegal blip type in radar.");
break;
}
}
void radar_plot_object( object *objp )
{
vec3d pos, tempv;
float awacs_level, dist, max_radar_dist;
vec3d world_pos = objp->pos;
SCP_list<CJumpNode>::iterator jnp;
// don't process anything here. Somehow, a jumpnode object caused this function
// to get entered on server side.
if( Game_mode & GM_STANDALONE_SERVER ){
return;
}
// multiplayer clients ingame joining should skip this function
if ( MULTIPLAYER_CLIENT && (Net_player->flags & NETINFO_FLAG_INGAME_JOIN) ){
return;
}
// get team-wide awacs level for the object if not ship
int ship_is_visible = 0;
if (objp->type == OBJ_SHIP) {
if (Player_ship != NULL) {
if (ship_is_visible_by_team(objp, Player_ship)) {
ship_is_visible = 1;
}
}
}
// only check awacs level if ship is not visible by team
awacs_level = 1.5f;
if (Player_ship != NULL && !ship_is_visible) {
awacs_level = awacs_get_level(objp, Player_ship);
}
// if the awacs level is unviewable - bail
if(awacs_level < 0.0f && !See_all){
return;
}
// Apply object type filters
switch (objp->type)
{
case OBJ_SHIP:
// Place to cull ships, such as NavBuoys
break;
case OBJ_JUMP_NODE:
{
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() == objp)
break;
}
// don't plot hidden jump nodes
if ( jnp->IsHidden() )
return;
// filter jump nodes here if required
break;
}
case OBJ_WEAPON:
{
// if not a bomb, return
if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_SHOWN_ON_RADAR) )
if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_BOMB) )
return;
// if explicitly hidden, return
if (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_DONT_SHOW_ON_RADAR)
return;
// if we don't attack the bomb, return
if ( (!(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_SHOW_FRIENDLY)) && (!iff_x_attacks_y(Player_ship->team, obj_team(objp))))
return;
// if a local ssm is in subspace, return
if (Weapons[objp->instance].lssm_stage == 3)
return;
// if corkscrew missile use last frame pos for pos
if ( (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_CORKSCREW) )
world_pos = objp->last_pos;
break;
}
// if any other kind of object, don't show it on radar
default:
return;
}
// JAS -- new way of getting the rotated point that doesn't require this to be
// in a g3_start_frame/end_frame block.
vm_vec_sub(&tempv, &world_pos, &Player_obj->pos);
vm_vec_rotate(&pos, &tempv, &Player_obj->orient);
// Apply range filter
dist = vm_vec_dist(&world_pos, &Player_obj->pos);
max_radar_dist = Radar_ranges[HUD_config.rp_dist];
if (dist > max_radar_dist) {
return;
}
// determine the range within which the radar blip is bright
if (timestamp_elapsed(Radar_calc_bright_dist_timer))
{
Radar_calc_bright_dist_timer = timestamp(1000);
Radar_bright_range = player_farthest_weapon_range();
if (Radar_bright_range <= 0)
Radar_bright_range = 1500.0f;
}
blip *b;
int blip_bright = 0;
int blip_type = 0;
if (N_blips >= MAX_BLIPS)
{
return;
}
b = &Blips[N_blips];
b->flags = 0;
// bright if within range
blip_bright = (dist <= Radar_bright_range);
// flag the blip as a current target if it is
if (OBJ_INDEX(objp) == Player_ai->target_objnum)
{
b->flags |= BLIP_CURRENT_TARGET;
blip_bright = 1;
}
radar_stuff_blip_info(objp, blip_bright, &b->blip_color, &blip_type);
if (blip_bright)
list_append(&Blip_bright_list[blip_type], b);
else
list_append(&Blip_dim_list[blip_type], b);
b->position = pos;
b->dist = dist;
b->objp = objp;
b->radar_image_2d = -1;
b->radar_color_image_2d = -1;
b->radar_image_size = -1;
b->radar_projection_size = 1.0f;
// see if blip should be drawn distorted
// also determine if alternate image was defined for this ship
if (objp->type == OBJ_SHIP)
{
// ships specifically hidden from sensors
if (Ships[objp->instance].flags & SF_HIDDEN_FROM_SENSORS)
b->flags |= BLIP_DRAW_DISTORTED;
// determine if its AWACS distorted
if (awacs_level < 1.0f)
b->flags |= BLIP_DRAW_DISTORTED;
ship_info Iff_ship_info = Ship_info[Ships[objp->instance].ship_info_index];
if (Iff_ship_info.radar_image_2d_idx >= 0 || Iff_ship_info.radar_color_image_2d_idx >= 0)
{
b->radar_image_2d = Iff_ship_info.radar_image_2d_idx;
b->radar_color_image_2d = Iff_ship_info.radar_color_image_2d_idx;
b->radar_image_size = Iff_ship_info.radar_image_size;
b->radar_projection_size = Iff_ship_info.radar_projection_size_mult;
}
}
// don't distort the sensor blips if the player has primitive sensors and the nebula effect
// is not active
if (Player_ship->flags2 & SF2_PRIMITIVE_SENSORS)
{
if (!(The_mission.flags & MISSION_FLAG_FULLNEB))
b->flags &= ~BLIP_DRAW_DISTORTED;
}
N_blips++;
}
void radar_mission_init()
{
for (int i=0; i<MAX_RADAR_COLORS; i++ ) {
for (int j=0; j<MAX_RADAR_LEVELS; j++ ) {
if (radar_iff_color[i][j][0] >= 0) {
gr_init_alphacolor( &Radar_colors[i][j], radar_iff_color[i][j][0], radar_iff_color[i][j][1], radar_iff_color[i][j][2], radar_iff_color[i][j][3] );
} else {
gr_init_alphacolor( &Radar_colors[i][j], Radar_color_rgb[i][j].r, Radar_color_rgb[i][j].g, Radar_color_rgb[i][j].b, 255 );
}
}
}
Radar_calc_bright_dist_timer = timestamp(0);
}
void radar_null_nblips()
{
int i;
N_blips=0;
for (i=0; i<MAX_BLIP_TYPES; i++) {
list_init(&Blip_bright_list[i]);
list_init(&Blip_dim_list[i]);
}
}
void radar_frame_init()
{
radar_null_nblips();
}
HudGaugeRadar::HudGaugeRadar():
HudGauge(HUD_OBJECT_RADAR_STD, HUD_RADAR, false, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), 255, 255, 255)
{
}
HudGaugeRadar::HudGaugeRadar(int _gauge_object, int r, int g, int b):
HudGauge(_gauge_object, HUD_RADAR, false, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), r, g, b)
{
}
void HudGaugeRadar::initRadius(int w, int h)
{
Radar_radius[0] = w;
Radar_radius[1] = h;
}
void HudGaugeRadar::initBlipRadius(int normal, int target)
{
Radar_blip_radius_normal = normal;
Radar_blip_radius_target = target;
}
void HudGaugeRadar::initDistanceShortOffsets(int x, int y)
{
Radar_dist_offsets[RR_SHORT][0] = x;
Radar_dist_offsets[RR_SHORT][1] = y;
}
void HudGaugeRadar::initDistanceLongOffsets(int x, int y)
{
Radar_dist_offsets[RR_LONG][0] = x;
Radar_dist_offsets[RR_LONG][1] = y;
}
void HudGaugeRadar::initDistanceInfinityOffsets(int x, int y)
{
Radar_dist_offsets[RR_INFINITY][0] = x;
Radar_dist_offsets[RR_INFINITY][1] = y;
}
void HudGaugeRadar::render(float frametime)
{
}
void HudGaugeRadar::pageIn()
{
}
void HudGaugeRadar::initialize()
{
int i;
Radar_death_timer = 0;
Radar_static_playing = 0;
Radar_static_next = 0;
Radar_avail_prev_frame = 1;
Radar_calc_bright_dist_timer = timestamp(0);
for ( i=0; i<NUM_FLICKER_TIMERS; i++ ) {
Radar_flicker_timer[i]=timestamp(0);
Radar_flicker_on[i]=0;
}
int w,h;
gr_set_font(FONT1);
Small_blip_string[0] = ubyte(SMALL_BLIP_CHAR);
Small_blip_string[1] = 0;
gr_get_string_size( &w, &h, Small_blip_string );
Small_blip_offset_x = -w/2;
Small_blip_offset_y = -h/2;
Large_blip_string[0] = ubyte(LARGE_BLIP_CHAR);
Large_blip_string[1] = 0;
gr_get_string_size( &w, &h, Large_blip_string );
Large_blip_offset_x = -w/2;
Large_blip_offset_y = -h/2;
HudGauge::initialize();
}
void HudGaugeRadar::drawRange()
{
char buf[32];
// hud_set_bright_color();
setGaugeColor(HUD_C_BRIGHT);
switch ( HUD_config.rp_dist ) {
case RR_SHORT:
renderPrintf(position[0] + Radar_dist_offsets[RR_SHORT][0], position[1] + Radar_dist_offsets[RR_SHORT][1], XSTR( "2k", 467));
break;
case RR_LONG:
renderPrintf(position[0] + Radar_dist_offsets[RR_LONG][0], position[1] + Radar_dist_offsets[RR_LONG][1], XSTR( "10k", 468));
break;
case RR_INFINITY:
sprintf(buf, NOX("%c"), Lcl_special_chars);
renderPrintf(position[0] + Radar_dist_offsets[RR_INFINITY][0], position[1] + Radar_dist_offsets[RR_INFINITY][1], buf);
break;
default:
Int3(); // can't happen (get Alan if it does)
break;
}
}
/**
* @brief Return if the specified object is visible on the radar
*
* @param objp The object which should be checked
* @return A RadarVisibility enum specifying the visibility of the specified object
*/
RadarVisibility radar_is_visible( object *objp )
{
Assert( objp != NULL );
if (objp->flags & OF_SHOULD_BE_DEAD)
{
return NOT_VISIBLE;
}
vec3d pos, tempv;
float awacs_level, dist, max_radar_dist;
vec3d world_pos = objp->pos;
SCP_list<CJumpNode>::iterator jnp;
// get team-wide awacs level for the object if not ship
int ship_is_visible = 0;
if (objp->type == OBJ_SHIP) {
if (Player_ship != NULL) {
if (ship_is_visible_by_team(objp, Player_ship)) {
ship_is_visible = 1;
}
}
}
// only check awacs level if ship is not visible by team
awacs_level = 1.5f;
if (Player_ship != NULL && !ship_is_visible) {
awacs_level = awacs_get_level(objp, Player_ship);
}
// if the awacs level is unviewable - bail
if(awacs_level < 0.0f && !See_all){
return NOT_VISIBLE;
}
// Apply object type filters
switch (objp->type)
{
case OBJ_SHIP:
if (Ships[objp->instance].flags & SIF_STEALTH)
return NOT_VISIBLE;
// Ships that are warp in in are not visible on the radar
if (Ships[objp->instance].flags & SF_ARRIVING_STAGE_1)
return NOT_VISIBLE;
break;
case OBJ_JUMP_NODE:
{
for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
if(jnp->GetSCPObject() == objp)
break;
}
// don't plot hidden jump nodes
if ( jnp->IsHidden() )
return NOT_VISIBLE;
// filter jump nodes here if required
break;
}
case OBJ_WEAPON:
{
// if not a bomb, return
if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_SHOWN_ON_RADAR) )
if ( !(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags & WIF_BOMB) )
return NOT_VISIBLE;
// if explicitly hidden, return
if (Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_DONT_SHOW_ON_RADAR)
return NOT_VISIBLE;
// if we don't attack the bomb, return
if ( (!(Weapon_info[Weapons[objp->instance].weapon_info_index].wi_flags2 & WIF2_SHOW_FRIENDLY)) && (!iff_x_attacks_y(Player_ship->team, obj_team(objp))))
return NOT_VISIBLE;
// if a local ssm is in subspace, return
if (Weapons[objp->instance].lssm_stage == 3)
return NOT_VISIBLE;
break;
}
// if any other kind of object, don't show it on radar
default:
return NOT_VISIBLE;
}
vm_vec_sub(&tempv, &world_pos, &Player_obj->pos);
vm_vec_rotate(&pos, &tempv, &Player_obj->orient);
// Apply range filter
dist = vm_vec_dist(&world_pos, &Player_obj->pos);
max_radar_dist = Radar_ranges[HUD_config.rp_dist];
if (dist > max_radar_dist) {
return NOT_VISIBLE;
}
if (objp->type == OBJ_SHIP)
{
// ships specifically hidden from sensors
if (Ships[objp->instance].flags & SF_HIDDEN_FROM_SENSORS)
return DISTORTED;
// determine if its AWACS distorted
if (awacs_level < 1.0f)
return DISTORTED;
}
return VISIBLE;
}
|