]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/mias.cpp
Don't define variables in header files.
[quix0rs-blobwars.git] / src / mias.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 */
21
22 #include "mias.h"
23
24 void initMIAPhrases()
25 {
26         strlcpy(mia_scared[0], "help me...", sizeof mia_scared[0]);
27         strlcpy(mia_scared[1], "i don't wanna die...", sizeof mia_scared[1]);
28         strlcpy(mia_scared[2], "please... someone help...", sizeof mia_scared[2]);
29         strlcpy(mia_scared[3], "i... i'm scared...", sizeof mia_scared[3]);
30         strlcpy(mia_scared[4], "i wanna go home...", sizeof mia_scared[4]);
31         strlcpy(mia_scared[5], "what was that?!", sizeof mia_scared[5]);
32         strlcpy(mia_scared[6], "i don't like it here...", sizeof mia_scared[6]);
33 }
34
35 void addMIA(const char *name, int x, int y, int type)
36 {
37         Entity *mia = new Entity();
38
39         strlcpy(mia->name, name, sizeof mia->name);
40         mia->id = type;
41         mia->baseThink = 60;
42         mia->health = 180;
43         mia->place(x, y);
44         mia->value = Math::rrand(0, 5);
45         mia->flags = ENT_INANIMATE; // MIAs don't drown
46
47         switch (mia->id)
48         {
49                 case MIA_NORMAL:
50                         mia->setSprites(graphics.getSprite("ScaredMIA", true), graphics.getSprite("ScaredMIA", true), graphics.getSprite("ScaredMIA", true));
51                         break;
52                 case MIA_AQUA:
53                         mia->setSprites(graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true));
54                         break;
55         }
56
57         map.addMIA(mia);
58 }
59
60 void doMIAs()
61 {
62         Entity *mia = (Entity*)map.miaList.getHead();
63
64         int x, y;
65
66         char message[256];
67
68         while (mia->next != NULL)
69         {
70                 mia = (Entity*)mia->next;
71
72                 if (mia->health <= 0)
73                         continue;
74
75                 mia->think();
76
77                 if (mia->flags & ENT_TELEPORTING)
78                 {
79                         moveEntity(mia);
80                 }
81                 else
82                 {
83                         x = (int)(mia->x - engine.playerPosX);
84                         y = (int)(mia->y - engine.playerPosY);
85
86                         if ((abs(x) <= 2048) && (abs(y) <= 768))
87                         {
88                                 moveEntity(mia);
89
90                                 if (mia->value < 100)
91                                 {
92                                         if ((Math::prand() % 250) == 0)
93                                                 mia->value = 100;
94                                 }
95                                 else
96                                 {
97                                         if ((Math::prand() % 250) == 0)
98                                                 mia->value = Math::rrand(0, 6);
99                                 }
100
101                                 if ((mia->value != 100) && (!(mia->flags & ENT_DYING)))
102                                 {
103                                         static Graphics::SurfaceCache cache;
104                                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
105                                         graphics.drawString(_((char*)mia_scared[mia->value]), x + 10, y - 10, true, graphics.screen, cache);
106                                 }
107
108                                 graphics.blit(mia->getFaceImage(), x, y, graphics.screen, false);
109                                 mia->animate();
110
111                         }
112
113                         if ((Collision::collision(&player, mia)) && (player.health > 0) && (!(player.flags & ENT_TELEPORTING)))
114                         {
115                                 if (!(mia->flags & ENT_DYING))
116                                 {
117                                         Math::addBit(&mia->flags, ENT_WEIGHTLESS);
118                                         Math::addBit(&mia->flags, ENT_DYING);
119                                         audio.playSound(SND_TELEPORT1, CH_ANY, mia->x);
120                                 }
121                         }
122                         
123                         if ((mia->id == MIA_NORMAL) && (mia->environment == ENV_WATER))
124                         {
125                                 mia->id = MIA_AQUA;
126                                 mia->setSprites(graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true));
127                                 debug(("MIA '%s' fell into water. Became Aqua Mia\n", mia->name));
128                         }
129
130                         if (mia->flags & ENT_DYING)
131                         {
132                                 for (int i = 0 ; i < 2 ; i++)
133                                         map.addParticle(mia->x + Math::rrand(-2, 15), mia->y + Math::prand() % mia->height, 0, Math::rrand(-5, -1), Math::rrand(30, 60), graphics.red, graphics.getSprite("TeleportStar", true), PAR_WEIGHTLESS);
134
135                                 if (mia->health <= 100)
136                                         mia->y -= 5;
137
138                                 if (mia->health <= 0)
139                                 {
140                                         map.foundMIAs++;
141                                         game.totalMIAsRescued++;
142
143                                         if ((map.foundMIAs == (map.requiredMIAs / 2)) || (game.skill == 0))
144                                         {
145                                                 snprintf(message, sizeof message, _("Rescued %s - Checkpoint Reached!"), mia->name);
146                                                 game.setObjectiveCheckPoint();
147                                         }
148                                         else
149                                         {
150                                                 snprintf(message, sizeof message, _("Rescued %s!"), mia->name);
151                                         }
152
153                                         if (map.foundMIAs == map.requiredMIAs)
154                                         {
155                                                 snprintf(message, sizeof message, _("Rescue %d MIAs - Objective Complete - Checkpoint Reached!"), map.requiredMIAs);
156                                                 game.setObjectiveCheckPoint();
157                                         }
158                                         
159                                         // MIA Medals
160                                         if (game.totalMIAsRescued == 50)
161                                         {
162                                                 presentPlayerMedal("50_MIA");
163                                         }
164                                         else if (game.totalMIAsRescued == 100)
165                                         {
166                                                 presentPlayerMedal("100_MIA");
167                                         }
168                                         else if (game.totalMIAsRescued == 200)
169                                         {
170                                                 presentPlayerMedal("200_MIA");
171                                         }
172                                         else if (game.totalMIAsRescued == 227)
173                                         {
174                                                 presentPlayerMedal("ALL_MIA");
175                                         }
176
177                                         engine.setInfoMessage(message, 1, INFO_OBJECTIVE);
178                                 }
179                         }
180                 }
181         }
182 }