]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/mias.cpp
Use UNIX line endings everywhere.
[quix0rs-blobwars.git] / src / mias.cpp
1 /*
2 Copyright (C) 2004 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         strcpy(mia_scared[0], "help me...");
26         strcpy(mia_scared[1], "i don't wanna die...");
27         strcpy(mia_scared[2], "please... someone help...");
28         strcpy(mia_scared[3], "i... i'm scared...");
29         strcpy(mia_scared[4], "i wanna go home...");
30         strcpy(mia_scared[5], "what was that?!");
31         strcpy(mia_scared[6], "i don't like it here...");
32 }
33
34 void addMIA(const char *name, int x, int y, int type)
35 {
36         Entity *mia = new Entity();
37
38         strcpy(mia->name, 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[100];
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                                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
103                                         graphics.drawString(_((char*)mia_scared[mia->value]), x + 10, y - 10, true, graphics.screen);
104                                 }
105
106                                 graphics.blit(mia->getFaceImage(), x, y, graphics.screen, false);
107                                 mia->animate();
108
109                         }
110
111                         if ((Collision::collision(&player, mia)) && (player.health > 0) && (!(player.flags & ENT_TELEPORTING)))
112                         {
113                                 if (!(mia->flags & ENT_DYING))
114                                 {
115                                         Math::addBit(&mia->flags, ENT_WEIGHTLESS);
116                                         Math::addBit(&mia->flags, ENT_DYING);
117                                         audio.playSound(SND_TELEPORT1, CH_ANY);
118                                 }
119                         }
120                         
121                         if ((mia->id == MIA_NORMAL) && (mia->environment == ENV_WATER))
122                         {
123                                 mia->id = MIA_AQUA;
124                                 mia->setSprites(graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true), graphics.getSprite("AquaMIA", true));
125                                 debug(("MIA '%s' fell into water. Became Aqua Mia\n", mia->name));
126                         }
127
128                         if (mia->flags & ENT_DYING)
129                         {
130                                 for (int i = 0 ; i < 2 ; i++)
131                                         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);
132
133                                 if (mia->health <= 100)
134                                         mia->y -= 5;
135
136                                 if (mia->health <= 0)
137                                 {
138                                         map.foundMIAs++;
139                                         game.totalMIAsRescued++;
140
141                                         if ((map.foundMIAs == (map.requiredMIAs / 2)) || (game.skill == 0))
142                                         {
143                                                 sprintf(message, _("Rescued %s - Checkpoint Reached!"), mia->name);
144                                                 game.setObjectiveCheckPoint();
145                                         }
146                                         else
147                                         {
148                                                 sprintf(message, _("Rescued %s!"), mia->name);
149                                         }
150
151                                         if (map.foundMIAs == map.requiredMIAs)
152                                         {
153                                                 sprintf(message, _("Rescue %d MIAs - Objective Complete - Checkpoint Reached!"), map.requiredMIAs);
154                                                 game.setObjectiveCheckPoint();
155                                         }
156
157                                         engine.setInfoMessage(message, 1, INFO_OBJECTIVE);
158                                 }
159                         }
160                 }
161         }
162 }