Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Real-time engine tweaking via 👼Script - with example. #3177

Merged
merged 12 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion doc/angelscript/Script2Game/BeamClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ class BeamClass
/**
* Retrieve the waypoint AI object.
*/
VehicleAiClass getVehicleAI();
VehicleAiClass @getVehicleAI();


/**
* Retrieve engine/transmission simulator.
*/
EngineClassPtr @getEngine();

//! @}

Expand Down
134 changes: 134 additions & 0 deletions doc/angelscript/Script2Game/EngineClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

namespace Script2Game {

/** \addtogroup ScriptSideAPIs
* @{
*/

/** \addtogroup Script2Game
* @{
*/

enum autoswitch
{
REAR,
NEUTRAL,
DRIVE,
TWO,
ONE,
MANUALMODE
};

/**
* @brief Binding of RoR::EngineSim; A land vehicle engine + transmission
* @note Obtain the object using `BeamClass::getEngine()`.
*/
class EngineSimClass
{
public:

/// @name Definition; keyword 'engine'
/// @{
float getMinRPM() const; //!< Shift down RPM ('engine' attr #1)
float getMaxRPM() const; //!< Shift up RPM ('engine' attr #2)
float getEngineTorque() const; //!< Torque in N/m ('engine' attr #3)
float getDiffRatio() const; //!< Global gear ratio ('engine' attr #4)
float getGearRatio(int pos); //!< -1=R, 0=N, 1... ('engine' attrs #5[R],#6[N],#7[1]...)
int getNumGears() const;
int getNumGearsRanges() const;
/// @}

/// @name Definition, Keyword 'engoption'
/// @{
float getEngineInertia() const; //!< ('engoption' attr #1)
char getEngineType() const; //!< 't' = truck (default), 'c' = car, 'e' = electric car ('engoption' attr #2)
bool isElectric() const;
bool hasAir() const;
bool hasTurbo() const;
float getClutchForce() const; //!< ('engoption' attr #3)
float getShiftTime() const; //!< Time (in seconds) that it takes to shift ('engoption' attr #4)
float getClutchTime() const; //!< Time (in seconds) the clutch takes to apply ('engoption' attr #5)
float getPostShiftTime() const; //!< Time (in seconds) until full torque is transferred ('engoption' attr #6)
float getStallRMP() const; //!< ('engoption' attr #7)
float getIdleRPM() const; //!< ('engoption' attr #8)
float getMaxIdleMixture() const; //!< Maximum throttle to maintain the idle RPM ('engoption' attr #9)
float getMinIdleMixture() const; //!< Minimum throttle to maintain the idle RPM ('engoption' attr #10)
float getBrakingTorque() const;
/// @}

/// @name General state getters
/// @{
float getAcc();
float getClutch();
float getCrankFactor();
float getRPM();
float getSmoke();
float getTorque();
float getTurboPSI();
SimGearboxMode getAutoMode();
int getGear();
int getGearRange();
bool isRunning();
bool hasContact(); //!< Ignition
float getEngineTorque();
float getInputShaftRPM();
float getDriveRatio();
float getEnginePower();
float getEnginePower(float rpm);
float getTurboPower();
float getIdleMixture();
float getPrimeMixture();
autoswitch getAutoShift();
float getAccToHoldRPM(); //!< estimate required throttle input to hold the current rpm
float getWheelSpin(); //!< Current wheel RPM
/// @}

/// @name Shifting diagnostic
/// @{
float getPostShiftClock();
float getShiftClock();
bool isPostShifting();
bool isShifting();
int getShifTargetGear();
float getAutoShiftBehavior();
int getUpshiftDelayCounter();
int getKickdownDelayCounter();
/// @}

/// @name General state changes
/// @{
void pushNetworkState(float engine_rpm, float acc, float clutch, int gear, bool running, bool contact, char auto_mode, char auto_select = -1);
void setAcc(float val);
void autoSetAcc(float val);
void setClutch(float clutch);
void setRPM(float rpm);
void setWheelSpin(float rpm);
void setAutoMode(SimGearboxMode mode);
void setPrime(bool p);
void setHydroPump(float work);
void setManualClutch(float val);
void setTCaseRatio(float ratio); //!< Set current transfer case gear (reduction) ratio
void toggleContact(); //!< Ignition
void offStart(); //!< Quick start of vehicle engine.
void startEngine(); //!< Quick engine start. Plays sounds.
void stopEngine(); //!< stall engine
/// @}

/// @name Shifting
/// @{
void toggleAutoMode();
void autoShiftDown();
void autoShiftSet(autoswitch mode);
void autoShiftUp();
void setGear(int v); //!< low level gear changing (bypasses shifting logic)
void setGearRange(int v); //!< low level gear changing (bypasses shifting logic)
void shift(int val); //!< Changes gear by a relative offset. Plays sounds.
void shiftTo(int val); //!< Changes gear to given value. Plays sounds.
/// @}

};

/// @} //addtogroup Script2Game
/// @} //addtogroup ScriptSideAPIs

} //namespace Script2Game
36 changes: 36 additions & 0 deletions doc/angelscript/Script2Game/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,42 @@ enum ActorSimAttr
ACTORSIMATTR_TC_RATIO, //!< Regulating force, safe values: <1 - 20>
ACTORSIMATTR_TC_PULSE_TIME, //!< Pulse duration in seconds, safe values <0.005 - 1>
ACTORSIMATTR_TC_WHEELSLIP_CONSTANT //!< Minimum wheel slip threshold, safe value = 0.25

// Engine
ACTORSIMATTR_ENGINE_SHIFTDOWN_RPM, //!< Automatic transmission - Param #1 of 'engine'
ACTORSIMATTR_ENGINE_SHIFTUP_RPM, //!< Automatic transmission - Param #2 of 'engine'
ACTORSIMATTR_ENGINE_TORQUE, //!< Engine torque in newton-meters (N/m) - Param #3 of 'engine'
ACTORSIMATTR_ENGINE_DIFF_RATIO, //!< Differential ratio (aka global gear ratio) - Param #4 of 'engine'
ACTORSIMATTR_ENGINE_GEAR_RATIOS_ARRAY, //!< Gearbox - Format: "<reverse_gear> <neutral_gear> <forward_gear 1> [<forward gear 2>]..."; Param #5 and onwards of 'engine'.

// Engoption
ACTORSIMATTR_ENGOPTION_ENGINE_INERTIA, //!< - Param #1 of 'engoption'
ACTORSIMATTR_ENGOPTION_ENGINE_TYPE, //!< - Param #2 of 'engoption'
ACTORSIMATTR_ENGOPTION_CLUTCH_FORCE, //!< - Param #3 of 'engoption'
ACTORSIMATTR_ENGOPTION_SHIFT_TIME, //!< - Param #4 of 'engoption'
ACTORSIMATTR_ENGOPTION_CLUTCH_TIME, //!< - Param #5 of 'engoption'
ACTORSIMATTR_ENGOPTION_POST_SHIFT_TIME, //!< Time (in seconds) until full torque is transferred - Param #6 of 'engoption'
ACTORSIMATTR_ENGOPTION_STALL_RPM, //!< RPM where engine stalls - Param #7 of 'engoption'
ACTORSIMATTR_ENGOPTION_IDLE_RPM, //!< Target idle RPM - Param #8 of 'engoption'
ACTORSIMATTR_ENGOPTION_MAX_IDLE_MIXTURE, //!< Max throttle to maintain idle RPM - Param #9 of 'engoption'
ACTORSIMATTR_ENGOPTION_MIN_IDLE_MIXTURE, //!< Min throttle to maintain idle RPM - Param #10 of 'engoption'
ACTORSIMATTR_ENGOPTION_BRAKING_TORQUE, //!< How much engine brakes on zero throttle - Param #11 of 'engoption'

// Engturbo2 (actually 'engturbo' with Param #1 [type] set to "2" - the recommended variant)
ACTORSIMATTR_ENGTURBO2_INERTIA_FACTOR, //!< Time to spool up - Param #2 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_NUM_TURBOS, //!< Number of turbos - Param #3 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_MAX_RPM, //!< MaxPSI * 10000 ~ calculated from Param #4 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_ENGINE_RPM_OP, //!< Engine RPM threshold for turbo to operate - Param #5 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_BOV_ENABLED, //!< Blow-off valve - Param #6 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_BOV_MIN_PSI, //!< Blow-off valve PSI threshold - Param #7 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_WASTEGATE_ENABLED, //!< - Param #8 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_WASTEGATE_MAX_PSI, //!< - Param #9 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_WASTEGATE_THRESHOLD_N, //!< 1 - WgThreshold ~ calculated from Param #10 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_WASTEGATE_THRESHOLD_P, //!< 1 + WgThreshold ~ calculated from Param #10 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_ANTILAG_ENABLED, //!< - Param #11 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_ANTILAG_CHANCE, //!< - Param #12 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_ANTILAG_MIN_RPM, //!< - Param #13 of 'engturbo2'
ACTORSIMATTR_ENGTURBO2_ANTILAG_POWER, //!< - Param #14 of 'engturbo2'
};

} // namespace Script2Game
Expand Down
Loading
Loading