• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CleverRaven / Cataclysm-DDA / 13110

pending completion
13110

Pull #26722

travis-ci

web-flow
Arbitrary number of spaces between summary parts.

I think they are rendered to one space character in html view, what makes almost impossible to see it.
Pull Request #26722: Arbitrary number of spaces between summary parts

31305 of 118137 relevant lines covered (26.5%)

97567.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/veh_type.h
1
#pragma once
2
#ifndef VEH_TYPE_H
3
#define VEH_TYPE_H
4

5
#include "calendar.h"
6
#include "color.h"
7
#include "damage.h"
8
#include "enums.h"
9
#include "optional.h"
10
#include "string_id.h"
11
#include "units.h"
12

13
#include <array>
14
#include <bitset>
15
#include <map>
16
#include <memory>
17
#include <string>
18
#include <set>
19
#include <utility>
20
#include <vector>
21

22
using itype_id = std::string;
23

24
class vpart_info;
25
using vpart_id = string_id<vpart_info>;
26
struct vehicle_prototype;
27
using vproto_id = string_id<vehicle_prototype>;
28
class vehicle;
29
class JsonObject;
30
struct vehicle_item_spawn;
31
struct quality;
32
using quality_id = string_id<quality>;
33
class Character;
34

35
struct requirement_data;
36
using requirement_id = string_id<requirement_data>;
37

38
class Skill;
39
using skill_id = string_id<Skill>;
40

41
// bitmask backing store of -certain- vpart_info.flags, ones that
42
// won't be going away, are involved in core functionality, and are checked frequently
43
enum vpart_bitflags : int {
44
    VPFLAG_ARMOR,
45
    VPFLAG_EVENTURN,
46
    VPFLAG_ODDTURN,
47
    VPFLAG_CONE_LIGHT,
48
    VPFLAG_CIRCLE_LIGHT,
49
    VPFLAG_BOARDABLE,
50
    VPFLAG_AISLE,
51
    VPFLAG_CONTROLS,
52
    VPFLAG_OBSTACLE,
53
    VPFLAG_OPAQUE,
54
    VPFLAG_OPENABLE,
55
    VPFLAG_SEATBELT,
56
    VPFLAG_WHEEL,
57
    VPFLAG_MOUNTABLE,
58
    VPFLAG_FLOATS,
59
    VPFLAG_DOME_LIGHT,
60
    VPFLAG_AISLE_LIGHT,
61
    VPFLAG_ATOMIC_LIGHT,
62
    VPFLAG_ALTERNATOR,
63
    VPFLAG_ENGINE,
64
    VPFLAG_FRIDGE,
65
    VPFLAG_FREEZER,
66
    VPFLAG_LIGHT,
67
    VPFLAG_WINDOW,
68
    VPFLAG_CURTAIN,
69
    VPFLAG_CARGO,
70
    VPFLAG_INTERNAL,
71
    VPFLAG_SOLAR_PANEL,
72
    VPFLAG_RECHARGE,
73
    VPFLAG_EXTENDS_VISION,
74
    VPFLAG_ENABLED_DRAINS_EPOWER,
75
    VPFLAG_WASHING_MACHINE,
76
    VPFLAG_FLUIDTANK,
77

78
    NUM_VPFLAGS
79
};
80
/* Flag info:
81
 * INTERNAL - Can be mounted inside other parts
82
 * ANCHOR_POINT - Allows secure seatbelt attachment
83
 * OVER - Can be mounted over other parts
84
 * MOUNTABLE - Usable as a point to fire a mountable weapon from.
85
 * E_COLD_START - Cold weather makes the engine take longer to start
86
 * E_STARTS_INSTANTLY - The engine takes no time to start, like foot pedals
87
 * E_ALTERNATOR - The engine can mount and power an alternator
88
 * E_COMBUSTION - The engine burns fuel to provide power and can burn or explode
89
 * E_HIGHER_SKILL - Multiple engines with this flag are harder to install
90
 * Other flags are self-explanatory in their names. */
91

92
struct vpslot_engine {
93
    float backfire_threshold = 0;
94
    int backfire_freq = 1;
95
    int muscle_power_factor = 0;
96
    float damaged_power_factor = 0;
97
    int noise_factor = 0;
98
    int m2c = 1;
99
    std::vector<std::string> exclusions;
100
};
101

102
class vpart_info
103
{
104
    private:
105
        /** Unique identifier for this part */
106
        vpart_id id;
107

108
        cata::optional<vpslot_engine> engine_info;
109

110
    public:
111
        /** Translated name of a part */
112
        std::string name() const;
113

114
        vpart_id get_id() const {
115
            return id;
×
116
        }
117

118
        /** base item for this part */
119
        itype_id item;
120

121
        /** What slot of the vehicle tile does this part occupy? */
122
        std::string location;
123

124
        /** Color of part for different states */
125
        nc_color color = c_light_gray;
126
        nc_color color_broken = c_light_gray;
127

128
        /**
129
         * Symbol of part which will be translated as follows:
130
         * y, u, n, b to NW, NE, SE, SW lines correspondingly
131
         * h, j, c to horizontal, vertical, cross correspondingly
132
         */
133
        long sym = 0;
134
        char sym_broken = '#';
135

136
        /** hint to tilesets for what tile to use if this part doesn't have one */
137
        std::string looks_like;
138

139
        /** Maximum damage part can sustain before being destroyed */
140
        int durability = 0;
141

142
        /** A text description of the part as a vehicle part */
143
        std::string description;
144

145
        /** Damage modifier (percentage) used when damaging other entities upon collision */
146
        int dmg_mod = 100;
147

148
        /**
149
         * Electrical power, flat rate (watts); positive for generation, negative for consumption
150
         * For motor consumption scaled with powertrain demand see @ref energy_consumption instead
151
         */
152
        int epower = 0;
153

154
        /**
155
         * Energy consumed by engines and motors (TODO: units?) when delivering max @ref power
156
         * Includes waste. Gets scaled based on powertrain demand.
157
         */
158
        int energy_consumption = 0;
159

160
        /**
161
         * For engines and motors this is maximum output (TODO: units?)
162
         * For alternators is engine power consumed (negative value)
163
         */
164
        int power = 0;
165

166
        /** Fuel type of engine or tank */
167
        itype_id fuel_type = "null";
168

169
        /** Default ammo (for turrets) */
170
        itype_id default_ammo = "null";
171

172
        /** Volume of a foldable part when folded */
173
        units::volume folded_volume = 0;
174

175
        /** Cargo location volume */
176
        units::volume size = 0;
177

178
        /** Mechanics skill required to install item */
179
        int difficulty = 0;
180

181
        /** Legacy parts don't specify installation requirements */
182
        bool legacy = true;
183

184
        /** Format the description for display */
185
        int format_description( std::ostringstream &msg, const std::string &format_color, int width ) const;
186

187
        /** Installation requirements for this component */
188
        requirement_data install_requirements() const;
189

190
        /** Required skills to install this component */
191
        std::map<skill_id, int> install_skills;
192

193
        /** Installation time (in moves) for component (@see install_time), default 1 hour */
194
        int install_moves = to_moves<int>( 1_hours );
195

196
        /** Installation time (in moves) for this component accounting for player skills */
197
        int install_time( const Character &ch ) const;
198

199
        /** Requirements for removal of this component */
200
        requirement_data removal_requirements() const;
201

202
        /** Required skills to remove this component */
203
        std::map<skill_id, int> removal_skills;
204

205
        /** Removal time (in moves) for component (@see removal_time), default is half @ref install_moves */
206
        int removal_moves = -1;
207

208
        /** Removal time (in moves) for this component accounting for player skills */
209
        int removal_time( const Character &ch ) const;
210

211
        /** Requirements for repair of this component (per level of damage) */
212
        requirement_data repair_requirements() const;
213

214
        /** Returns whether or not the part is repairable  */
215
        bool is_repairable() const;
216

217
        /** Required skills to repair this component */
218
        std::map<skill_id, int> repair_skills;
219

220
        /** Repair time (in moves) to fully repair a component (@see repair_time) */
221
        int repair_moves = to_moves<int>( 1_hours );
222

223
        /** Repair time (in moves) to fully repair this component, accounting for player skills */
224
        int repair_time( const Character &ch ) const;
225

226
        /** @ref item_group this part breaks into when destroyed */
227
        std::string breaks_into_group = "EMPTY_GROUP";
228

229
        /** Tool qualities this vehicle part can provide when installed */
230
        std::map<quality_id, int> qualities;
231

232
        /** seatbelt (str), muffler (%), horn (vol), light (intensity) */
233
        int bonus = 0;
234

235
        /** Flat decrease of damage of a given type. */
236
        std::array<float, NUM_DT> damage_reduction;
237

238
        /**
239
         * @name Engine specific functions
240
         *
241
         */
242
        std::vector<std::string> engine_excludes() const;
243
        int engine_m2c() const;
244
        float engine_backfire_threshold() const;
245
        int engine_backfire_freq() const;
246
        int engine_muscle_power_factor() const;
247
        float engine_damaged_power_factor() const;
248
        int engine_noise_factor() const;
249
    private:
250
        /** Name from vehicle part definition which if set overrides the base item name */
251
        mutable std::string name_;
252

253
        std::set<std::string> flags;    // flags
254
        std::bitset<NUM_VPFLAGS> bitflags; // flags checked so often that things slow down due to string cmp
255

256
        /** Second field is the multiplier */
257
        std::vector<std::pair<requirement_id, int>> install_reqs;
258
        std::vector<std::pair<requirement_id, int>> removal_reqs;
259
        std::vector<std::pair<requirement_id, int>> repair_reqs;
260

261
    public:
262

263
        int z_order;        // z-ordering, inferred from location, cached here
264
        int list_order;     // Display order in vehicle interact display
265

266
        bool has_flag( const std::string &flag ) const {
×
267
            return flags.count( flag ) != 0;
×
268
        }
269
        bool has_flag( const vpart_bitflags flag ) const {
270
            return bitflags.test( flag );
271
        }
272
        void set_flag( const std::string &flag );
273

274
        static void load_engine( cata::optional<vpslot_engine> &eptr, JsonObject &jo );
275
        static void load( JsonObject &jo, const std::string &src );
276
        static void finalize();
277
        static void check();
278
        static void reset();
279

280
        static const std::map<vpart_id, vpart_info> &all();
281
};
282

283
struct vehicle_item_spawn {
284
    point pos;
285
    int chance;
286
    /** Chance [0-100%] for items to spawn with ammo (plus default magazine if necessary) */
287
    int with_ammo = 0;
288
    /** Chance [0-100%] for items to spawn with their default magazine (if any) */
289
    int with_magazine = 0;
290
    std::vector<itype_id> item_ids;
291
    std::vector<std::string> item_groups;
292
};
293

294
/**
295
 * Prototype of a vehicle. The blueprint member is filled in during the finalizing, before that it
296
 * is a nullptr. Creating a new vehicle copies the blueprint vehicle.
297
 */
298
struct vehicle_prototype {
299
    struct part_def {
300
        point pos;
301
        vpart_id part;
302
        int with_ammo = 0;
303
        std::set<itype_id> ammo_types;
304
        std::pair<int, int> ammo_qty = { -1, -1 };
305
        itype_id fuel = "null";
306
    };
307

308
    std::string name;
309
    std::vector<part_def> parts;
310
    std::vector<vehicle_item_spawn> item_spawns;
311

312
    std::unique_ptr<vehicle> blueprint;
313

314
    static void load( JsonObject &jo );
315
    static void reset();
316
    static void finalize();
317

318
    static std::vector<vproto_id> get_all();
319
};
320

321
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc