Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPAirDistributor292.airscheme.txt:
- // V m 0 0.4
- //
- // # КДР
- // V kdr 0 1
- // C mk_kdr m kdr 5mm 0
- // C kdr_at kdr at 2.5mm 0
- //
- // # срывной клапан
- // V sk 0 0.5
- // C mk_sk m sk 0.8mm 0
- // C sk_tc sk tc 5mm 0
- // C mk_at_sk m at 6.5mm 0
- //
- // # МК - ЗК - ЗР
- // C mk_zk m zk 1 0
- // V zk 0 0.4
- // V zr 0 0.4
- // C zk zr 9mm
- //
- // # ТЦ
- // V tc 0 0.4
- // C zk_tc zk tc 4mm 0 # ЗК - ТЦ (служебное)
- // C tc_at tc at 1 0 # ТЦ - Ат (отпуск)
- // C zk_tc_e zk tc 1 0 # ЗК - ТЦ (экстренное)
- class SPAirDistributor292 : SPAirObject
- {
- readonly static public int ModeK = 0;
- readonly static public int ModeD = 1;
- readonly static public int ModeUV = 2;
- public int Mode = ModeK;
- int vM;
- //int vKDR;
- int cMK_KDR;
- int cKDR_AT;
- int vSK;
- int cMK_SK;
- int cSK_TC;
- int cMK_AT_SK;
- int cMK_ZK;
- int vZK;
- //int vZR;
- int vTC;
- int cZK_TC;
- int cTC_AT;
- int cZK_TC_E;
- public float ozx;
- public float gzx;
- static readonly float SKChargePressure = 40.0f;
- static readonly float SKTriggerPressure = 120.0f;
- static readonly float SKRatio = 2.0f;
- public override void Init(SPAirScheme scheme, string objectName)
- {
- vM = scheme.GetObjectReservoirIndex(".m");
- //vKDR = scheme.GetObjectReservoirIndex(".kdr");
- cMK_KDR = scheme.GetObjectConnectionIndex(".mk_kdr");
- cKDR_AT = scheme.GetObjectConnectionIndex(".kdr_at");
- vSK = scheme.GetObjectReservoirIndex(".sk");
- cMK_SK = scheme.GetObjectConnectionIndex(".mk_sk");
- cSK_TC = scheme.GetObjectConnectionIndex(".sk_tc");
- cMK_AT_SK = scheme.GetObjectConnectionIndex(".mk_at_sk");
- cMK_ZK = scheme.GetObjectConnectionIndex(".mk_zk");
- vZK = scheme.GetObjectReservoirIndex(".zk");
- //vZR = scheme.GetObjectReservoirIndex(".zr");
- vTC = scheme.GetObjectReservoirIndex(".tc");
- cZK_TC = scheme.GetObjectConnectionIndex(".zk_tc");
- cTC_AT = scheme.GetObjectConnectionIndex(".tc_at");
- cZK_TC_E = scheme.GetObjectConnectionIndex(".zk_tc_e");
- }
- public override void Update(SPAirScheme scheme, float dt)
- {
- float openMK_KDR = 0.0f;
- float openKDR_AT = 0.0f;
- float openMK_SK = 0.0f;
- float openSK_TC = 0.0f;
- float openMK_AT_SK = 0.0f;
- float openMK_ZK = 0.0f;
- float openZK_TC = 0.0f;
- float openTC_AT = 0.0f;
- float openZK_TC_E = 0.0f;
- // updating holes
- float ozgz_x = ozx - gzx;
- bool hole_a1_kdr = ozgz_x < 4.0;
- bool hole_t_zk = 3.5 < ozgz_x;
- bool hole_s_mk = 6.0 < ozgz_x;
- bool hole_mk_zk_3d175 = 1.0 < ozx && ozx < 4.0;
- bool hole_mk_zk_d200 = ozx <= 1.0;
- bool hole_tc3_t = 5.5 < gzx && gzx < 10.5;
- bool hole_tc3_sk = 10.5 <= gzx;
- bool hole_tc2_at = 0.0 <= gzx && gzx < 5.0;
- bool hole_a1_at = 0.0 <= gzx && gzx < 4.0;
- bool hole_kdr_s = 0.0 <= gzx && gzx <= 5.5;
- bool hole_tc_e = 15.0 <= gzx;
- bool hole_kdr_at_o = 13.0 <= gzx;
- float mkPressure = scheme.GetPressure(vM);
- float skPressure = scheme.GetPressure(vSK);
- float zkPressure = scheme.GetPressure(vZK);
- float tcPressure = scheme.GetPressure(vTC);
- // updating air flow through holes)
- if (hole_tc3_sk && Mode != ModeUV)
- openSK_TC = 1.0f;
- float skPressureDelta = mkPressure - (skPressure + SKRatio * tcPressure);
- if (skPressureDelta > SKChargePressure) {
- openMK_SK = 1.0f;
- if (skPressureDelta > SKTriggerPressure)
- openMK_AT_SK = 1.0f;
- }
- if (hole_tc_e) {
- if (Mode == ModeK)
- openZK_TC_E = SPAirHelper.HoleFlow(5.5f);
- else
- openZK_TC_E = SPAirHelper.HoleFlow(2.5f);
- }
- if (hole_mk_zk_3d175)
- openMK_ZK = SPAirHelper.HoleFlow(3 * 1.25f);
- else if (hole_mk_zk_d200)
- openMK_ZK = SPAirHelper.HoleFlow(2.0f);
- if (hole_tc2_at) {
- if (Mode == ModeK)
- openTC_AT = SPAirHelper.HoleFlow(3.0f);
- else
- openTC_AT = SPAirHelper.HoleFlow(2.5f);
- }
- if (hole_t_zk && hole_tc3_t)
- openZK_TC = (ozgz_x - 3.5f) / 4.0f;
- if (hole_s_mk && hole_kdr_s)
- openMK_KDR = 1.0f;
- if (hole_a1_at && hole_a1_kdr || hole_kdr_at_o)
- openKDR_AT = 1.0f;
- // setting holes
- scheme.SetFlowRate(cMK_KDR, openMK_KDR);
- scheme.SetFlowRate(cKDR_AT, openKDR_AT);
- scheme.SetFlowRate(cMK_SK, openMK_SK);
- scheme.SetFlowRate(cSK_TC, openSK_TC);
- scheme.SetFlowRate(cMK_AT_SK, openMK_AT_SK);
- scheme.SetFlowRate(cMK_ZK, openMK_ZK);
- scheme.SetFlowRate(cZK_TC, openZK_TC);
- scheme.SetFlowRate(cTC_AT, openTC_AT);
- scheme.SetFlowRate(cZK_TC_E, openZK_TC_E);
- // updating positions
- float ozDelta = zkPressure - mkPressure;
- const float ozLeftBuffer = 120.0f;
- const float ozRightBuffer = 40.0f;
- const float ozFriction = 5.0f;
- const float gzFriction = 7.0f;
- const float ozSpeed = 7.5f / 4.0f;
- const float ozgzSpeed = 7.5f / 6.0f;
- if (ozDelta > ozFriction)
- ozDelta = ozDelta - ozFriction;
- else if (ozDelta < -ozFriction)
- ozDelta = ozDelta + ozFriction;
- else
- ozDelta = 0.0f;
- float ozxNew = ozx + ozDelta * ozSpeed * dt;
- bool leftBuffer = false;
- bool rightBuffer = false;
- if (ozxNew < 3.0) {
- if (ozDelta < -ozLeftBuffer) {
- ozDelta = ozDelta + ozLeftBuffer;
- leftBuffer = true;
- }
- }
- else if (ozxNew > 15.0) {
- if (ozDelta > ozRightBuffer) {
- ozDelta = ozDelta - ozRightBuffer;
- rightBuffer = true;
- }
- }
- // collsion between oz and gz
- if (ozxNew < gzx || ozxNew > gzx + 7.5f) {
- float ozgzDelta = 0.0f;
- if (ozDelta > gzFriction)
- ozgzDelta = ozDelta - gzFriction;
- else if (ozDelta < -gzFriction)
- ozgzDelta = ozDelta + gzFriction;
- ozxNew = ozx + ozgzDelta * ozgzSpeed * dt;
- }
- else {
- float max = gzx + 7.5f;
- if (ozxNew > max)
- ozxNew = max;
- else if (ozxNew < gzx)
- ozxNew = gzx;
- }
- // collision with left and right buffer
- if (ozxNew < 3.0 && !leftBuffer)
- ozxNew = 3.0f;
- else if (ozxNew > 15.0 && !rightBuffer)
- ozxNew = 15.0f;
- if (ozxNew > 24.0f)
- ozxNew = 24.0f;
- else if (ozxNew < 0.0f)
- ozxNew = 0.0f;
- ozx = ozxNew;
- if (ozxNew > gzx + 7.5f)
- gzx = ozx - 7.5f;
- else if (ozxNew < gzx)
- gzx = ozxNew;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement