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