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 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
|
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team
This file is part of OpenMoHAA source code.
OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
// specialfx.cpp: Special fx
//
#include "g_local.h"
#include "g_phys.h"
#include "g_spawn.h"
#include "specialfx.h"
#include "level.h"
/*****************************************************************************/
/*QUAKED func_fulcrum (0 0 1) ? X_AXIS_ONLY Y_AXIS_ONLY
This creates a fulcrum that when you stand on it, it will rotate due to
the weight exerted it will start rotating, when not standing on it, it
will return to its rest position.
"speed" - set the speed at which the fulcrum will operate (default is 48)
"resetspeed" - speed at whcih fulcrum resets, (default speed * 0.002)
"dampening" - dampen constant (default 0.95)
"limit" - limit the movement of the fulcrum (default 90 degrees)
"movesound" - sound to be played while fulcrum is moving
X_AXIS_ONLY - only adjust the X axis
Y_AXIS_ONLY - only adjust the Y axis
******************************************************************************/
#define X_AXIS_ONLY (1 << 0)
#define Y_AXIS_ONLY (1 << 1)
Event EV_Fulcrum_SetSpeed
(
"speed",
EV_DEFAULT,
"f",
"speed",
"Speed at which fulcrum operates itself.",
EV_NORMAL
);
Event EV_Fulcrum_Reset
(
"reset",
EV_CONSOLE,
NULL,
NULL,
"Reset the fulcrum right now.",
EV_NORMAL
);
Event EV_Fulcrum_AdjustFulcrum
(
"_adjust_fulcrum",
EV_CODEONLY,
NULL,
NULL,
"Called periodically to adjust the frustum every frame and update its angular velocity.",
EV_NORMAL
);
Event EV_Fulcrum_SetResetSpeed
(
"resetspeed",
EV_DEFAULT,
"f",
"newResetspeed",
"Speed at which fulcrum resets itself, defaults to 0.002 * speed.",
EV_NORMAL
);
Event EV_Fulcrum_SetDampening
(
"dampening",
EV_DEFAULT,
"f",
"newDampening",
"dampening of fulcrum.",
EV_NORMAL
);
Event EV_Fulcrum_SetLimit
(
"limit",
EV_DEFAULT,
"f",
"newLimit",
"angular limit for the fulcrum.",
EV_NORMAL
);
Event EV_Fulcrum_Setup
(
"_setup",
EV_DEFAULT,
NULL,
NULL,
"setup the fulcrum for the first time.",
EV_NORMAL
);
Event EV_Fulcrum_SetMoveSound
(
"movesound",
EV_DEFAULT,
"s",
"newSinkSound",
"Sound played when fulcrum is moving.",
EV_NORMAL
);
CLASS_DECLARATION(ScriptSlave, Fulcrum, "func_fulcrum") {
{&EV_Fulcrum_SetSpeed, &Fulcrum::SetSpeed },
{&EV_Fulcrum_Reset, &Fulcrum::Reset },
{&EV_Fulcrum_AdjustFulcrum, &Fulcrum::Adjust },
{&EV_Touch, &Fulcrum::Touched },
{&EV_Fulcrum_SetResetSpeed, &Fulcrum::SetResetSpeed},
{&EV_Fulcrum_SetDampening, &Fulcrum::SetDampening },
{&EV_Fulcrum_SetLimit, &Fulcrum::SetLimit },
{&EV_Fulcrum_Setup, &Fulcrum::Setup },
{&EV_Fulcrum_SetMoveSound, &Fulcrum::SetMoveSound },
{NULL, NULL }
};
Fulcrum::Fulcrum()
{
if (LoadingSavegame) {
// Archive function will setup all necessary data
return;
}
touched = qfalse;
speed = 48;
resetspeed = speed * 0.002;
dampening = 0.95f;
limit = 90;
setMoveType(MOVETYPE_PUSH);
PostEvent(EV_Fulcrum_Setup, FRAMETIME);
}
void Fulcrum::Setup(Event *ev)
{
startangles = angles;
}
void Fulcrum::SetSpeed(Event *ev)
{
speed = ev->GetFloat(1);
resetspeed = speed * 0.002;
}
void Fulcrum::SetResetSpeed(Event *ev)
{
resetspeed = ev->GetFloat(1);
}
void Fulcrum::SetDampening(Event *ev)
{
dampening = ev->GetFloat(1);
}
void Fulcrum::SetLimit(Event *ev)
{
limit = ev->GetFloat(1);
}
void Fulcrum::SetMoveSound(Event *ev)
{
movesound = ev->GetString(1);
}
void Fulcrum::Reset(Event *ev)
{
StopLoopSound();
touched = qfalse;
avelocity = vec_zero;
setAngles(startangles);
CancelEventsOfType(EV_Fulcrum_AdjustFulcrum);
}
void Fulcrum::Touched(Event *ev)
{
Vector diff;
vec3_t dest;
Vector delta;
Entity *other;
other = ev->GetEntity(1);
assert(other);
if (!other) {
return;
}
//
// only things resting on me will affect me
//
if (other->groundentity != this->edict) {
return;
}
if (movesound.length()) {
LoopSound(movesound);
}
delta = getLocalVector(other->origin - origin);
//
// clear out angular velocity
//
avelocity = vec_zero;
// only look at x and y since z doesn't really concern us.
if (!(spawnflags & X_AXIS_ONLY)) {
avelocity[PITCH] += cos(DEG2RAD(startangles[YAW])) * speed * delta[0] / maxs[0];
avelocity[ROLL] += sin(DEG2RAD(startangles[YAW])) * speed * delta[0] / maxs[0];
}
if (!(spawnflags & Y_AXIS_ONLY)) {
avelocity[ROLL] += cos(DEG2RAD(startangles[YAW])) * -speed * delta[1] / maxs[1];
avelocity[PITCH] += sin(DEG2RAD(startangles[YAW])) * -speed * delta[1] / maxs[1];
}
AnglesSubtract(startangles, angles, dest);
diff = Vector(dest);
if (fabs(diff[PITCH]) >= limit) {
Vector newAngles;
StopLoopSound();
if (diff[PITCH] > 0) {
if (avelocity[PITCH] < 0) {
avelocity[PITCH] = 0;
}
} else if (diff[PITCH] < 0) {
if (avelocity[PITCH] > 0) {
avelocity[PITCH] = 0;
}
}
}
if (fabs(diff[ROLL]) >= limit) {
StopLoopSound();
if (diff[ROLL] > 0) {
if (avelocity[ROLL] < 0) {
avelocity[ROLL] = 0;
}
} else if (diff[ROLL] < 0) {
if (avelocity[ROLL] > 0) {
avelocity[ROLL] = 0;
}
}
}
touched = qtrue;
CancelEventsOfType(EV_Fulcrum_AdjustFulcrum);
PostEvent(EV_Fulcrum_AdjustFulcrum, 0);
}
void Fulcrum::Adjust(Event *ev)
{
if (!touched) {
int i;
float f;
Vector diff;
vec3_t dest;
qboolean post;
if (movesound.length()) {
LoopSound(movesound);
}
AnglesSubtract(startangles, angles, dest);
diff = Vector(dest);
post = qfalse;
for (i = 0; i < 3; i++) {
if (diff[i]) {
avelocity[i] += resetspeed * diff[i];
}
avelocity[i] *= dampening;
f = fabs(avelocity[i]);
if (f > 0.01f) {
post = qtrue;
}
}
if (!post) {
Reset(NULL);
return;
}
} else {
touched = qfalse;
}
PostEvent(EV_Fulcrum_AdjustFulcrum, FRAMETIME);
}
/*****************************************************************************/
/*QUAKED func_runthrough (0 0 1) ?
This is a trigger field that the player can run through and spawn tiki models
at that position. Used for releasing chaff from grass or butterflys from
flower gardens
"speed" - speed at which you have to be moving to trigger ( default 100 )
"delay" - time between triggering ( default 0.1 )
"chance" - chance that the trigger will spawn something( default 0.5 )
"lip" - how far below the surface of the trigger we should spawn these things ( default 3 )
"offset" - vector offset oriented along velocity vector( default "0 0 0" )
"spawnmodel" - thing to spawn when triggered
******************************************************************************/
Event EV_RunThrough_SetSpeed
(
"speed",
EV_DEFAULT,
"f",
"speed",
"threshold speed at which RunThrough is activated.",
EV_NORMAL
);
Event EV_RunThrough_SetDelay
(
"delay",
EV_DEFAULT,
"f",
"delay",
"time between RunThrough being activated.",
EV_NORMAL
);
Event EV_RunThrough_SetChance
(
"chance",
EV_DEFAULT,
"f",
"chance",
"chance that trigger will spawn something.",
EV_NORMAL
);
Event EV_RunThrough_SetLip
(
"lip",
EV_DEFAULT,
"f",
"lip",
"distance below trigger we should spawn things.",
EV_NORMAL
);
Event EV_RunThrough_SetSpawnModel
(
"spawnmodel",
EV_DEFAULT,
"s",
"model_to_spawn",
"When triggered, what to spawn.",
EV_NORMAL
);
Event EV_RunThrough_SetOffset
(
"offset",
EV_DEFAULT,
"v",
"spawn_offset",
"When triggered, what to offset the spawned object by.",
EV_NORMAL
);
CLASS_DECLARATION(Entity, RunThrough, "func_runthrough") {
{&EV_RunThrough_SetSpeed, &RunThrough::SetSpeed },
{&EV_RunThrough_SetDelay, &RunThrough::SetDelay },
{&EV_RunThrough_SetChance, &RunThrough::SetChance },
{&EV_RunThrough_SetLip, &RunThrough::SetLip },
{&EV_RunThrough_SetSpawnModel, &RunThrough::SetSpawnModel},
{&EV_RunThrough_SetOffset, &RunThrough::SetOffset },
{&EV_Touch, &RunThrough::Touched },
{NULL, NULL }
};
RunThrough::RunThrough()
{
if (LoadingSavegame) {
// Archive function will setup all necessary data
return;
}
offset = vec_zero;
speed = 100.0f;
chance = 0.5f;
delay = 0.1f;
lip = 3.0f;
spawnmodel = "";
lasttriggertime = 0;
setMoveType(MOVETYPE_NONE);
setSolidType(SOLID_TRIGGER);
}
void RunThrough::SetSpeed(Event *ev)
{
speed = ev->GetFloat(1);
}
void RunThrough::SetChance(Event *ev)
{
chance = ev->GetFloat(1);
}
void RunThrough::SetDelay(Event *ev)
{
delay = ev->GetFloat(1);
}
void RunThrough::SetLip(Event *ev)
{
lip = ev->GetFloat(1);
}
void RunThrough::SetOffset(Event *ev)
{
offset = ev->GetVector(1);
}
void RunThrough::SetSpawnModel(Event *ev)
{
spawnmodel = ev->GetString(1);
CacheResource(spawnmodel);
}
void RunThrough::Touched(Event *ev)
{
Vector forward, left, up;
Vector ang;
Vector org;
Entity *other;
other = ev->GetEntity(1);
assert(other);
if (!other) {
return;
}
// don't trigger on the world
if (other == world) {
return;
}
// don't re-trigger too soon
if (level.time < lasttriggertime) {
return;
}
// don't trigger if not moving fast enough
if (other->velocity.length() < speed) {
return;
}
// don't trigger if chance says not to.
if (G_Random(1) > chance) {
return;
}
ang = other->velocity.toAngles();
ang.AngleVectors(&forward, &left, &up);
// get the origin from the thing that triggered me
org = other->origin;
// set the height of the origin based on the bounds of this trigger minus the lip
org.z = absmax.z - lip;
org += offset.x * forward;
org += offset.y * left;
org += offset.z * up;
if (spawnmodel.length()) {
Entity *ent;
// purposely declared here so that we don't do it every frame
SpawnArgs args;
args.setArg("origin", va("%f %f %f", org[0], org[1], org[2]));
args.setArg("angles", va("%f %f %f", ang[0], ang[1], ang[2]));
args.setArg("model", spawnmodel.c_str());
ent = (Entity *)args.Spawn();
if (ent) {
ent->ProcessPendingEvents();
}
}
// set trigger time for next time
lasttriggertime = level.time + delay;
}
/*****************************************************************************/
/*QUAKED func_sinkobject (0 0 1) ? x FALLAWAY NO_RESET
This creates an object which gradually sinks downward when stepped on.
"delay" - delay between when object starts reacting towards weight (default 0 seconds)
"speed" - set the speed at which sinkobject sinks (default is 50)
"resetspeed" - speed at which sinkobject resets its position, (default speed * 0.1)
"dampening" - dampening constant to mitigate acceleration (default 0.95)
"limit" - limit the movement of the sinkobject how far down it should go (default 1000 units)
"resetdelay" - time between player gets off platform, and platform starts resetting itself.
"sinksound" - sound to be played while platform is sinking.
"resetsound" - sound to be played while platform is resetting.
"active" - make the sink object active
"notactive" - make the sink object not active
FALLAWAY - the sink object will progressively fall down faster and faster
NO_RESET - the sink object will not reset, only move downward
******************************************************************************/
#define FALLAWAY (1 << 1)
#define NO_RESET (1 << 2)
Event EV_SinkObject_SetSpeed
(
"speed",
EV_DEFAULT,
"f",
"speed",
"Speed at which SinkObject starts falling.",
EV_NORMAL
);
Event EV_SinkObject_SetDelay
(
"delay",
EV_DEFAULT,
"f",
"delay",
"Delay until SinkObject starts falling.",
EV_NORMAL
);
Event EV_SinkObject_Reset
(
"reset",
EV_CONSOLE,
NULL,
NULL,
"Reset the SinkObject right now.",
EV_NORMAL
);
Event EV_SinkObject_AdjustSinkObject
(
"_adjust_SinkObject",
EV_CODEONLY,
NULL,
NULL,
"Called periodically to adjust the sinkobject every frame and adjust its velocity.",
EV_NORMAL
);
Event EV_SinkObject_Fall
(
"_fall_SinkObject",
EV_CODEONLY,
NULL,
NULL,
"Called periodically to make a sink object fall away.",
EV_NORMAL
);
Event EV_SinkObject_SetResetSpeed
(
"resetspeed",
EV_DEFAULT,
"f",
"newResetspeed",
"Speed at which SinkObject resets itself, defaults to 0.002 * speed.",
EV_NORMAL
);
Event EV_SinkObject_SetResetDelay
(
"resetdelay",
EV_DEFAULT,
"f",
"newResetDelay",
"Delay between when sinkobject starts resetting.",
EV_NORMAL
);
Event EV_SinkObject_SetSinkSound
(
"sinksound",
EV_DEFAULT,
"s",
"newSinkSound",
"Sound played when sinkobject is sinking.",
EV_NORMAL
);
Event EV_SinkObject_SetResetSound
(
"resetsound",
EV_DEFAULT,
"s",
"newResetSound",
"Sound played when sinkobject is resetting.",
EV_NORMAL
);
Event EV_SinkObject_SetDampening
(
"dampening",
EV_DEFAULT,
"f",
"newDampening",
"dampening of SinkObject.",
EV_NORMAL
);
Event EV_SinkObject_SetLimit
(
"limit",
EV_DEFAULT,
"f",
"newLimit",
"maximum displacement of the SinkObject.",
EV_NORMAL
);
Event EV_SinkObject_Setup
(
"_setup",
EV_DEFAULT,
NULL,
NULL,
"setup the SinkObject for the first time.",
EV_NORMAL
);
Event EV_SinkObject_MakeActive
(
"active",
EV_DEFAULT,
NULL,
NULL,
"make the SinkObject active, so that it will respond to players touching it.",
EV_NORMAL
);
Event EV_SinkObject_MakeNonActive
(
"notactive",
EV_DEFAULT,
NULL,
NULL,
"make the SinkObject not active, so that it won't respond to players touching it.",
EV_NORMAL
);
CLASS_DECLARATION(ScriptSlave, SinkObject, "func_sinkobject") {
{&EV_SinkObject_SetSpeed, &SinkObject::SetSpeed },
{&EV_SinkObject_SetDelay, &SinkObject::SetDelay },
{&EV_SinkObject_Reset, &SinkObject::Reset },
{&EV_SinkObject_AdjustSinkObject, &SinkObject::Adjust },
{&EV_SinkObject_Fall, &SinkObject::Fall },
{&EV_Touch, &SinkObject::Touched },
{&EV_SinkObject_SetResetSpeed, &SinkObject::SetResetSpeed},
{&EV_SinkObject_SetDampening, &SinkObject::SetDampening },
{&EV_SinkObject_SetLimit, &SinkObject::SetLimit },
{&EV_SinkObject_Setup, &SinkObject::Setup },
{&EV_SinkObject_SetResetDelay, &SinkObject::SetResetDelay},
{&EV_SinkObject_SetResetSound, &SinkObject::SetResetSound},
{&EV_SinkObject_SetSinkSound, &SinkObject::SetSinkSound },
{&EV_SinkObject_MakeActive, &SinkObject::MakeActive },
{&EV_SinkObject_MakeNonActive, &SinkObject::MakeNonActive},
{NULL, NULL }
};
#define RESET_SCALE 0.1f
#define SPEED_DIVISOR (1.0f / 250.0f)
SinkObject::SinkObject()
{
if (LoadingSavegame) {
// Archive function will setup all necessary data
return;
}
active = qtrue;
sinksound = "";
resetsound = "";
resetdelay = 0;
delay = 0;
touched = qfalse;
speed = 50 * SPEED_DIVISOR;
resetspeed = speed * RESET_SCALE;
dampening = 0.95f;
limit = 1000;
time_touched = -1;
time_reset = -1;
setMoveType(MOVETYPE_PUSH);
PostEvent(EV_SinkObject_Setup, FRAMETIME);
}
void SinkObject::Setup(Event *ev)
{
startpos = origin;
}
void SinkObject::SetSpeed(Event *ev)
{
speed = ev->GetFloat(1) * SPEED_DIVISOR;
resetspeed = speed * RESET_SCALE;
}
void SinkObject::SetDelay(Event *ev)
{
delay = ev->GetFloat(1);
}
void SinkObject::SetResetSpeed(Event *ev)
{
resetspeed = ev->GetFloat(1) * SPEED_DIVISOR;
}
void SinkObject::SetResetDelay(Event *ev)
{
resetdelay = ev->GetFloat(1);
}
void SinkObject::SetSinkSound(Event *ev)
{
sinksound = ev->GetString(1);
}
void SinkObject::SetResetSound(Event *ev)
{
resetsound = ev->GetString(1);
}
void SinkObject::SetDampening(Event *ev)
{
dampening = ev->GetFloat(1);
}
void SinkObject::SetLimit(Event *ev)
{
limit = ev->GetFloat(1);
}
void SinkObject::Reset(Event *ev)
{
time_reset = -1;
time_touched = -1;
touched = qfalse;
velocity = vec_zero;
setOrigin(startpos);
CancelEventsOfType(EV_SinkObject_AdjustSinkObject);
StopLoopSound();
}
void SinkObject::Touched(Event *ev)
{
Entity *other;
// if we aren't active, don't let anyone touch us
if (!active) {
return;
}
other = ev->GetEntity(1);
assert(other);
if (!other) {
return;
}
//
// only things resting on me will affect me
//
if (other->groundentity != this->edict) {
return;
}
if (delay) {
if (time_touched == -1) {
time_touched = level.time + delay;
}
//
// not time yet
//
if (level.time < time_touched) {
return;
}
}
if (sinksound.length()) {
LoopSound(sinksound);
}
velocity.z -= speed;
if (origin.z < (startpos.z - limit)) {
origin.z = startpos.z - limit;
setOrigin(origin);
velocity = vec_zero;
}
touched = qtrue;
if (spawnflags & FALLAWAY) {
CancelEventsOfType(EV_SinkObject_Fall);
PostEvent(EV_SinkObject_Fall, FRAMETIME);
return;
}
CancelEventsOfType(EV_SinkObject_AdjustSinkObject);
PostEvent(EV_SinkObject_AdjustSinkObject, FRAMETIME);
}
void SinkObject::Fall(Event *ev)
{
velocity.z -= speed;
if (origin.z < (startpos.z - limit)) {
origin.z = startpos.z - limit;
setOrigin(origin);
velocity = vec_zero;
StopLoopSound();
} else {
CancelEventsOfType(EV_SinkObject_Fall);
PostEvent(EV_SinkObject_Fall, FRAMETIME);
}
}
void SinkObject::Adjust(Event *ev)
{
if (!touched) {
float diff;
if (spawnflags & NO_RESET) {
StopLoopSound();
time_touched = -1;
velocity.z = 0;
return;
} else {
if (resetdelay) {
// stop the object
velocity.z = 0;
// kill its sound
StopLoopSound();
if (time_reset == -1) {
time_reset = level.time + resetdelay;
}
//
// not time yet
//
if (level.time < time_reset) {
PostEvent(EV_SinkObject_AdjustSinkObject, FRAMETIME);
return;
}
}
if (resetsound.length()) {
LoopSound(resetsound);
}
diff = startpos.z - origin.z;
velocity.z += resetspeed * diff;
velocity.z *= dampening;
if ((fabs(diff) < 0.5f) && (fabs(velocity.z) < 1)) {
Reset(NULL);
return;
}
}
} else {
touched = qfalse;
}
PostEvent(EV_SinkObject_AdjustSinkObject, FRAMETIME);
}
void SinkObject::MakeActive(Event *ev)
{
active = qtrue;
}
void SinkObject::MakeNonActive(Event *ev)
{
active = qfalse;
}
|