-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.h
125 lines (121 loc) · 2.71 KB
/
settings.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include <stdlib.h> // malloc
#include <sys/stat.h> // fifo
#include <fcntl.h> // open
#include <unistd.h> // read, close, unlink
#include <string.h> // strcpy
#include <time.h> // time, difftime
#include <errno.h> // errno
#include <math.h> // floor
#include <signal.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/wait.h>
#define NAME_MAX_LENGTH 20
#define GAME_READY_SEM_KEY 1000
#define FIFO_ACCESS_SEM_KEY 1001
#define STDMSG_MAX_LENGTH 50
#define PLAYER_ATTRIBUTES_NUMBER 6
#define NUMBER_OF_UNIT_TYPES 4
#define TRAINING_QUEUE_CAPACITY 50
#define BATTLES_QUEUE_CAPACITY 20
#define MSGTYPE_ENDGAME 5
#define MSGTYPE_BATTLE 6
#define MSGTYPE_STATUS 7
#define MSGTYPE_TRAIN 10
#define MSGTYPE_ATTACK 11
struct stdMsg {
long type;
char text[STDMSG_MAX_LENGTH];
};
struct nameBuf {
long type;
char name[NAME_MAX_LENGTH];
};
struct unitsStruct {
int workers;
int lightInfantry;
int heavyInfantry;
int cavalry;
};
struct enemy {
int id;
char name[NAME_MAX_LENGTH];
};
struct enemyMsg {
long type;
struct enemy enemy;
};
struct commandMsg {
long type;
short id;
short amount;
};
struct commandBattle {
long type;
short target;
struct unitsStruct units;
};
struct unitDetails {
unsigned short id;
unsigned short cost;
unsigned short attack;
unsigned short defence;
unsigned short produceTime;
};
struct battleStruct {
int wonBy;
int attackerId;
struct unitsStruct attackerUnits;
struct unitsStruct attackerSurvived;
int defenderId;
struct unitsStruct defenderUnits;
struct unitsStruct defenderSurvived;
};
struct playerStruct {
char name[NAME_MAX_LENGTH];
int mid;
unsigned int gold;
// struct unitsStruct unitsHome;
int unitsHome[NUMBER_OF_UNIT_TYPES];
unsigned short attacksWon;
unsigned short battlesWon;
unsigned short battlesLost;
};
struct playerStatusStruct {
// long type;
unsigned int gold;
struct unitsStruct unitsHome;
// int *unitsHome;
unsigned short attacksWon;
unsigned short battlesWon;
unsigned short battlesLost;
};
struct unitsAmountStruct {
time_t timer;
int id;
int amount;
};
struct trainingQueue {
int head;
struct unitsAmountStruct array[TRAINING_QUEUE_CAPACITY];
};
struct battlesQueue {
int head;
time_t arrivingAt[BATTLES_QUEUE_CAPACITY];
int from[BATTLES_QUEUE_CAPACITY];
struct unitsStruct array[BATTLES_QUEUE_CAPACITY];
};
union serverMsgUnion {
struct playerStatusStruct status;
int endgame;
struct battleStruct battle;
};
struct serverMsg {
long type;
union serverMsgUnion data;
};
#endif