1 /*
2 Copyright (C) 2009-2021 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, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19
20 #include "../headers.h"
21
22 #include "../collisions.h"
23 #include "../entity.h"
24 #include "../event/script.h"
25 #include "../graphics/animation.h"
26 #include "../hud.h"
27 #include "../system/error.h"
28 #include "../system/properties.h"
29
30 extern Entity *self;
31 extern Game game;
32
33 static void entityWait(void);
34 static void talk(int);
35 static void touch(Entity *);
36
addNPC(char * name,int x,int y)37 Entity *addNPC(char *name, int x, int y)
38 {
39 Entity *e = getFreeEntity();
40
41 if (e == NULL)
42 {
43 showErrorAndExit("No free slots to add %s", name);
44 }
45
46 loadProperties(name, e);
47
48 e->x = x;
49 e->y = y;
50
51 e->action = &entityWait;
52
53 e->draw = &drawLoopingAnimationToMap;
54 e->activate = &talk;
55 e->touch = &touch;
56
57 e->type = NPC;
58
59 setEntityAnimation(e, "STAND");
60
61 return e;
62 }
63
entityWait()64 static void entityWait()
65 {
66 checkToMap(self);
67 }
68
talk(int val)69 static void talk(int val)
70 {
71 runScript(self->requires);
72 }
73
touch(Entity * other)74 static void touch(Entity *other)
75 {
76 if (other->type == PLAYER && game.showHints == TRUE)
77 {
78 setInfoBoxMessage(0, 255, 255, 255, _("Press Action to talk to %s"), _(self->objectiveName));
79 }
80 }
81