aboutsummaryrefslogtreecommitdiff
path: root/src/script.hh
blob: 0a831961c086ad540b81c5014e6992c223862f81 (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
97
98
99
100
101
102
103
104
#ifndef TIBIA_SCRIPT_HH_
#define TIBIA_SCRIPT_HH_ 1

#include "common.hh"
#include "enums.hh"

struct TReadScriptFile {
	// REGULAR FUNCTIONS
	// =========================================================================
	TReadScriptFile(void);
	~TReadScriptFile(void);
	void open(const char *FileName);
	void close(void);
	void error(const char *Text);
	void nextToken(void);
	char *getIdentifier(void);
	int getNumber(void);
	char *getString(void);
	uint8 *getBytesequence(void);
	void getCoordinate(int *x, int *y, int *z);
	char getSpecial(void);

	char *readIdentifier(void){
		this->nextToken();
		return this->getIdentifier();
	}

	int readNumber(void){
		this->nextToken();

		int Sign = 1;
		if(this->Token == SPECIAL && this->Special == '-'){
			Sign = -1;
			this->nextToken();
		}

		return Sign * this->getNumber();
	}

	char *readString(void){
		this->nextToken();
		return this->getString();
	}

	uint8 *readBytesequence(void){
		this->nextToken();
		return this->getBytesequence();
	}

	void readCoordinate(int *x, int *y, int *z){
		this->nextToken();
		this->getCoordinate(x, y, z);
	}

	char readSpecial(void){
		this->nextToken();
		return this->getSpecial();
	}

	void TReadScriptFile::readSymbol(char Symbol){
		if(this->readSpecial() != Symbol){
			this->error("symbol mismatch");
		}
	}

	// DATA
	// =========================================================================
	TOKEN Token;
	FILE *File[3];
	char Filename[3][4096];
	int Line[3];
	char String[4000];
	int RecursionDepth;
	uint8 *Bytes;
	int Number;
	int CoordX;
	int CoordY;
	int CoordZ;
	char Special;
};

struct TWriteScriptFile {
	// REGULAR FUNCTIONS
	// =========================================================================
	TWriteScriptFile(void);
	~TWriteScriptFile(void);
	void open(char *FileName);
	void close(void);
	void error(char *Text);
	void writeLn(void);
	void writeText(char *Text);
	void writeNumber(int Number);
	void writeString(char *Text);
	void writeCoordinate(int x ,int y ,int z);
	void writeBytesequence(uint8 *Sequence, int Length);

	// DATA
	// =========================================================================
	FILE *File;
	char Filename[4096];
	int Line;
};

#endif //TIBIA_SCRIPT_HH_