aboutsummaryrefslogtreecommitdiffstats
path: root/src/entity.h
blob: 65e5b2a5b8649de9966353ce94e0cdade794bb02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "utils.h"

// Pretty much any object in the game.

#ifndef ENTITY_H
#define ENTITY_H

#define ENTITY_COUNT 14

#define INTERACTION_MENU_MAX 9
#define INTERACTION_LABEL_MAX 64
#define ENTITY_DEFAULT_STATE -1

typedef int8_t EntityId;
typedef int16_t EntityState;
typedef enum InteractionCommand InteractionCommand;
typedef enum Selection Selection;

typedef struct Entity Entity;

typedef InteractionCommand (*InteractionCallback)(Entity* entity, Game* game,
                                                  Selection selection);
typedef void (*InitEntityCallback)(Entity* entity);
typedef void (*UpdateEntityCallback)(Entity* entity, Game* game);
typedef void (*CloseEntityCallback)(Entity* entity);

enum {
  ENTITY_NONE = -1,
  OLD_MINT,
  STICKY_NICKEL,
  TREE,
  BUSH,
  FLOWER,
  POND,
  UTILITY_POLE,
  SAMANTHA,
  SAMANTHAS_SPOT,
  TRASHCAN,
  TRASH,
  MEDICAL_TRASH,
  JOHN,
  RON
};

enum InteractionCommand {
  INTERACTION_END,
  INTERACTION_TALK,
  INTERACTION_SHOW_MENU,
};

enum Selection {
  SELECTION_INTERACT,
  SELECTION_NEXT_MESSAGE,
  SELECTION_MENU_ITEM, // +x to select any given menu entry
  SELECTION_LEAVE
};

struct Entity {
  EntityId id;
  Vector3 position; // Shouldnt be changed directly.
  BoundingBox box;
  EntityState state;
  void* data;
};

typedef struct {
  InitEntityCallback initCallback;
  UpdateEntityCallback updateCallback;
  CloseEntityCallback closeCallback;
  InteractionCallback interactionCallback;
  bool isPlace;
  bool canBeSelected;
} EntityEntry;

// Am I still insane if I am aware of my insanity?

extern const EntityEntry entityEntries[ENTITY_COUNT];

Entity createEntity(EntityId id, Vector3 position);
void updateEntity(Entity* entity, Game* game);
void closeEntity(Entity* entity);

void setEntityPosition(Entity* entity, Vector3 position);
void placeEntityOnGround(Entity* entity, const World* world);

bool entityIsPlace(EntityId id);
bool entityCanBeSelected(EntityId id);

float getEntityDistance(Entity entity, Vector3 position);

InteractionCommand interactWithEntity(Entity* entity, Game* game,
                                      Selection selection);

BoundingBox entityBoxFromScale(float scale, float width, float height);

#endif