-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
302 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
[ | ||
{ | ||
"id": "fault_engine_belt_drive", | ||
"type": "fault", | ||
"name": "drive belt", | ||
"description": "Required for operation of an attached alternator.", | ||
"skills": [ [ "mechanics", 2 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH", "level": 1 } ], | ||
"components": [ [ [ "drivebelt", 1 ], [ "leather_belt", 1 ] ] ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_glow_plug", | ||
"type": "fault", | ||
"name": "glow plugs", | ||
"description": "Required to start the vehicle in low ambient tmperatures.", | ||
"skills": [ [ "mechanics", 4 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH_FINE", "level": 1 } ], | ||
"components": [ [ [ "glowplug", 1 ] ] ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_immobiliser", | ||
"type": "fault", | ||
"name": "immobiliser", | ||
"description": "Prevents starting of the vehicle without the appropriate key.", | ||
"skills": [ [ "mechanics", 2 ], [ "electronics", 5 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "SCREW_FINE", "level": 1 } ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_pump_diesel", | ||
"type": "fault", | ||
"name": "diesel pump", | ||
"description": "Required to pump and pressurise diesel from a vehicles tank.", | ||
"skills": [ [ "mechanics", 4 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH_FINE", "level": 1 } ], | ||
"components": [ [ [ "pump_complex", 1 ] ] ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_pump_fuel", | ||
"type": "fault", | ||
"name": "fuel pump", | ||
"description": "Required to pump gasoline from a vehicles tank.", | ||
"skills": [ [ "mechanics", 4 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH_FINE", "level": 1 } ], | ||
"components": [ [ [ "well_pump", 1 ] ] ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_pump_water", | ||
"type": "fault", | ||
"name": "water pump", | ||
"description": "Required to pump water to an external radiator or heatsink.", | ||
"skills": [ [ "mechanics", 4 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH_FINE", "level": 1 } ], | ||
"components": [ [ [ "well_pump", 1 ] ] ] | ||
} | ||
}, | ||
{ | ||
"id": "fault_engine_starter", | ||
"type": "fault", | ||
"name": "starter motor", | ||
"description": "Required to initially start the engine.", | ||
"skills": [ [ "mechanics", 3 ] ], | ||
"requirements": { | ||
"qualities": [ { "id": "WRENCH_FINE", "level": 1 } ], | ||
"components": [ [ [ "motor_small", 1 ] ] ] | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[ | ||
{ | ||
"abstract": "spare_part", | ||
"type": "GENERIC", | ||
"category": "spare_parts", | ||
"name": "spare parts", | ||
"description": "Items with are not themselves useful but are instead requirements for crafting or repairs", | ||
"symbol": ";", | ||
"color": "dark_gray" | ||
}, | ||
{ | ||
"id": "drivebelt", | ||
"copy-from": "spare_part", | ||
"type": "GENERIC", | ||
"name": "drive belt", | ||
"description": "A synthetic rubber V-belt with steel reinforcement fibers commonly fited to engines or other industrial equipment.", | ||
"material": [ "plastic", "steel" ], | ||
"weight": 850, | ||
"volume": 2, | ||
"price": 1200 | ||
}, | ||
{ | ||
"id": "glowplug", | ||
"copy-from": "spare_part", | ||
"type":"GENERIC", | ||
"name": "glow plug", | ||
"description": "A cylindrical heating device designed to be screwed in to a diesel engine to aid starting in cold weather.", | ||
"material": [ "plastic", "copper" ], | ||
"weight": 260, | ||
"volume": 1, | ||
"price": 2300 | ||
}, | ||
{ | ||
"id": "well_pump", | ||
"copy-from": "spare_part", | ||
"type":"GENERIC", | ||
"name": "mechanical pump", | ||
"description": "An simple cast iron mechanical impeller pump. It's not good for much of anything on its own.", | ||
"material": "iron", | ||
"weight": 2400, | ||
"volume": 4, | ||
"price": 1800 | ||
}, | ||
{ | ||
"id": "pump_complex", | ||
"copy-from": "spare_part", | ||
"type":"GENERIC", | ||
"name": "high-pressure pump", | ||
"description": "An complex mechanical pump capable of achieving high pressures. Far beyond anything you could reasonably improvise.", | ||
"material": "iron", | ||
"weight": 2800, | ||
"volume": 5, | ||
"price": 28900 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "fault.h" | ||
|
||
#include "debug.h" | ||
|
||
static std::map<fault_id, fault> faults_all; | ||
|
||
template<> | ||
bool string_id<fault>::is_valid() const | ||
{ | ||
return faults_all.count( *this ); | ||
} | ||
|
||
template<> | ||
const fault &string_id<fault>::obj() const | ||
{ | ||
const auto found = faults_all.find( *this ); | ||
if( found == faults_all.end() ) { | ||
debugmsg( "Tried to get invalid fault: %s", c_str() ); | ||
static const fault null_fault{}; | ||
return null_fault; | ||
} | ||
return found->second; | ||
} | ||
|
||
void fault::load_fault( JsonObject &jo ) | ||
{ | ||
fault f; | ||
|
||
f.id_ = fault_id( jo.get_string( "id" ) ); | ||
f.name_ = jo.get_string( "name" ); | ||
f.description_ = jo.get_string( "description" ); | ||
|
||
auto sk = jo.get_array( "skills" ); | ||
while( sk.has_more() ) { | ||
auto cur = sk.next_array(); | ||
f.skills_.emplace( skill_id( cur.get_string( 0 ) ) , cur.size() >= 2 ? cur.get_int( 1 ) : 1 ); | ||
} | ||
|
||
auto req = jo.get_object( "requirements" ); | ||
f.requirements_.load( req ); | ||
|
||
if( faults_all.find( f.id_ ) != faults_all.end() ) { | ||
jo.throw_error( "parsed fault overwrites existing definition", "id" ); | ||
} else { | ||
faults_all[ f.id_ ] = f; | ||
DebugLog( D_INFO, DC_ALL ) << "Loaded fault: " << f.name_; | ||
} | ||
} | ||
|
||
const std::map<fault_id, fault> &fault::all() | ||
{ | ||
return faults_all; | ||
} | ||
|
||
void fault::reset() | ||
{ | ||
faults_all.clear(); | ||
} | ||
|
||
void fault::check_consistency() | ||
{ | ||
for( const auto &f : faults_all ) { | ||
for( auto &e : f.second.skills_ ) { | ||
if( !e.first.is_valid() ) { | ||
debugmsg( "fault %s has unknown skill %s", f.second.id_.c_str(), e.first.c_str() ); | ||
} | ||
} | ||
f.second.requirements_.check_consistency( f.second.id_.c_str() ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef FAULT_H | ||
#define FAULT_H | ||
|
||
#include "string_id.h" | ||
#include "requirements.h" | ||
#include "json.h" | ||
|
||
class fault; | ||
using fault_id = string_id<fault>; | ||
|
||
class Skill; | ||
using skill_id = string_id<Skill>; | ||
|
||
class fault | ||
{ | ||
public: | ||
fault() : id_( fault_id( "null" ) ) {} | ||
|
||
const fault_id &id() const { | ||
return id_; | ||
} | ||
|
||
bool is_null() const { | ||
return id_ == fault_id( "null" ); | ||
} | ||
|
||
const std::string &name() const { | ||
return name_; | ||
} | ||
|
||
const std::string &description() const { | ||
return description_; | ||
} | ||
|
||
const std::map<skill_id, int> &skills() const { | ||
return skills_; | ||
} | ||
|
||
const requirement_data &requirements() const { | ||
return requirements_; | ||
} | ||
|
||
/** Load fault from JSON definition */ | ||
static void load_fault( JsonObject &jo ); | ||
|
||
/** Get all currently loaded faults */ | ||
static const std::map<fault_id, fault> &all(); | ||
|
||
/** Clear all loaded faults (invalidating any pointers) */ | ||
static void reset(); | ||
|
||
/** Checks all loaded from JSON are valid */ | ||
static void check_consistency(); | ||
|
||
private: | ||
fault_id id_; | ||
std::string name_; | ||
std::string description_; | ||
std::map<skill_id, int> skills_; | ||
requirement_data requirements_; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.