1 /* 2 Copyright (C) 2007, 2010 - Bit-Blot 3 4 This file is part of Aquaria. 5 6 Aquaria is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 2 9 of the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 15 See the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 #ifndef AVATAR_H 22 #define AVATAR_H 23 24 #include "../BBGE/Particles.h" 25 26 #include "DSQ.h" 27 #include "Hair.h" 28 #include "Entity.h" 29 30 #include "Web.h" 31 32 class TileVector; 33 class SongIcon; 34 35 struct Target 36 { 37 public: TargetTarget38 Target() { e = 0; targetPt = -1; } 39 Entity *e; 40 Vector pos; 41 int targetPt; 42 Vector getWorldPosition(); 43 }; 44 45 enum BurstType 46 { 47 BURST_NONE = 0, 48 BURST_NORMAL = 1, 49 BURST_WALL = 2 50 }; 51 52 enum EnableInputType 53 { 54 AVATARINPUT_DEFAULT = 0, 55 AVATARINPUT_NOCURSOR = 1, 56 AVATARINPUT_MAX 57 }; 58 59 enum AvatarAnimLayers 60 { 61 ANIMLAYER_FLOURISH = 3, 62 ANIMLAYER_OVERRIDE = 4, 63 ANIMLAYER_ARMOVERRIDE = 5, 64 ANIMLAYER_UPPERBODYIDLE = 6, 65 ANIMLAYER_HEADOVERRIDE = 7, 66 ANIMLAYER_MAX 67 }; 68 69 enum SeeMapMode 70 { 71 SEE_MAP_NEVER = 0, 72 SEE_MAP_DEFAULT = 1, 73 SEE_MAP_ALWAYS = 2, 74 }; 75 76 class SongIconParticle : public Quad 77 { 78 public: 79 SongIconParticle(Vector color, Vector pos, int note); 80 int note; 81 SongIcon *toIcon; 82 protected: 83 void onUpdate(float dt); 84 }; 85 86 class SongIcon : public Quad 87 { 88 public: 89 SongIcon(int note); 90 void destroy(); 91 int note; 92 void openNote(); 93 void closeNote(); 94 void openInterface(); 95 void closeInterface(); 96 static int notesOpen; 97 Vector noteColor; 98 bool open; 99 100 protected: 101 Quad *glow; 102 float rippleTimer; 103 float len; 104 float ptimer; 105 void spawnParticles(float dt); 106 void *channel; 107 float delay, counter, minTime; 108 bool cursorIsIn; 109 void onUpdate(float dt); 110 }; 111 112 class AvatarState 113 { 114 public: 115 AvatarState(); 116 Timer blindTimer; 117 float abilityDelay; 118 bool blind; 119 bool wasUnderWater; 120 float shotDelay; 121 //Timer shockTimer; 122 Timer useItemDelay; 123 Timer lockToWallDelay; 124 float spellCharge; 125 bool lockedToWall; 126 float leachTimer; 127 bool nearWall; 128 float swimTimer, rollTimer; 129 float updateLookAtTime; 130 float blinkTimer; 131 Entity *lookAtEntity; 132 Vector outOfWaterVel; 133 float outOfWaterTimer; 134 bool backFlip; 135 }; 136 137 class Avatar : public Entity, public ActionMapper 138 { 139 public: 140 Avatar(); 141 void postInit(); 142 virtual ~Avatar(); 143 void destroy(); 144 void action(int actionID, int state); 145 AvatarState state; 146 float burst, burstTimer; 147 float burstDelay; 148 bool bursting; 149 BurstType lastBurstType; 150 //void damage(int amount); 151 bool isCharging(); 152 void setBlind(float time); 153 154 void revive(); 155 156 bool canWarp; 157 void entityDied(Entity *e); 158 void onCollide(Entity *e); 159 bool zoomOverriden; 160 void clampPosition(); 161 162 void splash(bool down); 163 InterpolatedVector myZoom; 164 165 Entity *entityToActivate; 166 Path *pathToActivate; 167 168 void applyWorldEffects(WorldType type); 169 170 void toggleMovement(bool on); 171 172 Vector getFacing(); 173 174 void refreshModel(std::string file, const std::string &skin, bool forceIdle=false); 175 void refreshDualFormModel(); 176 void switchDualFormMode(); 177 178 void enableInput(); 179 void disableInput(); 180 void clearTargets(); 181 bool singing; 182 183 void doBounce(); 184 Vector getKeyDir(); 185 186 void startBurstCommon(); 187 void updateJoystick(float dt); 188 189 int getNotesOpen(); 190 int getLastNote(); 191 192 int lastNote; 193 194 void openSingingInterface(); 195 void closeSingingInterface(); 196 void updateSingingInterface(float dt); 197 198 void playHitSound(); 199 200 void changeForm(FormType form, bool effects=true, bool onInit=false, FormType lastForm=FORM_NONE); 201 void singNote(int note); 202 std::vector<SongIcon*> songIcons; 203 Song currentSong; 204 int currentSongIdx; 205 206 Entity *pullTarget; 207 208 void setNearestPullTarget(); 209 210 void formAbility(int ability); 211 bool isMouseInputEnabled(); 212 213 void startCharge(int ability); 214 int currentMaxSpeed; 215 Vector getFakeCursorPosition(); 216 Vector getVectorToCursor(bool trueMouse=false); 217 Vector getVectorToCursorFromScreenCentre(); 218 219 bool canDie; 220 221 Vector warpInLocal; 222 223 float biteDelay, urchinDelay, jellyDelay; 224 bool movingOn; 225 226 void render(); 227 void activateAura(AuraType aura); 228 void stopAura(); 229 void setHeadTexture(const std::string &name, float t=0); 230 float headTextureTimer; 231 void updateDamageVisualEffects(); 232 int chargeLevelAttained; 233 void chargeVisualEffect(const std::string &tex); 234 void updateFormVisualEffects(float dt); 235 bool isSinging(); 236 bool isLockable(); 237 int getCursorQuadrant(); 238 void onWarp(); 239 int getBurstDistance(); 240 int getStopDistance(); 241 int looking; 242 std::string getIdleAnimName(); isRolling()243 bool isRolling() { return rolling; } 244 int rollDir; 245 std::string getBurstAnimName(); 246 std::string getRollAnimName(); 247 248 void updateDualFormChargeEffects(); 249 250 TileVector wallLockTile; 251 Vector wallNormal; 252 253 void fallOffWall(); 254 255 float fireDelay; 256 int getSingingInterfaceRadius(); 257 int getOpenSingingInterfaceRadius(); 258 AuraType activeAura; 259 float auraTimer; 260 bool fireAtNearestValidEntity(const std::string &shot); 261 262 void checkNearWall(); 263 Vector getAim(); 264 Vector getForwardAim(); 265 void setWasUnderWater(); 266 Quad *lightFormGlow, *lightFormGlowCone; 267 void setBlockSinging(bool v); 268 Vector headPosition; 269 void updatePosition(); 270 float quickSongCastDelay; 271 void onAnimationKeyPassed(int key); 272 273 bool isSwimming(); 274 isBlockSinging()275 bool isBlockSinging() { return blockSinging; } 276 277 float songInterfaceTimer; 278 void removeEatData(int idx); 279 //std::list<Entity*>bittenEntities; 280 typedef std::list<Entity*> BittenEntities; 281 BittenEntities bittenEntities; 282 void updateHeartbeatSfx(float t = 0); 283 Target getNearestTarget(const Vector &checkPos, const Vector &distPos, Entity *source, DamageType dt, bool override=false, std::vector<Target> *ignore=0, EntityList *entityList=0); 284 285 void toggleCape(bool on); 286 void updateLookAt(float dt); 287 void updateFoodParticleEffects(); 288 void endOfGameState(); 289 bool canQuickSong(); 290 bool canActivateStuff(); 291 void setCanActivateStuff(bool on); 292 bool hasThingToActivate(); 293 294 float biteTimer; 295 Timer flourishTimer; 296 Timer flourishPowerTimer; 297 Timer stillTimer; 298 299 void refreshNormalForm(); 300 bool canChangeForm; 301 302 void bindInput(); 303 304 Vector getHeadPosition(); 305 306 Bone *boneRightFoot, *boneLeftFoot, *boneRightArm, *boneLeftArm, *boneFish2, *bone_head; 307 Bone *boneLeftHand, *boneRightHand; 308 309 void startFlourish(); 310 void applyTripEffects(); 311 void removeTripEffects(); 312 313 void stopBurst(); 314 315 void createWeb(); 316 void clearWeb(); 317 Web *web; 318 float rollDelay; 319 320 void loseTargets(); 321 322 bool canSetBoneLock(); 323 324 void revert(); 325 void doBindSong(); 326 void doShieldSong(); 327 canBurst()328 bool canBurst() const { return _canBurst; } setCanBurst(bool b)329 void setCanBurst(bool b) { _canBurst = b; } 330 canLockToWall()331 bool canLockToWall() const { return _canLockToWall; } setCanLockToWall(bool b)332 void setCanLockToWall(bool b) { _canLockToWall = b; } 333 canSwimAgainstCurrents()334 bool canSwimAgainstCurrents() const { return _canSwimAgainstCurrents; } setCanSwimAgainstCurrents(bool b)335 void setCanSwimAgainstCurrents(bool b) { _canSwimAgainstCurrents = b; } 336 canCollideWithShots()337 bool canCollideWithShots() const { return _canCollideWithShots; } setCollideWithShots(bool b)338 void setCollideWithShots(bool b) { _canCollideWithShots = b; } 339 340 void setCollisionAvoidanceData(int range, float mod); 341 setSeeMapMode(SeeMapMode mode)342 void setSeeMapMode(SeeMapMode mode) { _seeMapMode = mode; } getSeeMapMode()343 SeeMapMode getSeeMapMode() const { return _seeMapMode; } 344 345 int leaches; 346 float shieldPoints; 347 float elementEffectMult; 348 349 bool blockBackFlip; 350 351 protected: 352 void setSongIconPositions(); 353 354 Timer webBitTimer; 355 int curWebPoint; 356 void checkUpgradeForShot(Shot *s); 357 int getNumShots(); 358 void lockToWallCommon(); 359 void onSetBoneLock(); 360 void onUpdateBoneLock(); 361 362 void adjustHeadRot(); 363 std::string lastHeadTexture; 364 void updateDualFormGlow(float dt); 365 Vector getTendrilAimVector(int i, int max); 366 void applyRidingPosition(); 367 void stopWallJump(); 368 void updateWallJump(float dt); 369 float wallBurstTimer; 370 float targetUpdateDelay; 371 std::vector<Target> targets; 372 void updateTargets(float dt, bool override); 373 void updateTargetQuads(float dt); 374 Vector bodyOffset; 375 bool flourish; 376 bool blockSinging; 377 int spiritEnergyAbsorbed; 378 float formAbilityDelay; 379 Vector bodyPosition; 380 381 382 bool joystickMove; 383 bool ripples; 384 float rippleDelay, tripDelay; 385 float formTimer; 386 float fallGravityTimer; 387 Vector fallGravity; 388 int lastOutOfWaterMaxSpeed; 389 390 void onIdle(); 391 void onHeal(int type); 392 ParticleEffect biteLeftEmitter, biteRightEmitter, swimEmitter, auraHitEmitter; 393 ParticleEffect auraEmitter, auraLowEmitter, wakeEmitter, healEmitter, hitEmitter, rollLeftEmitter, rollRightEmitter, spiritBeaconEmitter, plungeEmitter; 394 ParticleEffect speedEmitter, defenseEmitter, invincibleEmitter, regenEmitter; 395 ParticleEffect *leftHandEmitter, *rightHandEmitter; 396 ParticleEffect *chargingEmitter, *chargeEmitter; 397 void updateCursor(float dt); 398 bool rolling; 399 int rollDidOne; 400 401 void startRoll(int dir); 402 void stopRoll(); 403 int getQuadrantDirection(int lastQuad, int quad); 404 void updateRoll(float dt); 405 int lastQuad, lastQuadDir; 406 void onDamage(DamageData &d); 407 void updateHair(float dt); 408 409 void lostTarget(int i, Entity *e); 410 411 Vector shieldPosition; 412 void updateAura(float dt); 413 414 415 void onHealthChange(float change); 416 void startWallBurst(bool useCursor=true); 417 void startBurst(); 418 419 420 void startBackFlip(); 421 void stopBackFlip(); 422 423 void clampVelocity(); 424 425 bool canCharge(int ability); 426 void formAbilityUpdate(float dt); 427 float revertTimer; 428 429 void endCharge(); 430 Entity *activateEntity; 431 bool canMove; 432 433 void onEnterState(int action); 434 void onExitState(int action); 435 std::vector<ParticleEffect*>targetQuads; 436 Quad *blinder, *fader, *tripper; 437 void applyBlindEffects(); 438 void removeBlindEffects(); 439 440 float zoomVel; 441 // implement "bobbing" in a lower class 442 int getBeamWidth(); 443 Vector getWallNormal(TileVector t); 444 bool checkWarpAreas(); 445 446 float splashDelay; 447 //Hair *hair; 448 449 //Item *currentItem; 450 void onUpdate(float dt); 451 void onRender(); 452 453 Quad *glow; 454 bool swimming; 455 456 void lmbd(); 457 void lmbu(); 458 459 void rmbd(); 460 void rmbu(); 461 462 bool charging; 463 464 float pushingOffWallEffect; 465 float lockToWallFallTimer; 466 467 Vector wallPushVec; 468 469 470 471 void lockToWall(); 472 void doShock(const std::string &shotName); 473 474 bool _canActivateStuff; 475 bool _canBurst; 476 bool _canLockToWall; 477 bool _canSwimAgainstCurrents; 478 bool _canCollideWithShots; 479 SeeMapMode _seeMapMode; 480 481 int _collisionAvoidRange; 482 float _collisionAvoidMod; 483 484 }; 485 486 #endif 487