bool IsParametersGatesOk(int[] Pars, int pathIndx) { var tstr = quest.Paths[pathIndx].LogicExpression.Trim(); if (tstr != "") { var parse = new QuestCalcParse(); parse.Parse(tstr, Pars); if ((parse.answer == 0) && (!parse.error)) { return(false); } // parse = TCalcParse.Create; //// parse.AssignAndPreprocess(LogicExpression.Text,1); // 1 - не имееет значения // parse.internal_str = parse.ConvertToInternal(tstr); // if not parse.default_expression then // { //// if not parse.error then // parse.Parse(CalcParseClass.TParValues(pars)); // if (not parse.calc_error)and(parse.answer=0) then // { // return false; // } // } // parse.Destroy; } for (var i = 0; i < Quest.maxparameters; ++i) { if (quest.Pars[i].Enabled) { if (Pars[i] > quest.Paths[pathIndx].DPars[i].max) { return(false); } if (Pars[i] < quest.Paths[pathIndx].DPars[i].min) { return(false); } if (!IsParametersBitmaskOk(Pars[i], quest.Paths[pathIndx].DPars[i].bitmask)) { return(false); } if (!IsValueGatesOk(Pars[i], quest.Paths[pathIndx].DPars[i].ValuesGate)) { return(false); } if (!IsModZeroeGatesOk(Pars[i], quest.Paths[pathIndx].DPars[i].ModZeroesGate)) { return(false); } } } return(true); }
private string FixStringValuePars(string str, int[] Pars) { string result = str; string tstr = ""; int i = 0; int c = result.Length; while (i < c) { if (result[i] != '{') { tstr += result[i]; i++; } else { i++; string tstr1 = ""; while ((i < c) && (result[i] != '}')) { tstr1 += result[i]; i++; } if (tstr1 != "") { var parse = new QuestCalcParse(); parse.Clear(); string tmp = parse.AssignAndPreprocess(tstr1, 1); if (!(parse.error || parse.default_expression)) { parse.Parse(tmp, Pars); if (!parse.error) { tstr += parse.answer.ToString(); } else { tstr += '{' + tstr1; } } else { tstr += '{' + tstr1; } } i++; } } result = tstr; for (int p = 0; p < Quest.maxparameters; p++) { result = result.Replace("[p" + p.ToString() + "]", Pars[p].ToString()); } return(result); }
public string ProcessString(string text, int[] Pars) { text = QuestCalcParse.InsertParValues(text, Pars); text = text.Replace("<ToStar>", RToStar); text = text.Replace("<Parsec>", RParsec); text = text.Replace("<Artefact>", RArtefact); text = text.Replace("<ToPlanet>", RToPlanet); text = text.Replace("<Date>", RDate); text = text.Replace("<CurDate>", "1 января 3000 г."); text = text.Replace("<Money>", RMoney); text = text.Replace("<FromPlanet>", RFromPLanet); text = text.Replace("<FromStar>", RFromStar); //text = text.Replace("<Ranger>", RRanger); text = text.Replace("<clr>", ""); text = text.Replace("<clrEnd>", ""); text = FixStringValuePars(text, Pars); return(text); }
// Changes state of the Location public string FindLocationDescription(int[] playerPars) { var found = false; var text = ""; if (RandomShowLocationDescriptions) { var flag = true; var parse = new QuestCalcParse(); string str = parse.AssignAndPreprocess(LocDescrExprOrder, 1); if (parse.error || parse.default_expression) { flag = false; } if (flag) { parse.Parse(str, playerPars); if (parse.calc_error) { flag = false; } } if (flag) { if ((parse.answer > 10) || (parse.answer < 1)) { flag = false; } } if (flag) { string tmp = LocationDescriptions[parse.answer - 1]; tmp = string.IsNullOrEmpty(tmp) ? "" : tmp.Trim(); if (string.IsNullOrEmpty(tmp)) { flag = false; } } if (flag) { text = LocationDescriptions[parse.answer - 1].Trim(); } if (!flag) { int c = 0; while (!found) { int i = QuestRandom.Get("E", 10);// Random(10) + 1; text = LocationDescriptions[i].Trim(); if (text != "") { found = true; LocationDescription = text; } else { c++; } if (c > MaxLocationDescriptions * 2) { text = ""; found = true; } } } } else { var i = LocDescrOrder; var c = 0; while (!found) { text = LocationDescriptions[i - 1]; if (string.IsNullOrEmpty(text) == false) { found = true; LocationDescription = text.Trim(); LocDescrOrder = i + 1; } else { ++c; } ++i; if (i > MaxLocationDescriptions) { i = 1; } if (c > MaxLocationDescriptions) { text = ""; found = true; LocDescrOrder = i; } } } //!! LocationDescription = Quest.ProcessString(text); return(text); }
void ProcessParametersWithDelta(QuestParameterDelta[] delta) // delta.size == maxparameters { int[] tpars = new int[Quest.maxparameters]; for (var i = 0; i < Quest.maxparameters; ++i) { if (quest.Pars[i].Enabled) { var tstr = delta[i].Expression.Trim(); if (delta[i].DeltaExprFlag) { if (!string.IsNullOrEmpty(tstr)) { var parse = new QuestCalcParse(); parse.Parse(tstr, Pars); if (parse.error == false) { tpars[i] = parse.answer; } } else { tpars[i] = Pars[i]; } } else { if (delta[i].DeltaApprFlag) { tpars[i] = delta[i].delta; } else { if (delta[i].DeltaPercentFlag) { float dbl = (Pars[i] / 100.0f) * delta[i].delta; if (dbl == -29.5) { dbl = -29; //!!! fix Delphi Round !!! } tpars[i] = Pars[i] + (int)Math.Round(dbl); } else { tpars[i] = Pars[i] + delta[i].delta; } } } if (tpars[i] > quest.Pars[i].max) { tpars[i] = quest.Pars[i].max; } if (tpars[i] < quest.Pars[i].min) { tpars[i] = quest.Pars[i].min; } } } for (var i = 0; i < Quest.maxparameters; ++i) { if (quest.Pars[i].Enabled) { Pars[i] = tpars[i]; } } }