File: FireCommand.h

package info (click to toggle)
endless-sky 0.10.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 414,608 kB
  • sloc: cpp: 73,435; python: 893; xml: 666; sh: 271; makefile: 28
file content (60 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download
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
/* FireCommand.h
Copyright (c) 2021 by Michael Zahniser

Endless Sky 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.

Endless Sky 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 <https://www.gnu.org/licenses/>.
*/

#pragma once

#include "Bitset.h"

#include <cstdint>
#include <vector>



// Class that represents firing commands from ships, which includes
// whether a weapon is currently firing and its turn (if any).
class FireCommand {
public:
	// Sets the specified amount of hardpoints desired.
	void SetHardpoints(size_t count);

	// Assigns the subset of other to this class that is no larger than
	// this command's hardpoint size.
	void UpdateWith(const FireCommand &other) noexcept;

	// Reset this to an empty command.
	void Clear();

	// Get or set the fire commands.
	bool HasFire(int index) const noexcept;
	void SetFire(int index) noexcept;
	// Check if any weapons are firing.
	bool IsFiring() const noexcept;
	// Gets the current turn rate of the turret at the given weapon index.
	double Aim(int index) const noexcept;
	// Set the turn rate of the turret with the given weapon index. A value of
	// -1 or 1 means to turn at the full speed the turret is capable of.
	void SetAim(int index, double amount) noexcept;


private:
	bool IsIndexValid(int index) const noexcept;


private:
	// The weapon commands stores whether the given weapon is active.
	Bitset weapon;
	// Turret turn rates, reduced to 8 bits to save space.
	std::vector<signed char> aim;
};