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 GAME_H
22 #define GAME_H
23 
24 #include "../BBGE/DebugFont.h"
25 #include "../ExternalLibs/glpng.h"
26 
27 #include "DSQ.h"
28 #include "AquariaMenuItem.h"
29 #include "ScriptedEntity.h"
30 #include "TileVector.h"
31 #include "Shot.h"
32 #include "AquariaProgressBar.h"
33 
34 #include "tinyxml2.h"
35 using namespace tinyxml2;
36 
37 
38 class RecipeMenuEntry : public RenderObject
39 {
40 public:
41 	RecipeMenuEntry(Recipe *recipe);
42 protected:
43 	void onUpdate(float dt);
44 	Quad *result, *ing[3];
45 	Quad *glow;
46 	BitmapText *description;
47 	IngredientData *data;
48 
49 	Recipe *recipe;
50 
51 	int selected;
52 };
53 
54 struct RecipeMenu
55 {
56 	RecipeMenu();
57 	Quad *scroll;
58 	Quad *scrollEnd;
59 	BitmapText *header, *page, *description;
60 	AquariaMenuItem *nextPage, *prevPage;
61 
62 
63 	void toggle(bool on, bool watch=false);
64 	void createPage(int p);
65 	void slide(RenderObject *r, bool in, float t);
66 	void destroyPage();
67 	void goNextPage();
68 	void goPrevPage();
69 	int getNumPages();
70 	int getNumKnown();
71 
72 	int currentPage;
73 
74 	bool on;
75 
76 	std::vector<RecipeMenuEntry*> recipeMenuEntries;
77 };
78 
79 class Avatar;
80 class Gradient;
81 class CurrentRender;
82 class SteamRender;
83 class SongLineRender;
84 class AutoMap;
85 class DebugButton;
86 class WorldMapRender;
87 
88 const float boxElementZ = -0.1f;
89 const int MAX_GRID = 2222;
90 
91 const char CHAR_DOWN		= 'd';
92 const char CHAR_UP			= 'u';
93 const char CHAR_LEFT		= 'l';
94 const char CHAR_RIGHT		= 'r';
95 
96 
97 const float MIN_SIZE = 0.1;
98 
99 #ifdef AQUARIA_DEMO
100 	#undef AQUARIA_BUILD_SCENEEDITOR
101 #endif
102 
103 //#include "GridRender.h"
104 class GridRender;
105 class MiniMapRender;
106 class WaterSurfaceRender;
107 class ToolTip;
108 
109 #include "Path.h"
110 
111 #ifdef AQUARIA_BUILD_SCENEEDITOR
112 struct EntityGroupEntity
113 {
114 	std::string name;
115 	std::string gfx;
116 };
117 
118 typedef std::vector<EntityGroupEntity> EntityGroupEntities;
119 
120 struct EntityGroup
121 {
122 	std::string name;
123 	EntityGroupEntities entities;
124 };
125 
126 typedef std::vector<EntityGroup> EntityGroups;
127 
128 enum EditTypes
129 {
130 	ET_ELEMENTS		=0,
131 	ET_ENTITIES		=1,
132 	ET_PATHS		=2,
133 	ET_SELECTENTITY =4,
134 	ET_MAX
135 };
136 #endif
137 
138 class ManaBall : public Quad
139 {
140 public:
141 	ManaBall(Vector pos, float a);
142 	void destroy();
143 	bool isUsed();
144 	void use(Entity *entity);
145 	ParticleEffect healEmitter;
146 protected:
147 	float lifeSpan;
148 	bool used;
149 	float amount;
150 	void onUpdate(float dt);
151 };
152 
153 class Ingredient : public Entity
154 {
155 public:
156 	Ingredient(const Vector &pos, IngredientData *data, int amount=1);
157 	void destroy();
158 	IngredientData *getIngredientData();
159 
160 	void eat(Entity *e);
161 	bool hasIET(IngredientEffectType iet);
162 protected:
163 	bool isRotKind();
164 	IngredientData *data;
165 	bool used, gone;
166 	float lifeSpan;
167 	int amount;
168 	void onUpdate(float dt);
169 };
170 
171 typedef std::list<Ingredient*> Ingredients;
172 
173 class WarpArea
174 {
175 public:
WarpArea()176 	WarpArea()
177 	{
178 		w = h = radius = 0;
179 		generated = false;
180 	}
181 	Vector position;
182 	Vector avatarPosition;
183 	int radius;
184 	bool generated;
185 	int w, h;
186 	Vector spawnOffset;
187 	std::string sceneName, warpAreaType;
188 };
189 
190 class SongSlot : public AquariaGuiQuad
191 {
192 public:
193 	SongSlot(int songSlot);
194 
195 	int songSlot, songType;
196 	bool mbDown;
197 protected:
198 	Quad *glow;
199 	void onUpdate(float dt);
200 };
201 
202 class FoodSlot : public AquariaGuiQuad
203 {
204 public:
205 	FoodSlot(int slot);
206 
207 	void refresh(bool effects);
208 	int slot;
209 	void toggle(bool f);
210 	static int foodSlotIndex;
211 
getIngredient()212 	IngredientData *getIngredient() { return ingredient; }
213 
214 	float scaleFactor;
215 
216 	void eatMe();
217 	void moveRight();
218 	void discard();
219 
220 	bool isCursorIn();
221 
222 	void setOriginalPosition(const Vector &op);
223 
224 protected:
225 	int rmb;
226 	bool right;
227 	float doubleClickDelay;
228 	float grabTime;
229 	int lastAmount;
230 	IngredientData *lastIngredient;
231 	Vector originalPosition;
232 	void onUpdate(float dt);
233 	DebugFont *label;
234 	bool inCookSlot;
235 	IngredientData *ingredient;
236 	Quad *lid;
237 };
238 
239 class PetSlot : public AquariaGuiQuad
240 {
241 public:
242 	PetSlot(int pet);
243 	int petFlag;
244 protected:
245 	bool wasSlot;
246 	int petidx;
247 	bool mouseDown;
248 	void onUpdate(float dt);
249 };
250 
251 class TreasureSlot : public AquariaGuiQuad
252 {
253 public:
254 	TreasureSlot(int treasureFlag);
255 	void refresh();
256 protected:
257 	float doubleClickTimer;
258 	bool mbd;
259 	int flag;
260 	std::string treasureName, treasureDesc;
261 	int index;
262 	void onUpdate(float dt);
263 };
264 
265 class FoodHolder : public Quad
266 {
267 public:
268 	FoodHolder(int slot, bool trash=false);
269 
270 	bool isEmpty();
271 	bool isTrash();
272 	void setIngredient(IngredientData *i, bool effects=true);
273 	void dropFood();
274 	IngredientData *getIngredient();
275 	void animateLid(bool down, bool longAnim=true);
276 protected:
277 	bool trash;
278 	Quad *wok, *ing;
279 	bool buttonDown;
280 	void onUpdate(float dt);
281 
282 	Quad *lid;
283 
284 	int slot;
285 private:
286 	IngredientData *foodHolderIngredient;
287 };
288 
289 class ElementTemplate
290 {
291 public:
ElementTemplate()292 	ElementTemplate() { alpha = 1; cull = true; w=-1; h=-1; idx=-1; tu1=tu2=tv1=tv2=0; }
293 	std::string gfx;
294 	std::vector <TileVector> grid;
295 	int w,h;
296 	float tu1, tu2, tv1, tv2;
297 	void setGrid(Vector position);
298 	bool cull;
299 	float alpha;
300 	int idx;
301 };
302 
303 class MiniMapHint
304 {
305 public:
306 	std::string scene;
307 	std::string warpAreaType;
clear()308 	void clear()
309 	{
310 		debugLog("miniMapHint: CLEAR");
311 		scene = warpAreaType = "";
312 	}
313 };
314 
315 class WarpAreaRender : public RenderObject
316 {
317 public:
318 protected:
319 	void onRender();
320 };
321 
322 class ObsRow
323 {
324 public:
325 	ObsRow(int tx, int ty, int len);
326 	int tx, ty, len;
327 };
328 
329 enum FlagCheckType
330 {
331 	NO_TYPE	=-1,
332 	AND		=0,
333 	OR		=1
334 };
335 
336 #ifdef AQUARIA_BUILD_SCENEEDITOR
337 enum EditorStates
338 {
339 	ES_SELECTING	=0,
340 	ES_SCALING		=1,
341 	ES_ROTATING		=2,
342 	ES_MOVING		=3,
343 	ES_MAX
344 };
345 
346 #endif
347 
348 class EntityClass
349 {
350 public:
351 	EntityClass(std::string name, bool script=false, int idx=-1, std::string prevGfx="", float prevScale=1)
name(name)352 		: name(name), script(script), idx(idx), prevGfx(prevGfx), prevScale(prevScale) {}
353 	std::string name;
354 	float prevScale;
355 	std::string prevGfx;
356 	bool script;
357 	int idx;
358 };
359 
360 #ifdef AQUARIA_BUILD_SCENEEDITOR
361 
362 class SceneEditorMenuReceiver : public DebugButtonReceiver
363 {
364 public:
365 	void buttonPress(DebugButton *db);
366 };
367 
368 struct SelectedEntity
369 {
370 	SelectedEntity();
371 	void clear();
372 	void setIndex(int idx);
373 	void setName(const std::string &name, const std::string &prevGfx);
374 	void setSelectEntity(const SelectedEntity &ent);
375 
376 	bool nameBased;
377 	int index, typeListIndex;
378 	std::string name;
379 	std::string prevGfx;
380 	float prevScale;
381 };
382 
383 class SceneEditor : public ActionMapper
384 {
385 public:
386 	SceneEditor();
387 	void init();
388 	void shutdown();
389 	void toggle();
390 	void toggle(bool on);
391 	void update(float dt);
392 	void prevElement();
393 	void nextElement();
394 	void doPrevElement();
395 	Element *cycleElementNext(Element *e);
396 	Element *cycleElementPrev(Element *e);
397 	void selectZero();
398 	void selectEnd();
399 	void placeElement();
400 	void flipElementHorz();
401 	void flipElementVert();
402 	void deleteSelectedElement();
403 	void deleteElement(int selectedIdx);
404 	void action(int id, int state);
405 	void scaleElementUp();
406 	void scaleElementDown();
407 	void scaleElement1();
408 	void placeAvatar();
409 
410 	void executeButtonID(int bid);
411 
412 	void openMainMenu();
413 	void closeMainMenu();
414 
415 	void setBackgroundGradient();
416 
417 	bool isOn();
418 
419 	void generateLevel();
420 	void skinLevel(pngRawInfo *png, int minX, int minY, int maxX, int maxY);
421 	void skinLevel();
422 
423 	void regenLevel();
424 
425 
426 	void startDrawingWarpArea(char c);
427 	void endDrawingWarpArea(char c);
428 
429 	void updateSaveFileEnemyPosition(Entity *ent);
430 	void startMoveEntity();
431 	void endMoveEntity();
432 
433 	void down();
434 	void up();
435 
436 	void exitMoveState();
437 
438 	void alignHorz();
439 	void alignVert();
440 
441 	EditTypes editType;
442 	EditorStates state;
443 
444 	Element *getElementAtCursor();
445 	Entity *getEntityAtCursor();
446 
447 	void mouseButtonLeftUp();
448 	void mouseButtonRightUp();
449 	void moveToBack();
450 	void moveToFront();
451 	int bgLayer;
452 	Element *editingElement;
453 	Entity *editingEntity;
454 	Path *editingPath;
455 
456 	void toggleWarpAreaRender();
457 	int selectedIdx;
458 	int selectedNode;
459 	Path *getSelectedPath();
460 	void changeDepth();
461 	void updateEntitySaveData(Entity *editingEntity);
462 	void moveLayer();
463 	void moveElementToLayer(Element *e, int bgLayer);
464 	void toggleElementRepeat();
465 	bool multiSelecting;
466 	Vector multiSelectPoint;
467 	std::vector <Element*> selectedElements;
468 	void fixEntityIDs();
469 
470 	Vector groupCenter;
471 	Vector getSelectedElementsCenter();
472 
473 	Quad dummy;
474 
475 	void updateSelectedElementPosition(Vector position);
476 	int selectedEntityType;
477 	//int curEntity;
478 	SelectedEntity selectedEntity;
479 	//EntityGroups::iterator page;
480 	int entityPageNum;
481 
482 	void checkForRebuild();
483 	void createAquarian();
484 	void dumpObs();
485 
486 	DebugButton *btnMenu;
487 protected:
488 
489 	void reversePath();
490 
491 	void updateEntityPlacer();
492 	void updateMultiSelect();
493 	float autoSaveTimer;
494 	int autoSaveFile;
495 
496 	void enterName();
497 	void changeShape();
498 	int skinMinX, skinMinY, skinMaxX, skinMaxY;
499 
500 	void setGridPattern(int gi);
501 	void setGridPattern0();
502 	void setGridPattern1();
503 	void setGridPattern2();
504 	void setGridPattern3();
505 	void setGridPattern4();
506 	void setGridPattern5();
507 	void setGridPattern6();
508 	void setGridPattern7();
509 	void setGridPattern8();
510 	void setGridPattern9();
511 	void toggleElementSolid();
512 	void toggleElementHurt();
513 	void editModeElements();
514 	void editModeEntities();
515 	void editModePaths();
516 
517 	void deleteSelected();
518 	void cloneSelectedElement();
519 	void enterScaleState();
520 	void enterRotateState();
521 	void enterMoveState();
522 
523 	Vector oldPosition, oldRotation, oldScale, cursorOffset, oldRepeatScale;
524 
525 	Entity *movingEntity;
526 	void updateDrawingWarpArea(char c, int k);
527 	char drawingWarpArea;
528 
529 	void nextEntityType();
530 	void prevEntityType();
531 
532 	void removeEntity();
533 
534 	void selectEntityFromGroups();
535 
536 
537 	WarpAreaRender *warpAreaRender;
538 	Vector zoom;
539 
540 	Vector boxPos;
541 	Quad *boxPromo;
542 	bool drawingBox;
543 	void rotateElement();
544 	void rotateElement2();
545 	void updateText();
546 
547 	void saveScene();
548 	void loadScene();
549 
550 	SceneEditorMenuReceiver menuReceiver;
551 
552 	void addMainMenuItem(const std::string &label, int bid);
553 
554 	void loadSceneByName();
555 	void reloadScene();
556 
557 	void mouseButtonLeft();
558 	void mouseButtonRight();
559 
560 	int curElement, selectedVariation, possibleSelectedIdx;
561 
562 	Quad *placer;
563 	DebugFont *text;
564 	bool on;
565 	InterpolatedVector oldGlobalScale;
566 };
567 
568 #endif  // AQUARIA_BUILD_SCENEEDITOR
569 
570 typedef std::vector<Quad*> QuadList;
571 typedef std::vector<QuadList> QuadArray;
572 
573 typedef std::vector<Element*> ElementUpdateList;
574 
575 // Note: although this is a bitmask, only one of these values may be set at a time!
576 enum ObsType
577 {
578 	OT_EMPTY		= 0x00,
579 
580 	// immutable
581 	OT_BLACK		= 0x01,
582 	OT_BLACKINVIS	= 0x02,  // same as OT_BLACK, but not drawn
583 	OT_MASK_BLACK	= OT_BLACK | OT_BLACKINVIS,
584 
585 	// set by tiles
586 	OT_INVISIBLE	= 0x04,
587 	OT_INVISIBLEIN	= 0x08,
588 	OT_HURT			= 0x10,
589 
590 	// set by entities
591 	OT_INVISIBLEENT = 0x20,
592 
593 	// mask for all bits that block
594 	OT_BLOCKING = OT_MASK_BLACK | OT_INVISIBLE | OT_INVISIBLEIN | OT_HURT | OT_INVISIBLEENT,
595 
596 	// free for use, not colliding by default
597 	OT_USER1 = 0x40,
598 	OT_USER2 = 0x80,
599 	OT_USER_MASK = OT_USER1 | OT_USER2,
600 };
601 
602 struct EntitySaveData
603 {
604 public:
EntitySaveDataEntitySaveData605 	EntitySaveData(Entity *e, int idx, int x, int y, int rot, int id, const std::string &name) : e(e), idx(idx), x(x), y(y), rot(rot), id(id), name(name) {}
606 	Entity *e;
607 	int idx, x, y, rot, id;
608 	std::string name;
609 };
610 
611 class Game : public StateObject
612 {
613 public:
614 	Game();
615 	~Game();
616 	void applyState();
617 	void removeState();
618 	void update(float dt);
619 	void onLeftMouseButton();
620 	//std::vector<Item*>items;
621 
622 	Avatar *avatar;
623 	Entity *li;
624 
625 	Element *elementWithMenu;
626 
627 	FoodSlot *moveFoodSlotToFront;
628 
629 	//void doChoiceMenu(Vector position, std::vector<std::string> choices);
630 
getSelectedChoice()631 	std::string getSelectedChoice() { return selectedChoice; }
632 
633 	ObsType getGrid(const TileVector &tile) const;
634 	ObsType getGridRaw(const TileVector &tile) const;
635 	unsigned char *getGridColumn(int tileX);
636 	void setGrid(const TileVector &tile, ObsType v);
637 	void addGrid(const TileVector &tile, ObsType v);
638 	bool isObstructed(const TileVector &tile, int t = OT_BLOCKING) const;
639 	void trimGrid();
640 	void dilateGrid(unsigned int radius, ObsType test, ObsType set, ObsType allowOverwrite);
641 
642 	void clearPointers();
643 
644 	void sortFood();
645 	void updatePreviewRecipe();
646 
647 	void transitionToScene(std::string scene);
648 	bool loadScene(std::string scene);
649 
650 	void clearGrid(int v = 0);
651 	void clearDynamicGrid(unsigned char maskbyte = OT_MASK_BLACK);
652 
653 	void toggleWorldMap();
654 
655 	void action(int id, int state);
656 
657 	void adjustFoodSlotCursor();
658 
659 	void loadElementTemplates(std::string pack);
660 	Element* createElement(int etidx, Vector position, int bgLayer=0, RenderObject *copy=0, ElementTemplate *et=0);
661 	void setGrid(ElementTemplate *et, Vector position, float rot360=0);
662 
663 	void updateParticlePause();
664 
665 	void reconstructGrid(bool force=false);
666 	void reconstructEntityGrid();
667 
668 	void registerSporeDrop(const Vector &pos, int t);
669 
670 	bool collideCircleWithGrid(const Vector& position, float r);
671 
672 	bool collideHairVsCircle(Entity *a, int num, const Vector &pos2, float radius, float perc=0, int *colSegment=0);
673 
674 	bool collideCircleVsCircle(Entity *a, Entity *b);
675 	Bone *collideSkeletalVsCircle(Entity *skeletal, RenderObject *circle);
676 	Bone *collideSkeletalVsLine(Entity *skeletal, Vector start, Vector end, float radius);
677 	bool collideCircleVsLine(RenderObject *r, Vector start, Vector end, float radius);
678 	bool collideCircleVsLineAngle(RenderObject *r, float angle, float startLen, float endLen, float radius, Vector basePos);
679 	Bone *collideSkeletalVsCircle(Entity *skeletal, Vector pos, float radius);
680 	void handleShotCollisions(Entity *e, bool hasShield=false);
681 	void handleShotCollisionsSkeletal(Entity *e);
682 	void handleShotCollisionsHair(Entity *e, int num = 0, float perc = 0);
683 
684 	std::vector<ElementTemplate> elementTemplates;
685 	std::string sceneName;
686 
687 	ElementTemplate *getElementTemplateByIdx(int idx);
688 
689 	bool saveScene(std::string scene);
690 	typedef std::vector<WarpArea> WarpAreas;
691 	WarpAreas warpAreas;
692 
693 	void postInitEntities();
694 	EntityClass *getEntityClassForEntityType(const std::string &type);
695 
696 	void warpToArea(WarpArea *area);
697 
698 	InterpolatedVector sceneColor, sceneColor2, sceneColor3;
699 	Vector backupSceneColor;
700 
701 	Vector getCameraPositionFor(const Vector &vec);
702 
703 	bool isActive();
704 
705 	bool isPaused();
706 	void togglePause(bool v);
707 
708 	Ingredient* spawnIngredient(const std::string &ing, const Vector &pos, int times=1, int out=0);
709 	void spawnIngredientFromEntity(Entity *ent, IngredientData *data);
710 
711 	Ingredient *getNearestIngredient(const Vector &pos, int radius);
712 	Entity *getNearestEntity(const Vector &pos, int radius, Entity *ignore = 0, EntityType et=ET_NOTYPE, DamageType dt=DT_NONE, int lrStart=-1, int lrEnd=-1);
713 
714 	Script *cookingScript;
715 
716 	void spawnManaBall(Vector pos, float a);
717 	bool updateMusic();
718 	std::string overrideMusic;
719 	void resetFromTitle();
720 
721 	float maxZoom;
722 	float maxLookDistance;
723 
724 	void setParallaxTextureCoordinates(Quad *q, float speed);
725 
726 	XMLDocument *saveFile;
727 
728 	Vector positionToAvatar;
729 	float getCoverage(Vector pos, int sampleArea = 5);
730 
731 	float getPercObsInArea(Vector position, int range, int obs=-1);
732 	Vector getWallNormal(Vector pos, int sampleArea = 5, float *dist=0, int obs = -1);
733 
734 	// HACK:: clean up these vars
735 	std::string warpAreaType, warpAreaSide;
736 	Vector spawnOffset;
737 	Vector miniMapHintPosition;
738 	MiniMapHint miniMapHint;
739 	void updateMiniMapHintPosition();
740 	EntitySaveData *getEntitySaveDataForEntity(Entity *e, Vector pos);
741 	Entity *createEntity(int idx, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, bool doPostInit=false);
742 	Entity *createEntity(const std::string &type, int id, Vector position, int rot, bool createSaveData, std::string name, EntityType = ET_ENEMY, bool doPostInit=false);
743 	Entity *establishEntity(Entity *e, int id=0, Vector position=Vector(0,0), int rot=0, bool createSaveData=false, std::string name="", EntityType = ET_ENEMY,bool doPostInit=false);
744 	void setCameraFollow(RenderObject *r);
745 	void setCameraFollowEntity(Entity *e);
746 	void setMenuDescriptionText(const std::string &text);
747 
748 	bool removeEntityAtCursor();
749 	void toggleOverrideZoom(bool on);
750 	bool doFlagCheck(const std::string &flagCheck, FlagCheckType type=NO_TYPE, bool lastTruth=false);
751 
752 	bool useWaterLevel;
753 	InterpolatedVector waterLevel;
754 	int saveWaterLevel;
755 	void flipSceneVertical(int flipY);
756 	void warpCameraTo(RenderObject *r);
757 	bool isSceneFlipped();
758 	void refreshItemSlotIcons();
759 
760 	void addObsRow(int tx, int ty, int len);
761 	void clearObsRows();
762 	void setWarpAreaSceneName(WarpArea &warpArea);
763 	Entity *getEntityAtCursor();
764 	Vector cameraMin, cameraMax;
765 	bool removeEntity(Entity *e);
766 	void removeIngredient(Ingredient *i);
767 	void bindIngredients();
768 
769 protected:
770 	std::vector<Path*> paths;
771 	Path *firstPathOfType[PATH_MAX];
772 public:
773 	void addPath(Path *p);
774 	void removePath(int idx);
775 	void clearPaths();
getNumPaths()776 	int getNumPaths() const {return paths.size();}
getPath(int idx)777 	Path *getPath(int idx) const {return paths[idx];}
getFirstPathOfType(PathType type)778 	Path *getFirstPathOfType(PathType type) const {return firstPathOfType[type];}
779 	Path *getPathByName(std::string name);
780 	int getIndexOfPath(Path *p);
781 	Path *getPathAtCursor();
782 	Path *getScriptedPathAtCursor(bool withAct=false);
783 	Path *getNearestPath(const Vector &pos, const std::string &name="", const Path *ignore=0);
784 	Path *getNearestPath(const Vector &pos, PathType pathType=PATH_NONE);
785 	Path *getNearestPath(Path *p, std::string name);
786 
787 #ifdef AQUARIA_BUILD_SCENEEDITOR
788 	SceneEditor sceneEditor;
isSceneEditorActive()789 	bool isSceneEditorActive() {return sceneEditor.isOn();}
790 #else
isSceneEditorActive()791 	bool isSceneEditorActive() const {return false;}
792 #endif
793 
794 	bool isInGameMenu();
795 
796 	typedef std::vector<EntityClass> EntityTypeList;
797 	EntityTypeList entityTypeList;
798 	void loadEntityTypeList();
799 	std::vector<EntitySaveData> entitySaveData;
800 	int getIdxForEntityType(std::string type);
801 	void hideInGameMenu(bool effects=true, bool cancel=false);
802 	void showInGameMenu(bool force=false, bool optionsOnly=false, MenuPage menuPage = MENUPAGE_NONE);
803 	bool optionsOnly;
804 
805 	MenuPage currentMenuPage;
806 	int currentFoodPage, currentTreasurePage;
807 
808 	Precacher tileCache;
809 
810 	//void cameraPanToNode(Path *p, int speed=500);
811 	//void cameraRestore();
812 	void setCameraFollow(Vector *position);
813 	Shot *fireShot(Entity *firer, const std::string &particleEffect, Vector position, bool big, Vector direction, Entity *target, int homing=0, int velLenOverride=0, int targetPt=-1);
814 	Shot *fireShot(const std::string &bankShot, Entity *firer, Entity *target=0, const Vector &pos=Vector(0,0,0), const Vector &aim=Vector(0,0,0), bool playSfx=true);
815 	void playBurstSound(bool wallJump=false);
816 	void toggleMiniMapRender();
817 	void toggleMiniMapRender(int v);
818 	bool runGameOverScript;
819 
820 
821 	void setTimerTextAlpha(float a, float t);
822 	void setTimerText(float time);
823 
824 	void generateCollisionMask(Quad *q, float overrideCollideRadius=0);
825 	std::string sceneNatureForm;
826 	std::string fromScene, toNode;
827 	int toFlip;
828 	char fromWarpType;
829 	Vector fromVel;
830 	void warpToSceneFromNode(Path *p);
831 	Vector fromPosition;
832 
833 	Quad *damageSprite;
834 
835 	void toggleDamageSprite(bool on);
836 
837 	ObsType lastCollideTileType;
838 
839 	void fillGridFromQuad(Quad *q, ObsType ot=OT_INVISIBLEIN, bool trim=true);
840 
841 	bool isDamageTypeAvatar(DamageType dt);
842 	bool isDamageTypeEnemy(DamageType dt);
843 	bool isEntityCollideWithShot(Entity *e, Shot *shot);
844 	void setControlHint(const std::string &hint, bool left, bool right, bool middle, float time, std::string image="", bool ignoreClear=false, int songType=0, float scale=1);
845 	void clearControlHint();
846 
847 	void colorTest();
848 
849 	void playSongInMenu(int songType, bool override=false);
850 
851 	bool trace(Vector start, Vector target);
852 
853 	Quad *menuSongs;
854 	std::vector<SongSlot*> songSlots;
855 	std::vector<FoodSlot*> foodSlots;
856 	std::vector<TreasureSlot*> treasureSlots;
857 	BitmapText* songDescription;
858 
859 	BitmapText *timerText;
860 
861 	float cameraLerpDelay;
862 	Vector gradTop, gradBtm;
863 	bool isValidTarget(Entity *e, Entity *me);
864 	Gradient *grad;
865 	std::string bgSfxLoop, airSfxLoop;
866 	void constrainCamera();
867 	void setElementLayerVisible(int bgLayer, bool v);
868 	bool isElementLayerVisible(int bgLayer);
869 
870 	void showInGameMenuExitCheck();
871 	void hideInGameMenuExitCheck(bool refocus);
872 	bool isControlHint();
873 
874 	int getNumberOfEntitiesNamed(const std::string &name);
875 	MiniMapRender *miniMapRender;
876 	WorldMapRender *worldMapRender;
877 	AutoMap *autoMap;
878 
879 	Quad *hudUnderlay;
880 
881 	int worldMapIndex;
882 
883 	bool loadingScene;
884 
885 	WaterSurfaceRender *waterSurfaceRender;
886 	Quad *shapeDebug;
887 
888 #ifdef AQUARIA_BUILD_SCENEEDITOR
889 	EntityGroups entityGroups;
890 #endif
891 
892 	std::string getNoteName(int n, const std::string &pre="");
893 
894 	void selectEntityFromGroups();
895 	InterpolatedVector cameraInterp;
896 	//InterpolatedVector tintColor;
897 	float getWaterLevel();
898 	void setMusicToPlay(const std::string &musicToPlay);
899 	Vector lastCollidePosition;
900 	void switchBgLoop(int v);
901 	ElementTemplate getElementTemplateForLetter(int i);
902 	CurrentRender *currentRender;
903 	SteamRender *steamRender;
904 	SongLineRender *songLineRender;
905 
906 	void showImage(const std::string &image);
907 	void hideImage();
908 
909 	bool bNatural;
910 	void onLips();
911 	std::string sceneToLoad;
912 	void snapCam();
913 
914 	void updateOptionsMenu(float dt);
915 	BitmapText *songLabel, *foodLabel, *foodDescription, *treasureLabel;
916 	ToolTip *treasureDescription;
917 	Quad *treasureCloseUp;
918 	void updateBgSfxLoop();
919 	void preLocalWarp(LocalWarpType localWarpType);
920 	void postLocalWarp();
921 	void entityDied(Entity *e);
922 
isShuttingDownGameState()923 	bool isShuttingDownGameState() { return shuttingDownGameState; }
924 	void warpToSceneNode(std::string scene, std::string node);
925 
926 	AquariaProgressBar *progressBar;
927 	void addProgress();
928 	void endProgress();
929 
930 	void refreshFoodSlots(bool effects);
931 	void refreshTreasureSlots();
932 
933 	Recipe *findRecipe(const std::vector<IngredientData*> &list);
934 	void onCook();
935 	void onRecipes();
936 	void updateCookList();
937 	void onUseTreasure();
938 	void onUseTreasure(int flag);
939 
940 	void onPrevFoodPage();
941 	void onNextFoodPage();
942 
943 	void onPrevTreasurePage();
944 	void onNextTreasurePage();
945 
946 	std::vector<std::string> dropIngrNames;
947 
948 	AquariaMenuItem *lips;
949 
950 	int lastCollideMaskIndex;
951 
952 	void ensureLimit(Entity *e, int num, int state=0);
953 
954 	void rebuildElementUpdateList();
955 	void setElementLayerFlags();
956 
957 	float getTimer(float mod=1);
958 	float getHalfTimer(float mod=1);
959 	float getHalf2WayTimer(float mod=1);
960 
961 	std::string bgSfxLoopPlaying2;
962 
963 
964 	void createInGameMenu();
965 
966 	Entity *currentPet;
967 	Entity* setActivePet(int flag);
968 
969 	void spawnAllIngredients(const Vector &position);
970 	void createGradient();
971 
972 	std::string saveMusic;
973 	GridRender *gridRender, *gridRender2, *gridRender3, *edgeRender, *gridRenderEnt, *gridRenderUser1, *gridRenderUser2;
974 	void toggleGridRender();
975 	ElementUpdateList elementUpdateList;
976 	ElementUpdateList elementInteractionList;
977 
978 	bool invinciblity;
979 
isApplyingState()980 	bool isApplyingState() { return applyingState; }
981 	bool activation;
982 	void overrideZoom(float z, float t=1);
983 
984 	void learnedRecipe(Recipe *r, bool effects=true);
985 
986 
987 	bool firstSchoolFish;
988 	bool invincibleOnNested;
989 	bool hasPlayedLow;
990 
991 	void pickupIngredientEffects(IngredientData *data);
992 
993 	void bindInput();
994 	RecipeMenu recipeMenu;
995 
996 	AquariaMenuItem *eYes, *eNo, *cook, *recipes, *nextFood, *prevFood, *nextTreasure, *prevTreasure, *use, *keyConfigButton;
997 	AquariaMenuItem *opt_cancel, *opt_save, *foodSort;
998 
999 	bool cameraOffBounds;
1000 
1001 	void enqueuePreviewRecipe();
1002 
toggleHelpScreen()1003 	void toggleHelpScreen() { action(ACTION_TOGGLEHELPSCREEN, 0); }
1004 
setWorldPaused(bool b)1005 	void setWorldPaused(bool b) { worldPaused = b; }
isWorldPaused()1006 	bool isWorldPaused() const { return worldPaused; }
1007 
1008 	void setIgnoreAction(AquariaActions ac, bool ignore);
1009 	bool isIgnoreAction(AquariaActions ac) const;
1010 
1011 protected:
1012 
1013 	void toggleHelpScreen(bool on, const std::string &label="");
1014 	void onToggleHelpScreen();
1015 
1016 	void onHelpUp();
1017 	void onHelpDown();
1018 	bool helpWasPaused;
1019 	Quad *helpBG, *helpBG2;
1020 	AquariaMenuItem *helpUp, *helpDown, *helpCancel;
1021 	TTFText *helpText;
1022 	bool inHelpScreen;
1023 
1024 	int enqueuedPreviewRecipe;
1025 
1026 	Quad *previewRecipe;
1027 	Quad *menuIconGlow;
1028 	Quad *showRecipe;
1029 
1030 	bool isCooking;
1031 
1032 	void doMenuSectionHighlight(int sect);
1033 
1034 	float cookDelay;
1035 
1036 	float ingOffY;
1037 	float ingOffYTimer;
1038 
1039 	std::vector<RenderObject*> controlHintNotes;
1040 
1041 	void onPrevRecipePage();
1042 	void onNextRecipePage();
1043 
1044 
1045 
1046 	typedef std::vector<IngredientData*> CookList;
1047 	CookList cookList;
1048 
1049 	bool active;
1050 	bool applyingState;
1051 	int lastBgSfxLoop;
1052 	float timer, halfTimer;
1053 
1054 
1055 	void warpPrep();
1056 	bool shuttingDownGameState;
1057 	void onOptionsMenu();
1058 	bool optionsMenu, foodMenu, petMenu, treasureMenu, keyConfigMenu;
1059 	void toggleOptionsMenu(bool f, bool skipBackup=false, bool isKeyConfig=false);
1060 	void toggleFoodMenu(bool f);
1061 	void toggleMainMenu(bool f);
1062 	void togglePetMenu(bool f);
1063 	void toggleTreasureMenu(bool f);
1064 	void toggleRecipeList(bool on);
1065 	void toggleKeyConfigMenu(bool f);
1066 
1067 	void switchToSongMenu();
1068 	void switchToFoodMenu();
1069 	void switchToPetMenu();
1070 	void switchToTreasureMenu();
1071 
1072 	void onKeyConfig();
1073 
1074 	void addKeyConfigLine(RenderObject *group, const std::string &label, const std::string &actionInputName, int y, int l1=0, int l2=0, int l3=0);
1075 
1076 	AquariaKeyConfig *addAxesConfigLine(RenderObject *group, const std::string &label, const std::string &actionInputName, int y, int offx);
1077 
1078 	void onOptionsSave();
1079 	void onOptionsCancel();
1080 	AquariaSlider *sfxslider, *musslider, *voxslider;
1081 	AquariaCheckBox *autoAimCheck, *targetingCheck, *toolTipsCheck, *flipInputButtonsCheck, *micInputCheck, *blurEffectsCheck;
1082 	AquariaCheckBox *subtitlesCheck, *fullscreenCheck, *ripplesCheck;
1083 	AquariaComboBox *resBox;
1084 	Quad *songBubbles, *energyIdol, *liCrystal;
1085 
1086 	RenderObject *group_keyConfig;
1087 
1088 	Quad *options;
1089 
1090 	Quad *image;
1091 	void assignEntitiesUniqueIDs();
1092 	void initEntities();
1093 
1094 
1095 	void onExitCheckNo();
1096 	void onExitCheckYes();
1097 
1098 	BitmapText *circlePageNum;
1099 
1100 	std::vector<ToolTip*> foodTips, songTips, petTips, treasureTips;
1101 
1102 
1103 
1104 	Quad *eAre;
1105 	int inGameMenuExitState;
1106 	float controlHintTimer;
1107 	bool cameraConstrained;
1108 
1109 	void updateCursor(float dt);
1110 	void updateInGameMenu(float dt);
1111 	float songMenuPlayDelay;
1112 	int currentSongMenuNote;
1113 	int playingSongInMenu;
1114 	Quad *controlHint_mouseLeft, *controlHint_mouseRight, *controlHint_mouseBody, *controlHint_mouseMiddle, *controlHint_bg, *controlHint_image;
1115 	Quad *controlHint_shine;
1116 	bool controlHint_ignoreClear;
1117 	BitmapText *controlHint_text;
1118 
1119 
1120 
1121 	void updateCurrentVisuals(float dt);
1122 	std::string lastTileset;
1123 
1124 
1125 	void createLi();
1126 	void createPets();
1127 	Quad *backdropQuad;
1128 	void findMaxCameraValues();
1129 	std::vector<ObsRow> obsRows;
1130 
1131 	bool sceneFlipped;
1132 
1133 
1134 	void flipRenderObjectVertical(RenderObject *r, int flipY);
1135 	void onFlipTest();
1136 
1137 	void onDebugSave();
1138 
1139 	BitmapText *menuDescription;
1140 	BitmapText *menuEXP, *menuMoney;
1141 
1142 	std::vector<Quad*> spellIcons;
1143 	int currentInventoryPage;
1144 	float backgroundImageRepeat;
1145 
1146 	std::string musicToPlay;
1147 
1148 	float deathTimer;
1149 
1150 	/*
1151 	void onAssignMenuScreenItemToSlot0();
1152 	void onAssignMenuScreenItemToSlot1();
1153 	void onAssignMenuScreenItemToSlot2();
1154 	void onAssignMenuScreenItemToSlot3();
1155 	*/
1156 
1157 	void onInGameMenuInventory();
1158 	void onInGameMenuSpellBook();
1159 	void onInGameMenuContinue();
1160 	void onInGameMenuOptions();
1161 	void onInGameMenuSave();
1162 	void onInGameMenuExit();
1163 
1164 	void onPressEscape();
1165 
1166 
1167 
1168 	std::vector<AquariaMenuItem*> menu;
1169 	Quad *menuBg, *menuBg2;
1170 	bool paused;
1171 	bool worldPaused;
1172 
1173 	Vector getClosestPointOnTriangle(Vector a, Vector b, Vector c, Vector p);
1174 	Vector getClosestPointOnLine(Vector a, Vector b, Vector p);
1175 
1176 	std::string elementTemplatePack;
1177 
1178 
1179 	Vector *cameraFollow;
1180 	RenderObject *cameraFollowObject;
1181 	Entity *cameraFollowEntity;
1182 	bool loadSceneXML(std::string scene);
1183 
1184 #ifdef AQUARIA_BUILD_SCENEEDITOR
1185 	void toggleSceneEditor();
1186 #endif
1187 
1188 	unsigned char grid[MAX_GRID][MAX_GRID];
1189 
1190 
1191 	Quad *bg, *bg2;
1192 
1193 	bool inGameMenu;
1194 	float menuOpenTimer;
1195 
1196 	std::vector <Quad*> itemSlotIcons, itemSlotEmptyIcons;
1197 
1198 
1199 	std::string selectedChoice;
1200 
1201 	void warpCameraTo(Vector position);
1202 
1203 	std::set<int> ignoredActions;
1204 
1205 private:
1206 	Ingredients ingredients;
1207 };
1208 
1209 extern Game *game;
1210 
1211 // INLINE FUNCTIONS
1212 
1213 inline
getGridRaw(const TileVector & tile)1214 ObsType Game::getGridRaw(const TileVector &tile) const
1215 {
1216 	return (unsigned(tile.x) < unsigned(MAX_GRID) && unsigned(tile.y) < unsigned(MAX_GRID))
1217 		? ObsType(grid[tile.x][tile.y])
1218 		: OT_INVISIBLE;
1219 }
1220 
1221 inline
getGrid(const TileVector & tile)1222 ObsType Game::getGrid(const TileVector &tile) const
1223 {
1224 	return (unsigned(tile.x) < unsigned(MAX_GRID) && unsigned(tile.y) < unsigned(MAX_GRID))
1225 		? ObsType(grid[tile.x][tile.y] & OT_BLOCKING)
1226 		: OT_INVISIBLE;
1227 }
1228 
1229 inline
getGridColumn(int tileX)1230 unsigned char *Game::getGridColumn(int tileX)
1231 {
1232 	if (tileX < 0)
1233 		return grid[0];
1234 	else if (tileX >= MAX_GRID)
1235 		return grid[MAX_GRID-1];
1236 	else
1237 		return grid[tileX];
1238 }
1239 
1240 inline
setGrid(const TileVector & tile,ObsType v)1241 void Game::setGrid(const TileVector &tile, ObsType v)
1242 {
1243 	if (unsigned(tile.x) < unsigned(MAX_GRID) && unsigned(tile.y) < unsigned(MAX_GRID))
1244 		grid[tile.x][tile.y] = v;
1245 }
1246 
1247 inline
addGrid(const TileVector & tile,ObsType v)1248 void Game::addGrid(const TileVector &tile, ObsType v)
1249 {
1250 	if (unsigned(tile.x) < unsigned(MAX_GRID) && unsigned(tile.y) < unsigned(MAX_GRID))
1251 		grid[tile.x][tile.y] |= v;
1252 }
1253 
1254 inline
isObstructed(const TileVector & tile,int t)1255 bool Game::isObstructed(const TileVector &tile, int t /* = OT_BLOCKING */) const
1256 {
1257 	return (getGrid(tile) & t);
1258 }
1259 
1260 #endif
1261