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 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
|
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// flagbase.cpp
// Project: Postal
//
// This module implements the flag object for capture the flag gameplay.
//
// History:
//
// 06/30/97 BRH Started this file for the challenge levels.
//
// 07/12/97 BRH Added FlagID so that flags can be matched with their
// bases. Added loading/saving thereof. Also added
// EditModify dialog so that the value can be set.
//
// 07/14/97 BRH Changed to using the CSmash::Flagbase bits to identify
// the base. Also added checking for Flags to update
// and incrementing the m_sFlagbaseCaptured value in realm
// when the proper flag meets the base.
//
// 07/16/97 BRH Changed to using the correct base files rather than
// the bandguy as a placeholder.
//
// 08/03/97 JMI Init() was setting the looping parms on a phot which no
// longer exists. Now the looping parms are passed via the
// Get() call in GetResources() instead so they will get set
// via the CAnim3D which should know which ones are okay to
// use.
//
// 08/11/97 BRH Added flagbase color option as a variable that is loaded
// and saved and can be changed in the EditModify dialog.
//
// 08/18/97 JMI Changed State_Dead to call DeadRender3D() (which used to be
// known/called as just another Render() overload).
//
// 08/28/97 BRH Set the correct bits to detect the flag base. Finished
// the code for capturing the flagbase.
//
////////////////////////////////////////////////////////////////////////////////
#define FLAGBASE_CPP
#include "RSPiX.h"
#include "flagbase.h"
#include "flag.h"
#include "SampleMaster.h"
////////////////////////////////////////////////////////////////////////////////
// Macros/types/etc.
////////////////////////////////////////////////////////////////////////////////
#define GUI_FLAGID_EDIT_ID 103
#define GUI_COLOR_EDIT_ID 104
////////////////////////////////////////////////////////////////////////////////
// Variables/data
////////////////////////////////////////////////////////////////////////////////
// These are default values -- actually values are set using the editor!
double CFlagbase::ms_dInRange = 30 * 30; // Sq distance to base
// Let this auto-init to 0
int16_t CFlagbase::ms_sFileCount;
/// Throwing Animation Files ////////////////////////////////////////////////////
// An array of pointers to resource names (one for each channel of the animation)
static char* ms_apszRedResNames[] =
{
"3d/rbase.sop",
"3d/rbase.mesh",
"3d/rbase.tex",
"3d/rbase.hot",
"3d/rbase.bounds",
"3d/rbase.floor",
NULL,
NULL
};
static char* ms_apszBlueResNames[] =
{
"3d/bbase.sop",
"3d/bbase.mesh",
"3d/bbase.tex",
"3d/bbase.hot",
"3d/bbase.bounds",
"3d/bbase.floor",
NULL,
NULL
};
// These are the points that are checked on the attribute map relative to his origin
static RP3d ms_apt3dAttribCheck[] =
{
{-6, 0, -6},
{ 0, 0, -6},
{ 6, 0, -6},
{-6, 0, 6},
{ 0, 0, 6},
{ 6, 0, 6},
};
////////////////////////////////////////////////////////////////////////////////
// Load object (should call base class version!)
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::Load( // Returns 0 if successfull, non-zero otherwise
RFile* pFile, // In: File to load from
bool bEditMode, // In: True for edit mode, false otherwise
int16_t sFileCount, // In: File count (unique per file, never 0)
uint32_t ulFileVersion) // In: Version of file format to load.
{
int16_t sResult = 0;
// Call the base load function to get ID, position, etc.
sResult = CThing3d::Load(pFile, bEditMode, sFileCount, ulFileVersion);
if (sResult == 0)
{
// Load common data just once per file (not with each object)
if (ms_sFileCount != sFileCount)
{
ms_sFileCount = sFileCount;
// Load static data
switch (ulFileVersion)
{
default:
case 1:
pFile->Read(&ms_dInRange);
break;
}
}
// Load other values
switch (ulFileVersion)
{
default:
case 45:
pFile->Read(&m_u16Color);
case 44:
case 43:
case 42:
case 41:
case 40:
case 39:
case 38:
case 37:
case 36:
case 35:
case 34:
case 33:
case 32:
case 31:
case 30:
case 29:
case 28:
case 27:
case 26:
case 25:
case 24:
case 23:
case 22:
case 21:
case 20:
case 19:
case 18:
case 17:
case 16:
case 15:
case 14:
case 13:
case 12:
case 11:
case 10:
case 9:
case 8:
case 7:
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
pFile->Read(&m_u16FlagID);
break;
}
// Make sure there were no file errors or format errors . . .
if (!pFile->Error() && sResult == 0)
{
// Get resources
sResult = GetResources();
}
else
{
sResult = -1;
TRACE("CFlagbase::Load(): Error reading from file!\n");
}
}
else
{
TRACE("CFlagbase::Load(): CDoofus::Load() failed.\n");
}
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Save object (should call base class version!)
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::Save( // Returns 0 if successfull, non-zero otherwise
RFile* pFile, // In: File to save to
int16_t sFileCount) // In: File count (unique per file, never 0)
{
// Swap the hotspot we want to save in.
int16_t sResult;
// Call the base class save to save the instance ID, position, etc
CThing3d::Save(pFile, sFileCount);
// Save common data just once per file (not with each object)
if (ms_sFileCount != sFileCount)
{
ms_sFileCount = sFileCount;
// Save static data
pFile->Write(&ms_dInRange);
}
// Save additinal stuff here.
pFile->Write(&m_u16Color);
pFile->Write(&m_u16FlagID);
if (!pFile->Error())
{
sResult = SUCCESS;
}
else
{
TRACE("CFlagbase::Save() - Error writing to file\n");
sResult = -1;
}
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Init - Call this after the resources are in place
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::Init(void)
{
int16_t sResult = 0;
// Prepare shadow (get resources and setup sprite).
sResult = PrepareShadow();
// Init other stuff
m_dVel = 0.0;
m_dRot = 0.0;
// Set to different starting state based on the design of the animation, but
// for now, ok. Then also set his current animation.
m_state = CFlagbase::State_Wait;
m_panimCur = &m_animFlagWave;
m_lAnimTime = 0;
m_lTimer = m_pRealm->m_time.GetGameTime() + 500;
m_smash.m_bits = CSmash::FlagBase;
m_smash.m_pThing = this;
m_sBrightness = 0; // Default Brightness level
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Startup object
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::Startup(void) // Returns 0 if successfull, non-zero otherwise
{
int16_t sResult = 0;
// Set the current height, previous time, and Nav Net
CThing3d::Startup();
// Init other stuff
Init();
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Shutdown object
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::Shutdown(void) // Returns 0 if successfull, non-zero otherwise
{
int16_t sResult = 0;
m_trans.Make1();
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Update object
////////////////////////////////////////////////////////////////////////////////
void CFlagbase::Update(void)
{
int16_t sHeight = m_sPrevHeight;
int32_t lThisTime;
int32_t lTimeDifference;
int32_t lSqDistanceToDude = 0;
CSmash* pSmashed = NULL;
if (!m_sSuspend)
{
// Get new time
lThisTime = m_pRealm->m_time.GetGameTime();
lTimeDifference = lThisTime - m_lPrevTime;
// Calculate elapsed time in seconds
double dSeconds = (double)(lThisTime - m_lPrevTime) / 1000.0;
// Check for new messages that may change the state
ProcessMessages();
switch(m_state)
{
case CFlagbase::State_Wait:
if (lThisTime > m_lTimer)
{
m_state = CFlagbase::State_Guard;
}
// Update sphere.
m_smash.m_sphere.sphere.X = m_dX;
m_smash.m_sphere.sphere.Y = m_dY;
m_smash.m_sphere.sphere.Z = m_dZ;
m_smash.m_sphere.sphere.lRadius = 20; //m_spriteBase.m_sRadius;
// Update the smash.
m_pRealm->m_smashatorium.Update(&m_smash);
break;
//-----------------------------------------------------------------------
// Guard - normal operation
//-----------------------------------------------------------------------
case CFlagbase::State_Guard:
m_pRealm->m_smashatorium.QuickCheckReset(&m_smash, CSmash::Flag, 0, 0);
while (m_pRealm->m_smashatorium.QuickCheckNext(&pSmashed))
{
if (pSmashed->m_pThing->GetClassID() == CFlagID)
{
if (((CFlag*) (pSmashed->m_pThing))->m_u16FlagID == m_u16FlagID)
{
m_pRealm->m_sFlagbaseCaptured++;
m_state = State_Dead;
}
}
}
break;
//-----------------------------------------------------------------------
// Blownup - You were blown up so pop up into the air and come down dead
//-----------------------------------------------------------------------
case CFlagbase::State_BlownUp:
// Make her animate
m_lAnimTime += lTimeDifference;
if (!WhileBlownUp())
m_state = State_Dead;
else
{
UpdateFirePosition();
}
break;
//-----------------------------------------------------------------------
// Dead - You are dead, so lay there and decompose, then go away
//-----------------------------------------------------------------------
case CFlagbase::State_Dead:
CHood* phood = m_pRealm->m_phood;
// Render current dead frame into background to stay.
m_pRealm->m_scene.DeadRender3D(
phood->m_pimBackground, // Destination image.
&m_sprite, // Tree of 3D sprites to render.
phood); // Dst clip rect.
delete this;
return;
break;
}
// Update sphere.
m_smash.m_sphere.sphere.X = m_dX;
m_smash.m_sphere.sphere.Y = m_dY;
m_smash.m_sphere.sphere.Z = m_dZ;
m_smash.m_sphere.sphere.lRadius = 20; //m_spriteBase.m_sRadius;
// Update the smash.
m_pRealm->m_smashatorium.Update(&m_smash);
// Save time for next time
m_lPrevTime = lThisTime;
m_lAnimPrevUpdateTime = m_lAnimTime;
}
}
////////////////////////////////////////////////////////////////////////////////
// Called by editor to init new object at specified position
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::EditNew( // Returns 0 if successfull, non-zero otherwise
int16_t sX, // In: New x coord
int16_t sY, // In: New y coord
int16_t sZ) // In: New z coord
{
int16_t sResult = 0;
sResult = CThing3d::EditNew(sX, sY, sZ);
if (sResult == SUCCESS)
{
// Load resources
sResult = GetResources();
if (sResult == SUCCESS)
{
sResult = Init();
}
}
else
{
sResult = -1;
}
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Edit Move
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::EditMove(int16_t sX, int16_t sY, int16_t sZ)
{
int16_t sResult = CThing3d::EditMove(sX, sY, sZ);
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Give Edit a rectangle around this object
////////////////////////////////////////////////////////////////////////////////
void CFlagbase::EditRect(RRect* pRect)
{
// Call base class.
CThing3d::EditRect(pRect);
}
////////////////////////////////////////////////////////////////////////////////
// Called by editor to get the hotspot of an object in 2D.
// (virtual (Overridden here)).
////////////////////////////////////////////////////////////////////////////////
void CFlagbase::EditHotSpot( // Returns nothiing.
int16_t* psX, // Out: X coord of 2D hotspot relative to
// EditRect() pos.
int16_t* psY) // Out: Y coord of 2D hotspot relative to
// EditRect() pos.
{
// Get rectangle.
RRect rc;
EditRect(&rc);
// Get 2D hotspot.
int16_t sX;
int16_t sY;
Map3Dto2D(
m_dX,
m_dY,
m_dZ,
&sX,
&sY);
// Get relation.
*psX = sX - rc.sX;
*psY = sY - rc.sY;
}
////////////////////////////////////////////////////////////////////////////////
// Called by editor to modify object
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::EditModify(void)
{
int16_t sResult = 0;
U16 u16OrigColor = m_u16Color;
RGuiItem* pGuiItem = NULL;
RGuiItem* pguiRoot = RGuiItem::LoadInstantiate(FullPathVD("res/editor/flagbase.gui"));
if (pguiRoot != NULL)
{
REdit* peditFlagID = (REdit*) pguiRoot->GetItemFromId(GUI_FLAGID_EDIT_ID);
REdit* peditColor = (REdit*) pguiRoot->GetItemFromId(GUI_COLOR_EDIT_ID);
if (peditFlagID != NULL && peditColor != NULL)
{
ASSERT(peditFlagID->m_type == RGuiItem::Edit);
ASSERT(peditColor->m_type == RGuiItem::Edit);
peditFlagID->SetText("%d", m_u16FlagID);
peditFlagID->Compose();
peditColor->SetText("%d", m_u16Color);
peditColor->Compose();
sResult = DoGui(pguiRoot);
if (sResult == 1)
{
m_u16FlagID = peditFlagID->GetVal();
m_u16Color = MIN((int32_t) (CFlag::EndOfColors - 1), peditColor->GetVal());
}
}
}
delete pguiRoot;
// If the user switched colors, get the new resources
if (m_u16Color != u16OrigColor)
{
FreeResources();
GetResources();
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Get all required resources
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::GetResources(void) // Returns 0 if successfull, non-zero otherwise
{
int16_t sResult = 0;
switch (m_u16Color)
{
default:
case CFlag::Red:
sResult = m_animFlagWave.Get(ms_apszRedResNames, RChannel_LoopAtStart | RChannel_LoopAtEnd);
break;
case CFlag::Blue:
sResult = m_animFlagWave.Get(ms_apszBlueResNames, RChannel_LoopAtStart | RChannel_LoopAtEnd);
break;
}
if (sResult == 0)
{
// Add new animation loads here
}
else
{
TRACE("CFlagbase::GetResources - Failed to open 3D flag waving animation\n");
}
return sResult;
}
////////////////////////////////////////////////////////////////////////////////
// Free all resources
////////////////////////////////////////////////////////////////////////////////
int16_t CFlagbase::FreeResources(void) // Returns 0 if successfull, non-zero otherwise
{
m_animFlagWave.Release();
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// Message handlers
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Shot Message
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Explosion message
////////////////////////////////////////////////////////////////////////////////
void CFlagbase::OnExplosionMsg(Explosion_Message* pMessage)
{
if (
m_state != State_BlownUp &&
m_state != State_Die &&
m_state != State_Dead)
{
// CCharacter::OnExplosionMsg(pMessage);
// PlaySample(g_smidBlownupFemaleYell);
// m_ePreviousState = m_state;
m_state = State_BlownUp;
// m_panimPrev = m_panimCur;
// m_panimCur = &m_animDie;
m_lAnimTime = 0;
// m_stockpile.m_sHitPoints = 0;
m_lTimer = m_pRealm->m_time.GetGameTime();
m_dExtHorzVel *= 1.4; //2.5;
m_dExtVertVel *= 1.1; //1.4;
// Send it spinning.
m_dExtRotVelY = GetRandom() % 720;
m_dExtRotVelZ = GetRandom() % 720;
// m_panimCur = &m_animDie;
}
}
////////////////////////////////////////////////////////////////////////////////
// Burning message
////////////////////////////////////////////////////////////////////////////////
void CFlagbase::OnBurnMsg(Burn_Message* pMessage)
{
// For now we made the sentry fireproof, the only
// way it can be destroyed is by blowing it up.
}
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////
|