File: UsableItem.h

package info (click to toggle)
cytadela 1.1.0-4
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, bullseye, buster, stretch
  • size: 82,804 kB
  • ctags: 1,521
  • sloc: cpp: 11,228; sh: 787; makefile: 186
file content (153 lines) | stat: -rw-r--r-- 3,652 bytes parent folder | download | duplicates (5)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
  File name: UsableItem.h
  Copyright: (C) 2007 - 2008 Tomasz Kazmierczak

  Creation date: 24.04.2007
  Last modification date: 15.12.2008

  This file is part of Cytadela

 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program. If not, see <http://www.gnu.org/licenses/>.  *

*/

#ifndef _USABLEITEM_H_
#define _USABLEITEM_H_

#include <stdint.h>
#include <math.h>

typedef enum {
	UIT_HAND,
	UIT_HANDGUN,
	UIT_SHOTGUN,
	UIT_MASHINEGUN,
	UIT_FLAMER,
	UIT_BLASTER,
	UIT_ROCKETLAUNCHER,
	UIT_RED_CARD,
	UIT_GREEN_CARD,
	UIT_BLUE_CARD
} UsableItemType;

typedef enum {
	WPNS_NA = 0,
	WPNS_ACTIVE,
	WPNS_DAMAGED
} WeaponState;

//clsses for item objects
class Item {
protected:
	uint32_t mTakeAmount;

public:
	int32_t  takeSoundNumber;

	Item(uint32_t takeAmount) : mTakeAmount(takeAmount), takeSoundNumber(0) {}

	//get
	uint32_t getTakeAmount() { return mTakeAmount; }
};

class Ammo : public Item {
private:
	uint32_t mAmount;

public:
	Ammo(uint32_t takeAmount);

	uint32_t getAmount() { return mAmount; }
	void setAmount(uint32_t amount);
	void take();
	void use() { mAmount--; }
};

//abstract class for usable items
class UsableItem : public Item {
protected:
	UsableItemType mType;

public:
	int32_t useSoundNumber;

	UsableItem(UsableItemType type, uint32_t takeAmount) :
			Item(takeAmount), mType(type), useSoundNumber(-1) {}
	virtual ~UsableItem() {}

	//get
	UsableItemType getType() { return mType; }
	virtual uint32_t getStatus() = 0;
	virtual uint32_t getAmountForCounter() = 0;
	//set
	virtual void setStatus(uint32_t) = 0;
};

//derivatives of UsableItem
class Hand : public UsableItem {
public:
	Hand() : UsableItem(UIT_HAND, 0) {}
	~Hand() {}

	//get
	uint32_t getStatus() { return WPNS_NA; }
	uint32_t getAmountForCounter() { return 0; }
	//set
	void setStatus(uint32_t) {}
};

class Card : public UsableItem {
public:
	uint32_t cardsCount;

	Card(UsableItemType type) : UsableItem(type, 1), cardsCount(0) {}
	~Card() {}

	//get
	uint32_t getStatus() { return WPNS_NA; }
	uint32_t getAmountForCounter() { return cardsCount; }
	//set
	void setStatus(uint32_t) {}
};

class Weapon : public UsableItem {
private:
	WeaponState mState;
	uint16_t    mBullets;
	uint16_t    mFireCount;
	int16_t     mPower;
	float       mRange;
	Ammo        mAmmo;

public:
	int32_t  fireSoundNumber;
	int32_t  noAmmoSoundNumber;

	Weapon(UsableItemType type, uint16_t bullets, int16_t power, float range, Ammo ammo);
	~Weapon() {}

	//get
	uint32_t getStatus() { return (uint32_t)mState; }
	uint16_t getBullets() { return mBullets; }
	int16_t getPower() { return mPower; }
	float getRange() { return mRange; }
	uint32_t getAmountForCounter() { return mAmmo.getAmount(); }
	Ammo *getAmmo() { return &mAmmo; }
	//set
	void setStatus(uint32_t status);

	void damage(uint16_t minshots, float randomnumber);
};

#endif //_USABLEITEM_H_