-
Notifications
You must be signed in to change notification settings - Fork 3
/
Weapon.go
164 lines (138 loc) · 4.63 KB
/
Weapon.go
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
154
155
156
157
158
159
160
161
162
163
164
package externalballistics
import "github.com/gehtsoft-usa/go_ballisticcalc/bmath/unit"
//ZeroInfo structure keeps the information about zeroing of the weapon
type ZeroInfo struct {
hasAmmunition bool
ammunition Ammunition
zeroDistance unit.Distance
hasAtmosphere bool
zeroAtmosphere Atmosphere
}
//HasAmmunition return flag indicating whether other ammo is used to zero
func (v ZeroInfo) HasAmmunition() bool {
return v.hasAmmunition
}
//Ammunition return ammo used to zero
func (v ZeroInfo) Ammunition() Ammunition {
return v.ammunition
}
//HasAtmosphere returns flag indicating whether weapon is zeroed under different conditions
func (v ZeroInfo) HasAtmosphere() bool {
return v.hasAtmosphere
}
//Atmosphere returns conditions at the time of zeroing
func (v ZeroInfo) Atmosphere() Atmosphere {
return v.zeroAtmosphere
}
//ZeroDistance returns the distance at which the weapon was zeroed
func (v ZeroInfo) ZeroDistance() unit.Distance {
return v.zeroDistance
}
//CreateZeroInfo creates zero information using distance only
func CreateZeroInfo(distance unit.Distance) ZeroInfo {
return ZeroInfo{
hasAmmunition: false,
hasAtmosphere: false,
zeroDistance: distance,
}
}
//CreateZeroInfoWithAtmosphere creates zero information using distance and conditions
func CreateZeroInfoWithAtmosphere(distance unit.Distance, atmosphere Atmosphere) ZeroInfo {
return ZeroInfo{
hasAmmunition: false,
hasAtmosphere: true,
zeroAtmosphere: atmosphere,
zeroDistance: distance,
}
}
//CreateZeroInfoWithAnotherAmmo creates zero information using distance and other ammunition
func CreateZeroInfoWithAnotherAmmo(distance unit.Distance, ammo Ammunition) ZeroInfo {
return ZeroInfo{
hasAmmunition: true,
ammunition: ammo,
hasAtmosphere: false,
zeroDistance: distance,
}
}
//CreateZeroInfoWithAnotherAmmoAndAtmosphere creates zero information using distance, other conditions and other ammunition
func CreateZeroInfoWithAnotherAmmoAndAtmosphere(distance unit.Distance, ammo Ammunition, atmosphere Atmosphere) ZeroInfo {
return ZeroInfo{
hasAmmunition: true,
ammunition: ammo,
hasAtmosphere: true,
zeroAtmosphere: atmosphere,
zeroDistance: distance,
}
}
//TwistRight is the flag indiciating that the barrel is right-hand twisted
const TwistRight byte = 1
//TwistLeft is the flag indiciating that the barrel is left-hand twisted
const TwistLeft byte = 2
//TwistInfo contains the rifling twist information
//
//The rifling twist is used to calculate spin drift only
type TwistInfo struct {
twistDirection byte
riflingTwist unit.Distance
}
//CreateTwist creates twist information
//
//Direction must be either Twist_Right or Twist_Left constant
func CreateTwist(direction byte, twist unit.Distance) TwistInfo {
return TwistInfo{
twistDirection: direction,
riflingTwist: twist,
}
}
//Direction returns the twist direction (see TwistRight and TwistLeft)
func (v TwistInfo) Direction() byte {
return v.twistDirection
}
//Twist returns the twist step (the distance inside the barrel at which the projectile makes one turn)
func (v TwistInfo) Twist() unit.Distance {
return v.riflingTwist
}
//Weapon struct contains the weapon description
type Weapon struct {
sightHeight unit.Distance
zeroInfo ZeroInfo
hasTwistInfo bool
twist TwistInfo
clickValue unit.Angular
}
//SightHeight returns the height of the sight centerline over the barrel centerline
func (v Weapon) SightHeight() unit.Distance {
return v.sightHeight
}
//Zero returns the zeroing information
func (v Weapon) Zero() ZeroInfo {
return v.zeroInfo
}
//HasTwist returns the flag indicating whether the rifling twist information is set
func (v Weapon) HasTwist() bool {
return v.hasTwistInfo
}
//Twist returns the rifling twist information
func (v Weapon) Twist() TwistInfo {
return v.twist
}
//ClickValue returns the value of one click of the scope
func (v Weapon) ClickValue() unit.Angular {
return v.clickValue
}
//SetClickValue sets the value of one click of the scope
func (v *Weapon) SetClickValue(click unit.Angular) {
v.clickValue = click
}
//CreateWeapon creates the weapon definition with no twist info
//
//If no twist info is set, spin drift won't be calculated
func CreateWeapon(sightHeight unit.Distance, zeroInfo ZeroInfo) Weapon {
return Weapon{sightHeight: sightHeight, zeroInfo: zeroInfo, hasTwistInfo: false}
}
//CreateWeaponWithTwist creates weapon description with twist info
//
//If twist info AND bullet dimensions are set, spin drift will be calculated
func CreateWeaponWithTwist(sightHeight unit.Distance, zeroInfo ZeroInfo, twist TwistInfo) Weapon {
return Weapon{sightHeight: sightHeight, zeroInfo: zeroInfo, hasTwistInfo: true, twist: twist}
}