Debian Codegraph @

src/cdogs/thing.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4
5 Copyright (c) 2013-2019 Cong Xu
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11 Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13 Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 */
29 #pragma once
30
31 #include <stdbool.h>
32
33 #include "c_array.h"
34 #include "cpic.h"
35 #include "mathc/mathc.h"
36 #include "pic.h"
37 #include "proto/msg.pb.h"
38 #include "vector.h"
39
40 typedef enum
41 {
42 KIND_CHARACTER,
43 KIND_PARTICLE,
44 KIND_MOBILEOBJECT,
45 KIND_OBJECT,
46 KIND_PICKUP
47 } ThingKind;
48
49 #define THING_IMPASSABLE 1
50 #define THING_CAN_BE_SHOT 2
51 #define THING_OBJECTIVE (8 + 16 + 32 + 64 + 128)
52 #define THING_DRAW_BELOW 256
53 #define THING_DRAW_ABOVE 512
54 #define OBJECTIVE_SHIFT 3
55
56
57 typedef struct
58 {
59 int MobObjId;
60 struct vec2 Scale;
61 union
62 {
63 struct
64 {
65 const CArray *Sprites;
66 direction_e Dir;
67 color_t Color;
68 } MuzzleFlash;
69 } u;
70 } ThingDrawFuncData;
71 typedef void (*ThingDrawFunc)(const struct vec2i, const ThingDrawFuncData *);
72 typedef struct
73 {
74 struct vec2 Pos;
75 struct vec2 LastPos;
76 struct vec2 Vel;
77 struct vec2i size;
78 ThingKind kind;
79 int id; // Id of item (actor, mobobj or obj)
80 int flags;
81 ThingDrawFunc drawFunc;
82 ThingDrawFuncData drawData;
83 CPic CPic;
84 DrawCPicFunc CPicFunc;
85 struct vec2 drawShake;
86 struct vec2i ShadowSize;
87 int SoundLock;
88 } Thing;
89 #define SOUND_LOCK_THING 12
90
91
92 typedef struct
93 {
94 // TODO: add an entity id system
95 int Id;
96 ThingKind Kind;
97 } ThingId;
98
99
100 bool IsThingInsideTile(const Thing *i, const struct vec2i tilePos);
101
102 void ThingInit(
103 Thing *t, const int id, const ThingKind kind, const struct vec2i size,
104 const int flags);
105 void ThingUpdate(Thing *t, const int ticks);
106 void ThingAddDrawShake(Thing *t, const struct vec2 shake);
107 void ThingDamage(const NThingDamage d);
108
109 Thing *ThingGetByUID(const ThingKind kind, const int uid);
110 Thing *ThingIdGetThing(const ThingId *tid);
111 bool ThingDrawBelow(const Thing *t);
112 bool ThingDrawAbove(const Thing *t);