RigsofRods
Soft-body Physics Simulation
TuneupFileFormat.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2024 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "TuneupFileFormat.h"
23 
24 #include "Actor.h"
25 #include "Application.h"
26 #include "CacheSystem.h"
27 #include "Console.h"
28 #include "Utils.h"
29 
30 #include <OgreEntity.h>
31 #include <OgreMaterialManager.h>
32 #include <OgrePass.h>
33 #include <OgreSubEntity.h>
34 #include <OgreTechnique.h>
35 
36 using namespace RoR;
37 
39 {
40  TuneupDefPtr ret = new TuneupDef();
41 
42  // General info
43  ret->name = this->name ; //std::string
44  ret->guid = this->guid ; //std::string
45  ret->thumbnail = this->thumbnail ; //std::string
46  ret->description = this->description ; //std::string
47  ret->author_name = this->author_name ; //std::string
48  ret->author_id = this->author_id ; //int
49  ret->category_id = this->category_id ; //CacheCategoryId
50  ret->filename = this->filename ; //std::string
51 
52  // addonparts
53  ret->use_addonparts = this->use_addonparts ;
54 
55  // props
56  ret->protected_props = this->protected_props;
57  ret->unwanted_props = this->unwanted_props;
59  ret->prop_tweaks = this->prop_tweaks;
60 
61  // flexbodies
65  ret->flexbody_tweaks = this->flexbody_tweaks;
66 
67  // wheels
70  ret->wheel_tweaks = this->wheel_tweaks;
71 
72  // nodes
73  ret->protected_nodes = this->protected_nodes;
74  ret->node_tweaks = this->node_tweaks;
75 
76  return ret;
77 }
78 
80 {
81  // addonparts
82  this->use_addonparts.clear();
83 
84  // props
85  this->protected_props.clear();
86  this->unwanted_props.clear();
87  this->force_remove_props.clear();
88  this->prop_tweaks.clear();
89 
90  // flexbodies
91  this->protected_flexbodies.clear();
92  this->unwanted_flexbodies.clear();
93  this->force_remove_flexbodies.clear();
94  this->flexbody_tweaks.clear();
95 
96  // wheels
97  this->protected_wheels.clear();
98  this->force_wheel_sides.clear();
99  this->wheel_tweaks.clear();
100 
101  // nodes
102  this->protected_nodes.clear();
103  this->node_tweaks.clear();
104 
105 }
106 
107 bool TuneupDef::isWheelSideForced(WheelID_t wheelid, WheelSide& out_val) const
108 {
109  auto itor = force_wheel_sides.find(wheelid);
110  if (itor != force_wheel_sides.end())
111  {
112  out_val = itor->second;
113  return true;
114  }
115  else
116  {
117  return false;
118  }
119 }
120 
121  // Tweaking helpers
122 
123 float RoR::TuneupUtil::getTweakedWheelTireRadius(TuneupDefPtr& tuneup_def, WheelID_t wheel_id, float orig_val)
124 {
125  TuneupWheelTweak* tweak = nullptr;
126  if (TuneupUtil::isWheelTweaked(tuneup_def, wheel_id, /*out:*/ tweak))
127  {
128  ROR_ASSERT(tweak);
129  return (tweak->twt_tire_radius > 0) ? tweak->twt_tire_radius : orig_val;
130  }
131  else
132  {
133  return orig_val;
134  }
135 }
136 
137 float RoR::TuneupUtil::getTweakedWheelRimRadius(TuneupDefPtr& tuneup_def, WheelID_t wheel_id, float orig_val)
138 {
139  TuneupWheelTweak* tweak = nullptr;
140  if (TuneupUtil::isWheelTweaked(tuneup_def, wheel_id, tweak))
141  {
142  ROR_ASSERT(tweak);
143  return (tweak->twt_rim_radius > 0) ? tweak->twt_rim_radius : orig_val;
144  }
145  else
146  {
147  return orig_val;
148  }
149 }
150 
151 std::string RoR::TuneupUtil::getTweakedWheelMedia(TuneupDefPtr& tuneup_def, WheelID_t wheel_id, int media_idx, const std::string& orig_val)
152 {
153  TuneupWheelTweak* tweak = nullptr;
154  if (TuneupUtil::isWheelTweaked(tuneup_def, wheel_id, tweak))
155  {
156  ROR_ASSERT(tweak);
157  ROR_ASSERT(tweak->twt_media.size() > media_idx);
158  return (tweak->twt_media[media_idx] != "") ? tweak->twt_media[media_idx] : orig_val;
159  }
160  else
161  {
162  return orig_val;
163  }
164 }
165 
166 std::string RoR::TuneupUtil::getTweakedWheelMediaRG(TuneupDefPtr& tuneup_def, WheelID_t wheel_id, int media_idx, const std::string& orig_val)
167 {
168  TuneupWheelTweak* tweak = nullptr;
169  if (TuneupUtil::isWheelTweaked(tuneup_def, wheel_id, tweak))
170  {
171  ROR_ASSERT(tweak);
172  ROR_ASSERT(tweak->twt_media.size() > media_idx);
173  if (tweak->twt_media[media_idx] != "")
174  {
175  // Find the tweak addonpart
176  CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*'partial':*/false, tweak->twt_origin);
177  if (addonpart_entry)
178  {
179  return addonpart_entry->resource_group;
180  }
181  else
182  {
183  LOG(fmt::format("[RoR|Tuneup] WARN Addonpart '{}' not found in modcache!", tweak->twt_origin));
184  return orig_val;
185  }
186  }
187  }
188 
189  return orig_val;
190 
191 }
192 
194 {
195 
196 
197  if (tuneup_def)
198  {
199  WheelSide forced_side = WheelSide::INVALID;
200  if (tuneup_def->isWheelSideForced(wheel_id, forced_side))
201  {
202  return forced_side;
203  }
204 
205  TuneupWheelTweak* tweak = nullptr;
206  if (TuneupUtil::isWheelTweaked(tuneup_def, wheel_id, tweak))
207  {
208  ROR_ASSERT(tweak);
209  if (tweak->twt_side != WheelSide::INVALID)
210  {
211  return tweak->twt_side;
212  }
213  }
214  }
215 
216  return orig_val;
217 }
218 
220 {
221 
222 
223  if (tuneup_def)
224  {
225  auto itor = tuneup_def->wheel_tweaks.find(wheel_id);
226  if (itor != tuneup_def->wheel_tweaks.end())
227  {
228  out_tweak = &itor->second;
229  return true;
230  }
231  }
232 
233  return false;
234 }
235 
236 Ogre::Vector3 RoR::TuneupUtil::getTweakedNodePosition(TuneupDefPtr& tuneup_def, NodeNum_t nodenum, Ogre::Vector3 orig_val)
237 {
238  TuneupNodeTweak* tweak = nullptr;
239  if (TuneupUtil::isNodeTweaked(tuneup_def, nodenum, tweak))
240  {
241  ROR_ASSERT(tweak);
242  return tweak->tnt_pos;
243  }
244  else
245  {
246  return orig_val;
247  }
248 }
249 
251 {
252  if (tuneup_def)
253  {
254  auto itor = tuneup_def->node_tweaks.find(nodenum);
255  if (itor != tuneup_def->node_tweaks.end())
256  {
257  out_tweak = &itor->second;
258  return true;
259  }
260  }
261 
262  return false;
263 }
264 
265 
266 // > prop
268 {
269  return tuneup_def
270  && (tuneup_def->isPropUnwanted(prop_id) || tuneup_def->isPropForceRemoved(prop_id));
271 }
272 
273 Ogre::Vector3 RoR::TuneupUtil::getTweakedPropOffset(TuneupDefPtr& tuneup_def, PropID_t prop_id, Ogre::Vector3 orig_val)
274 {
275  TuneupPropTweak* tweak = nullptr;
276  if (TuneupUtil::isPropTweaked(tuneup_def, prop_id, tweak))
277  {
278  ROR_ASSERT(tweak);
279  return tweak->tpt_offset;
280  }
281  else
282  {
283  return orig_val;
284  }
285 }
286 
287 Ogre::Vector3 RoR::TuneupUtil::getTweakedPropRotation(TuneupDefPtr& tuneup_def, PropID_t prop_id, Ogre::Vector3 orig_val)
288 {
289  TuneupPropTweak* tweak = nullptr;
290  if (TuneupUtil::isPropTweaked(tuneup_def, prop_id, tweak))
291  {
292  ROR_ASSERT(tweak);
293  return tweak->tpt_rotation;
294  }
295  else
296  {
297  return orig_val;
298  }
299 }
300 
301 std::string RoR::TuneupUtil::getTweakedPropMedia(TuneupDefPtr& tuneup_def, PropID_t prop_id, int media_idx, const std::string& orig_val)
302 {
303  TuneupPropTweak* tweak = nullptr;
304  if (TuneupUtil::isPropTweaked(tuneup_def, prop_id, tweak))
305  {
306  ROR_ASSERT(tweak);
307  ROR_ASSERT(tweak->tpt_media.size() > media_idx);
308  return (tweak->tpt_media[media_idx] != "") ? tweak->tpt_media[media_idx] : orig_val;
309  }
310  else
311  {
312  return orig_val;
313  }
314 }
315 
316 std::string RoR::TuneupUtil::getTweakedPropMediaRG(TuneupDefPtr& tuneup_def, PropID_t prop_id, int media_idx, const std::string& orig_val)
317 {
318  TuneupPropTweak* tweak = nullptr;
319  if (TuneupUtil::isPropTweaked(tuneup_def, prop_id, tweak))
320  {
321  ROR_ASSERT(tweak);
322  ROR_ASSERT(tweak->tpt_media.size() > media_idx);
323  if (tweak->tpt_media[media_idx] != "")
324  {
325  // Find the tweak addonpart
326  CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial:*/false, tweak->tpt_origin);
327  if (addonpart_entry)
328  {
329  return addonpart_entry->resource_group;
330  }
331  else
332  {
333  LOG(fmt::format("[RoR|Tuneup] WARN Addonpart '{}' not found in modcache!", tweak->tpt_origin));
334  }
335  }
336  }
337 
338  return orig_val;
339 }
340 
342 {
343 
344 
345  if (tuneup_def)
346  {
347  auto itor = tuneup_def->prop_tweaks.find(prop_id);
348  if (itor != tuneup_def->prop_tweaks.end())
349  {
350  out_tweak = &itor->second;
351  return true;
352  }
353  }
354 
355  return false;
356 }
357 
358 // > flexbody
360 {
361  return tuneup_def &&
362  (tuneup_def->isFlexbodyUnwanted(flexbody_id) || tuneup_def->isFlexbodyForceRemoved(flexbody_id));
363 }
364 
365 Ogre::Vector3 RoR::TuneupUtil::getTweakedFlexbodyOffset(TuneupDefPtr& tuneup_def, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val)
366 {
367  TuneupFlexbodyTweak* tweak = nullptr;
368  if (TuneupUtil::isFlexbodyTweaked(tuneup_def, flexbody_id, tweak))
369  {
370  ROR_ASSERT(tweak);
371  return tweak->tft_offset;
372  }
373  else
374  {
375  return orig_val;
376  }
377 }
378 
379 Ogre::Vector3 RoR::TuneupUtil::getTweakedFlexbodyRotation(TuneupDefPtr& tuneup_def, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val)
380 {
381  TuneupFlexbodyTweak* tweak = nullptr;
382  if (TuneupUtil::isFlexbodyTweaked(tuneup_def, flexbody_id, tweak))
383  {
384  ROR_ASSERT(tweak);
385  return tweak->tft_rotation;
386  }
387  else
388  {
389  return orig_val;
390  }
391 }
392 
393 std::string RoR::TuneupUtil::getTweakedFlexbodyMedia(TuneupDefPtr& tuneup_def, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val)
394 {
395  TuneupFlexbodyTweak* tweak = nullptr;
396  if (TuneupUtil::isFlexbodyTweaked(tuneup_def, flexbody_id, tweak))
397  {
398  ROR_ASSERT(tweak);
399  return (tweak->tft_media != "") ? tweak->tft_media : orig_val;
400  }
401  else
402  {
403  return orig_val;
404  }
405 }
406 
407 std::string RoR::TuneupUtil::getTweakedFlexbodyMediaRG(TuneupDefPtr& tuneup_def, FlexbodyID_t flexbody_id, int media_idx, const std::string& orig_val)
408 {
409  TuneupFlexbodyTweak* tweak = nullptr;
410  if (TuneupUtil::isFlexbodyTweaked(tuneup_def, flexbody_id, tweak))
411  {
412  ROR_ASSERT(tweak);
413  if (tweak->tft_media != "")
414  {
415  // Find the tweak addonpart
416  CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial:*/false, tweak->tft_origin);
417  if (addonpart_entry)
418  {
419  return addonpart_entry->resource_group;
420  }
421  else
422  {
423  LOG(fmt::format("[RoR|Tuneup] WARN Addonpart '{}' not found in modcache!", tweak->tft_origin));
424  return orig_val;
425  }
426  }
427  }
428 
429  return orig_val;
430 }
431 
433 {
434 
435 
436  if (tuneup_def)
437  {
438  auto itor = tuneup_def->flexbody_tweaks.find(flexbody_id);
439  if (itor != tuneup_def->flexbody_tweaks.end())
440  {
441  out_tweak = &itor->second;
442  return true;
443  }
444  }
445 
446  return false;
447 }
448 
449 // > flare
451 {
452  return tuneup_def
453  && (tuneup_def->isFlareUnwanted(flare_id) || tuneup_def->isFlareForceRemoved(flare_id));
454 }
455 
456 // > exhaust
458 {
459  return tuneup_def
460  && (tuneup_def->isExhaustUnwanted(exhaust_id) || tuneup_def->isExhaustForceRemoved(exhaust_id));
461 }
462 
463 // > managedmaterials
464 bool RoR::TuneupUtil::isManagedMatAnyhowRemoved(TuneupDefPtr& tuneup_def, const std::string& material_name)
465 {
466  return tuneup_def
467  && (tuneup_def->isManagedMatUnwanted(material_name) || tuneup_def->isManagedMatForceRemoved(material_name));
468 }
469 
470 bool RoR::TuneupUtil::isManagedMatTweaked(TuneupDefPtr& tuneup_def, const std::string& material_name, TuneupManagedMatTweak*& out_tweak)
471 {
472  if (tuneup_def)
473  {
474  auto itor = tuneup_def->managedmat_tweaks.find(material_name);
475  if (itor != tuneup_def->managedmat_tweaks.end())
476  {
477  out_tweak = &itor->second;
478  return true;
479  }
480  }
481 
482  return false;
483 }
484 
485 std::string RoR::TuneupUtil::getTweakedManagedMatType(TuneupDefPtr& tuneup_def, const std::string& material_name, const std::string& orig_val)
486 {
487  TuneupManagedMatTweak* tweak = nullptr;
488  if (TuneupUtil::isManagedMatTweaked(tuneup_def, material_name, tweak))
489  {
490  ROR_ASSERT(tweak);
491  return (tweak->tmt_type != "") ? tweak->tmt_type : orig_val;
492  }
493  else
494  {
495  return orig_val;
496  }
497 }
498 
499 std::string RoR::TuneupUtil::getTweakedManagedMatMedia(TuneupDefPtr& tuneup_def, const std::string& material_name, int media_idx, const std::string& orig_val)
500 {
501  TuneupManagedMatTweak* tweak = nullptr;
502  if (TuneupUtil::isManagedMatTweaked(tuneup_def, material_name, tweak))
503  {
504  ROR_ASSERT(tweak);
505  ROR_ASSERT(tweak->tmt_media.size() > media_idx);
506  return (tweak->tmt_media[media_idx] != "") ? tweak->tmt_media[media_idx] : orig_val;
507  }
508  else
509  {
510  return orig_val;
511  }
512 }
513 
514 std::string RoR::TuneupUtil::getTweakedManagedMatMediaRG(TuneupDefPtr& tuneup_def, const std::string& material_name, int media_idx, const std::string& orig_val)
515 {
516  TuneupManagedMatTweak* tweak = nullptr;
517  if (TuneupUtil::isManagedMatTweaked(tuneup_def, material_name, tweak))
518  {
519  ROR_ASSERT(tweak);
520  ROR_ASSERT(tweak->tmt_media.size() > media_idx);
521  if (tweak->tmt_media[media_idx] != "")
522  {
523  // Find the tweak addonpart
524  CacheEntryPtr addonpart_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial:*/false, tweak->tmt_origin);
525  if (addonpart_entry)
526  {
527  return addonpart_entry->resource_group;
528  }
529  else
530  {
531  LOG(fmt::format("[RoR|Tuneup] WARN managedmaterial '{}': Addonpart '{}' not found in modcache!", material_name, tweak->tmt_origin));
532  return orig_val;
533  }
534  }
535  }
536 
537  return orig_val;
538 }
539 
540 bool RoR::TuneupUtil::isAddonPartUsed(TuneupDefPtr& tuneup_entry, const std::string& filename)
541 {
542  return tuneup_entry
543  && tuneup_entry->use_addonparts.find(filename) != tuneup_entry->use_addonparts.end();
544 }
545 
546 std::vector<TuneupDefPtr> RoR::TuneupUtil::ParseTuneups(Ogre::DataStreamPtr& stream)
547 {
548  std::vector<TuneupDefPtr> result;
549  TuneupDefPtr curr_tuneup;
550  try
551  {
552  while(!stream->eof())
553  {
554  std::string line = SanitizeUtf8String(stream->getLine());
555 
556  // Ignore blanks & comments
557  if (!line.length() || line.substr(0, 2) == "//")
558  {
559  continue;
560  }
561 
562  if (!curr_tuneup)
563  {
564  // No current tuneup -- So first valid data should be tuneup name
565  Ogre::StringUtil::trim(line);
566  curr_tuneup = new TuneupDef();
567  curr_tuneup->name = line;
568  stream->skipLine("{");
569  }
570  else
571  {
572  // Already in tuneup
573  if (line == "}")
574  {
575  result.push_back(curr_tuneup); // Finished
576  curr_tuneup = nullptr;
577  }
578  else
579  {
580  RoR::TuneupUtil::ParseTuneupAttribute(line, curr_tuneup);
581  }
582  }
583  }
584 
585  if (curr_tuneup)
586  {
589  fmt::format("Tuneup '{}' in file '{}' not properly closed with '}}'",
590  curr_tuneup->name, stream->getName()));
591  result.push_back(curr_tuneup); // Submit anyway
592  curr_tuneup = nullptr;
593  }
594  }
595  catch (Ogre::Exception& e)
596  {
599  fmt::format("Error parsing tuneup file '{}', message: {}",
600  stream->getName(), e.getFullDescription()));
601  }
602  return result;
603 }
604 
605 void RoR::TuneupUtil::ParseTuneupAttribute(const std::string& line, TuneupDefPtr& tuneup_def) // static
606 {
607  Ogre::StringVector params = Ogre::StringUtil::split(line, "\t=,;\n");
608  for (unsigned int i=0; i < params.size(); i++)
609  {
610  Ogre::StringUtil::trim(params[i]);
611  }
612  Ogre::String& attrib = params[0];
613  Ogre::StringUtil::toLowerCase(attrib);
614 
615  // General info
616  if (attrib == "preview" && params.size() >= 2) { tuneup_def->thumbnail = params[1]; return; }
617  if (attrib == "description" && params.size() >= 2) { tuneup_def->description = params[1]; return; }
618  if (attrib == "author_name" && params.size() >= 2) { tuneup_def->author_name = params[1]; return; }
619  if (attrib == "author_id" && params.size() == 2) { tuneup_def->author_id = PARSEINT(params[1]); return; }
620  if (attrib == "category_id" && params.size() == 2) { tuneup_def->category_id = (CacheCategoryId)PARSEINT(params[1]); return; }
621  if (attrib == "guid" && params.size() >= 2) { tuneup_def->guid = params[1]; Ogre::StringUtil::trim(tuneup_def->guid); Ogre::StringUtil::toLowerCase(tuneup_def->guid); return; }
622  if (attrib == "name" && params.size() >= 2) { tuneup_def->name = params[1]; Ogre::StringUtil::trim(tuneup_def->name); return; }
623  if (attrib == "filename" && params.size() >= 2) { tuneup_def->filename = params[1]; Ogre::StringUtil::trim(tuneup_def->filename); return; }
624 
625  // Addonparts and extracted data
626  if (attrib == "use_addonpart" && params.size() == 2) { tuneup_def->use_addonparts.insert(params[1]); return; }
627  if (attrib == "unwanted_prop" && params.size() == 2) { tuneup_def->unwanted_props.insert(PARSEINT(params[1])); return; }
628  if (attrib == "unwanted_flexbody" && params.size() == 2) { tuneup_def->unwanted_flexbodies.insert(PARSEINT(params[1])); return; }
629  if (attrib == "protected_prop" && params.size() == 2) { tuneup_def->protected_props.insert(PARSEINT(params[1])); return; }
630  if (attrib == "protected_flexbody" && params.size() == 2) { tuneup_def->protected_flexbodies.insert(PARSEINT(params[1])); return; }
631 
632  // UI overrides
633  if (attrib == "forced_wheel_side" && params.size() == 3) { tuneup_def->force_wheel_sides[PARSEINT(params[1])] = (WheelSide)PARSEINT(params[2]); return; }
634  if (attrib == "force_remove_prop" && params.size() == 2) { tuneup_def->force_remove_props.insert(PARSEINT(params[1])); return; }
635  if (attrib == "force_remove_flexbody" && params.size() == 2) { tuneup_def->force_remove_flexbodies.insert(PARSEINT(params[1])); return; }
636 }
637 
638 void RoR::TuneupUtil::ExportTuneup(Ogre::DataStreamPtr& stream, TuneupDefPtr& tuneup)
639 {
641  buf << tuneup->name << "\n";
642  buf << "{\n";
643 
644  // General info:
645  buf << "\tpreview = " << tuneup->thumbnail << "\n";
646  buf << "\tdescription = " << tuneup->description << "\n";
647  buf << "\tauthor_name = " << tuneup->author_name << "\n";
648  buf << "\tauthor_id = " << tuneup->author_id << "\n";
649  buf << "\tcategory_id = " << (int)tuneup->category_id << "\n";
650  buf << "\tguid = " << tuneup->guid << "\n";
651  buf << "\tfilename = " << tuneup->filename << "\n";
652  buf << "\n";
653 
654  // Addonparts and extracted data:
655  for (const std::string& addonpart: tuneup->use_addonparts)
656  {
657  buf << "\tuse_addonpart = " << addonpart << "\n";
658  }
659  for (PropID_t unwanted_prop: tuneup->unwanted_props)
660  {
661  buf << "\tunwanted_prop = " << (int)unwanted_prop << "\n";
662  }
663  for (FlexbodyID_t unwanted_flexbody: tuneup->unwanted_flexbodies)
664  {
665  buf << "\tunwanted_flexbody = " << (int)unwanted_flexbody << "\n";
666  }
667  for (PropID_t protected_prop: tuneup->protected_props)
668  {
669  buf << "\tprotected_prop = " << (int)protected_prop << "\n";
670  }
671  for (FlexbodyID_t protected_flexbody: tuneup->protected_flexbodies)
672  {
673  buf << "\tprotected_flexbody = " << (int)protected_flexbody << "\n";
674  }
675 
676  // UI overrides:
677  for (PropID_t prop: tuneup->force_remove_props)
678  {
679  buf << "\tforce_remove_prop = " << (int)prop << "\n";
680  }
681  for (FlexbodyID_t flexbody: tuneup->force_remove_flexbodies)
682  {
683  buf << "\tforce_remove_flexbody = " << (int)flexbody << "\n";
684  }
685  for (auto& pair: tuneup->force_wheel_sides)
686  {
687  buf << "\tforced_wheel_side = " << pair.first << ", " << (int)pair.second << "\n";
688  }
689  buf << "}\n\n";
690 
691  size_t written = stream->write(buf.GetBuffer(), buf.GetLength());
692  if (written < buf.GetLength())
693  {
695  fmt::format("Error writing file '{}': only written {}/{} bytes", stream->getName(), written, buf.GetLength()));
696  }
697 }
698 
RoR::TuneupDef
Dual purpose:
Definition: TuneupFileFormat.h:93
ROR_ASSERT
#define ROR_ASSERT(_EXPR)
Definition: Application.h:40
RoR::TuneupDef::isFlexbodyForceRemoved
bool isFlexbodyForceRemoved(FlexbodyID_t flexbodyid)
Definition: TuneupFileFormat.h:170
RoR::TuneupDef::clone
TuneupDefPtr clone()
Definition: TuneupFileFormat.cpp:38
RoR::TuneupDef::force_remove_flexbodies
std::set< FlexbodyID_t > force_remove_flexbodies
UI overrides.
Definition: TuneupFileFormat.h:126
RoR::TuneupWheelTweak::twt_origin
std::string twt_origin
Addonpart filename.
Definition: TuneupFileFormat.h:60
RoR::TuneupUtil::isAddonPartUsed
static bool isAddonPartUsed(TuneupDefPtr &tuneup_entry, const std::string &filename)
Definition: TuneupFileFormat.cpp:540
RoR::TuneupUtil::ParseTuneups
static std::vector< TuneupDefPtr > ParseTuneups(Ogre::DataStreamPtr &stream)
Definition: TuneupFileFormat.cpp:546
RoR::TuneupUtil::isWheelTweaked
static bool isWheelTweaked(TuneupDefPtr &tuneup_entry, WheelID_t wheel_id, TuneupWheelTweak *&out_tweak)
Definition: TuneupFileFormat.cpp:219
RoR::TuneupWheelTweak::twt_tire_radius
float twt_tire_radius
Arg#5, optional.
Definition: TuneupFileFormat.h:58
RoR::TuneupDef::force_remove_props
std::set< PropID_t > force_remove_props
UI overrides.
Definition: TuneupFileFormat.h:125
RoR::Str::GetBuffer
char * GetBuffer()
Definition: Str.h:48
RoR::TuneupDef::unwanted_props
std::set< PropID_t > unwanted_props
'addonpart_unwanted_prop' directives.
Definition: TuneupFileFormat.h:116
RoR::LT_AddonPart
@ LT_AddonPart
Definition: Application.h:304
RoR::TuneupPropTweak
< Data of 'addonpart_tweak_prop <prop ID> <offsetX> <offsetY> <offsetZ> <rotX> <rotY> <rotZ> <media1>...
Definition: TuneupFileFormat.h:64
RoR::TuneupWheelTweak::twt_rim_radius
float twt_rim_radius
Arg#6, optional, only applies to some wheel types.
Definition: TuneupFileFormat.h:59
RoR::TuneupFlexbodyTweak::tft_rotation
Ogre::Vector3 tft_rotation
Definition: TuneupFileFormat.h:78
RoR::TuneupUtil::isPropTweaked
static bool isPropTweaked(TuneupDefPtr &tuneup_entry, PropID_t flexbody_id, TuneupPropTweak *&out_tweak)
Definition: TuneupFileFormat.cpp:341
RoR::TuneupFlexbodyTweak::tft_origin
std::string tft_origin
Addonpart filename.
Definition: TuneupFileFormat.h:79
RoR::CacheSystem::FindEntryByFilename
CacheEntryPtr FindEntryByFilename(RoR::LoaderType type, bool partial, const std::string &filename)
Returns NULL if none found.
Definition: CacheSystem.cpp:184
RoR::TuneupManagedMatTweak::tmt_type
std::string tmt_type
Arg#2, required.
Definition: TuneupFileFormat.h:85
RoR::TuneupFlexbodyTweak::tft_media
std::string tft_media
Definition: TuneupFileFormat.h:76
RoR::TuneupUtil::isPropAnyhowRemoved
static bool isPropAnyhowRemoved(TuneupDefPtr &tuneup_def, PropID_t prop_id)
Definition: TuneupFileFormat.cpp:267
RoR::TuneupDef::prop_tweaks
std::map< PropID_t, TuneupPropTweak > prop_tweaks
Mesh name(s), offset and rotation overrides via 'addonpart_tweak_prop'.
Definition: TuneupFileFormat.h:113
format
Truck file format(technical spec)
RoR::TuneupDef::unwanted_flexbodies
std::set< FlexbodyID_t > unwanted_flexbodies
'addonpart_unwanted_flexbody' directives.
Definition: TuneupFileFormat.h:117
RoR::SanitizeUtf8String
std::string SanitizeUtf8String(std::string const &str_in)
Definition: Utils.cpp:117
RoR::TuneupUtil::ExportTuneup
static void ExportTuneup(Ogre::DataStreamPtr &stream, TuneupDefPtr &tuneup)
Definition: TuneupFileFormat.cpp:638
Console.h
RoR::TuneupDef::name
std::string name
Definition: TuneupFileFormat.h:97
RoR::Console::putMessage
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition: Console.cpp:97
RoR::TuneupDef::protected_nodes
std::set< NodeNum_t > protected_nodes
Nodes that cannot be altered via 'addonpart_tweak_node'.
Definition: TuneupFileFormat.h:135
RoR::CacheEntry::resource_group
Ogre::String resource_group
Resource group of the loaded bundle. Empty if not loaded yet.
Definition: CacheSystem.h:89
TuneupFileFormat.h
The vehicle tuning system; applies addonparts and user overrides to vehicles.
RoR::TuneupDef::use_addonparts
std::set< std::string > use_addonparts
Addonpart filenames.
Definition: TuneupFileFormat.h:109
RoR::TuneupDef::isExhaustUnwanted
bool isExhaustUnwanted(ExhaustID_t exhaustid)
Definition: TuneupFileFormat.h:163
RoR::TuneupDef::isPropUnwanted
bool isPropUnwanted(PropID_t propid)
Definition: TuneupFileFormat.h:160
RoR::TuneupUtil::getTweakedPropOffset
static Ogre::Vector3 getTweakedPropOffset(TuneupDefPtr &tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val)
Definition: TuneupFileFormat.cpp:273
RoR::TuneupUtil::getTweakedPropRotation
static Ogre::Vector3 getTweakedPropRotation(TuneupDefPtr &tuneup_entry, PropID_t prop_id, Ogre::Vector3 orig_val)
Definition: TuneupFileFormat.cpp:287
Utils.h
RoR::Str::GetLength
size_t GetLength() const
Definition: Str.h:51
RoR::TuneupPropTweak::tpt_rotation
Ogre::Vector3 tpt_rotation
Definition: TuneupFileFormat.h:69
RefCountingObjectPtr< TuneupDef >
Actor.h
RoR::ExhaustID_t
int ExhaustID_t
Index into Actor::exhausts, use RoR::EXHAUSTID_INVALID as empty value.
Definition: ForwardDeclarations.h:71
RoR::TuneupDef::protected_props
std::set< PropID_t > protected_props
Props which cannot be altered via 'addonpart_tweak_prop' or 'addonpart_unwanted_prop' directive.
Definition: TuneupFileFormat.h:137
RoR::TuneupUtil::isNodeTweaked
static bool isNodeTweaked(TuneupDefPtr &tuneup_entry, NodeNum_t nodenum, TuneupNodeTweak *&out_tweak)
Definition: TuneupFileFormat.cpp:250
RoR::TuneupUtil::getTweakedFlexbodyMediaRG
static std::string getTweakedFlexbodyMediaRG(TuneupDefPtr &tuneup_def, FlexbodyID_t flexbody_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:407
PARSEINT
#define PARSEINT(x)
Definition: Application.h:57
RoR::TuneupDef::managedmat_tweaks
std::map< std::string, TuneupManagedMatTweak > managedmat_tweaks
Managed material overrides via 'addonpart_tweak_managedmaterial'.
Definition: TuneupFileFormat.h:115
RoR::TuneupDef::node_tweaks
std::map< NodeNum_t, TuneupNodeTweak > node_tweaks
Node position overrides via 'addonpart_tweak_node'.
Definition: TuneupFileFormat.h:111
RoR::TuneupManagedMatTweak
< Data of 'addonpart_tweak_managedmaterial <name> <type> <media1> <media2> [<media3>]'
Definition: TuneupFileFormat.h:82
RoR::TuneupManagedMatTweak::tmt_origin
std::string tmt_origin
Addonpart filename.
Definition: TuneupFileFormat.h:87
RoR::NodeNum_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
Definition: ForwardDeclarations.h:52
RoR::TuneupUtil::isManagedMatAnyhowRemoved
static bool isManagedMatAnyhowRemoved(TuneupDefPtr &tuneup_def, const std::string &matname)
Definition: TuneupFileFormat.cpp:464
RoR::Str
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition: Str.h:35
RoR::TuneupUtil::isFlexbodyAnyhowRemoved
static bool isFlexbodyAnyhowRemoved(TuneupDefPtr &tuneup_def, FlexbodyID_t flexbody_id)
Definition: TuneupFileFormat.cpp:359
RoR::TuneupDef::isManagedMatForceRemoved
bool isManagedMatForceRemoved(const std::string &matname)
Definition: TuneupFileFormat.h:174
RoR::TuneupNodeTweak
< Data of 'addonpart_tweak_node <nodenum> <posX> <posY> <posZ>'
Definition: TuneupFileFormat.h:44
CacheSystem.h
A database of user-installed content alias 'mods' (vehicles, terrains...)
RoR::TuneupDef::protected_wheels
std::set< WheelID_t > protected_wheels
Wheels that cannot be altered via 'addonpart_tweak_wheel'.
Definition: TuneupFileFormat.h:136
RoR::TuneupWheelTweak::twt_side
WheelSide twt_side
Arg#4, optional, default LEFT (Only applicable to mesh/flexbody wheels)
Definition: TuneupFileFormat.h:57
RoR::TuneupUtil::getTweakedPropMedia
static std::string getTweakedPropMedia(TuneupDefPtr &tuneup_entry, PropID_t prop_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:301
RoR::TuneupDef::flexbody_tweaks
std::map< FlexbodyID_t, TuneupFlexbodyTweak > flexbody_tweaks
Mesh name, offset and rotation overrides via 'addonpart_tweak_flexbody'.
Definition: TuneupFileFormat.h:114
RoR::WheelID_t
int WheelID_t
Index to Actor::ar_wheels, use RoR::WHEELID_INVALID as empty value.
Definition: ForwardDeclarations.h:56
RoR::TuneupNodeTweak::tnt_pos
Ogre::Vector3 tnt_pos
Args#234, required.
Definition: TuneupFileFormat.h:47
RoR::TuneupDef::reset
void reset()
Definition: TuneupFileFormat.cpp:79
RoR::TuneupDef::thumbnail
std::string thumbnail
Definition: TuneupFileFormat.h:100
RoR::TuneupDef::isFlareUnwanted
bool isFlareUnwanted(FlareID_t flareid)
Definition: TuneupFileFormat.h:162
RoR::CacheCategoryId
CacheCategoryId
Definition: CacheSystem.h:147
Application.h
Central state/object manager and communications hub.
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:270
RoR::TuneupPropTweak::tpt_origin
std::string tpt_origin
Addonpart filename.
Definition: TuneupFileFormat.h:70
RoR::TuneupDef::description
std::string description
Definition: TuneupFileFormat.h:101
RoR::TuneupUtil::getTweakedFlexbodyMedia
static std::string getTweakedFlexbodyMedia(TuneupDefPtr &tuneup_entry, FlexbodyID_t flexbody_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:393
RoR::TuneupUtil::getTweakedManagedMatMediaRG
static std::string getTweakedManagedMatMediaRG(TuneupDefPtr &tuneup_def, const std::string &matname, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:514
RoR::TuneupUtil::getTweakedWheelRimRadius
static float getTweakedWheelRimRadius(TuneupDefPtr &tuneup_entry, WheelID_t wheel_id, float orig_val)
Definition: TuneupFileFormat.cpp:137
RoR::TuneupDef::isFlareForceRemoved
bool isFlareForceRemoved(FlareID_t flareid)
Definition: TuneupFileFormat.h:172
RoR::TuneupUtil::isFlareAnyhowRemoved
static bool isFlareAnyhowRemoved(TuneupDefPtr &tuneup_def, FlareID_t flare_id)
Definition: TuneupFileFormat.cpp:450
RoR::TuneupUtil::getTweakedFlexbodyRotation
static Ogre::Vector3 getTweakedFlexbodyRotation(TuneupDefPtr &tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val)
Definition: TuneupFileFormat.cpp:379
RoR::TuneupWheelTweak::twt_media
std::array< std::string, 2 > twt_media
twt_media[0] Arg#2, required ('wheels[2]': face material, 'meshwheels[2]/flexbodywheels': rim mesh) t...
Definition: TuneupFileFormat.h:56
RoR::TuneupDef::author_id
int author_id
Definition: TuneupFileFormat.h:103
RoR::App::GetCacheSystem
CacheSystem * GetCacheSystem()
Definition: Application.cpp:272
RoR::TuneupPropTweak::tpt_media
std::array< std::string, 2 > tpt_media
Media1 = prop mesh; Media2: Steering wheel mesh or beacon flare material.
Definition: TuneupFileFormat.h:67
RoR::TuneupDef::author_name
std::string author_name
Definition: TuneupFileFormat.h:102
RoR::TuneupUtil::getTweakedFlexbodyOffset
static Ogre::Vector3 getTweakedFlexbodyOffset(TuneupDefPtr &tuneup_entry, FlexbodyID_t flexbody_id, Ogre::Vector3 orig_val)
Definition: TuneupFileFormat.cpp:365
RoR::TuneupDef::protected_flexbodies
std::set< FlexbodyID_t > protected_flexbodies
Flexbodies which cannot be altered via 'addonpart_tweak_flexbody' or 'addonpart_unwanted_flexbody' di...
Definition: TuneupFileFormat.h:138
RoR::TuneupPropTweak::tpt_offset
Ogre::Vector3 tpt_offset
Definition: TuneupFileFormat.h:68
RoR::TuneupUtil::getTweakedPropMediaRG
static std::string getTweakedPropMediaRG(TuneupDefPtr &tuneup_def, PropID_t prop_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:316
RoR::WheelSide::INVALID
@ INVALID
RoR::TuneupUtil::getTweakedManagedMatType
static std::string getTweakedManagedMatType(TuneupDefPtr &tuneup_def, const std::string &matname, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:485
RoR::TuneupDef::filename
std::string filename
target vehicle filename
Definition: TuneupFileFormat.h:99
RoR::TuneupUtil::isExhaustAnyhowRemoved
static bool isExhaustAnyhowRemoved(TuneupDefPtr &tuneup_def, ExhaustID_t exhaust_id)
Definition: TuneupFileFormat.cpp:457
RoR::TuneupUtil::isManagedMatTweaked
static bool isManagedMatTweaked(TuneupDefPtr &tuneup_def, const std::string &matname, TuneupManagedMatTweak *&out_tweak)
Definition: TuneupFileFormat.cpp:470
RoR::TuneupUtil::getTweakedWheelMediaRG
static std::string getTweakedWheelMediaRG(TuneupDefPtr &tuneup_def, WheelID_t wheel_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:166
RoR::FlareID_t
int FlareID_t
Index into Actor::ar_flares, use RoR::FLAREID_INVALID as empty value.
Definition: ForwardDeclarations.h:68
RoR::TuneupUtil::getTweakedWheelSide
static WheelSide getTweakedWheelSide(TuneupDefPtr &tuneup_entry, WheelID_t wheel_id, WheelSide orig_val)
Definition: TuneupFileFormat.cpp:193
RoR::TuneupUtil::getTweakedWheelTireRadius
static float getTweakedWheelTireRadius(TuneupDefPtr &tuneup_entry, WheelID_t wheel_id, float orig_val)
Definition: TuneupFileFormat.cpp:123
RoR::TuneupDef::isExhaustForceRemoved
bool isExhaustForceRemoved(ExhaustID_t exhaustid)
Definition: TuneupFileFormat.h:173
RoR::TuneupUtil::getTweakedManagedMatMedia
static std::string getTweakedManagedMatMedia(TuneupDefPtr &tuneup_def, const std::string &matname, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:499
RoR::TuneupDef::category_id
CacheCategoryId category_id
Definition: TuneupFileFormat.h:104
RoR::TuneupWheelTweak
< Data of 'addonpart_tweak_wheel <wheel ID> <media1> <media2> <side flag> <tire radius> <rim radius>'
Definition: TuneupFileFormat.h:51
RoR::TuneupUtil::getTweakedNodePosition
static Ogre::Vector3 getTweakedNodePosition(TuneupDefPtr &tuneup_entry, NodeNum_t nodenum, Ogre::Vector3 orig_val)
Definition: TuneupFileFormat.cpp:236
RoR::Console::CONSOLE_MSGTYPE_ACTOR
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
Definition: Console.h:63
RoR::Console::CONSOLE_SYSTEM_WARNING
@ CONSOLE_SYSTEM_WARNING
Definition: Console.h:53
RoR::TuneupDef::force_wheel_sides
std::map< WheelID_t, WheelSide > force_wheel_sides
UI overrides.
Definition: TuneupFileFormat.h:127
RoR::TuneupDef::isFlexbodyUnwanted
bool isFlexbodyUnwanted(FlexbodyID_t flexbodyid)
Definition: TuneupFileFormat.h:161
RoR::Console::CONSOLE_MSGTYPE_INFO
@ CONSOLE_MSGTYPE_INFO
Generic message.
Definition: Console.h:60
RoR::WheelSide
WheelSide
Used by rig-def/addonpart/tuneup formats to specify wheel rim mesh orientation.
Definition: GfxData.h:115
RoR::FlexbodyID_t
int FlexbodyID_t
Index to GfxActor::m_flexbodies, use RoR::FLEXBODYID_INVALID as empty value.
Definition: ForwardDeclarations.h:62
RoR::TuneupDef::isWheelSideForced
bool isWheelSideForced(WheelID_t wheelid, WheelSide &out_val) const
Definition: TuneupFileFormat.cpp:107
RoR::TuneupUtil::isFlexbodyTweaked
static bool isFlexbodyTweaked(TuneupDefPtr &tuneup_entry, FlexbodyID_t flexbody_id, TuneupFlexbodyTweak *&out_tweak)
Definition: TuneupFileFormat.cpp:432
RoR::TuneupDef::guid
std::string guid
target vehicle GUID
Definition: TuneupFileFormat.h:98
RoR::TuneupUtil::ParseTuneupAttribute
static void ParseTuneupAttribute(const std::string &line, TuneupDefPtr &tuneup_def)
Definition: TuneupFileFormat.cpp:605
RoR::TuneupFlexbodyTweak::tft_offset
Ogre::Vector3 tft_offset
Definition: TuneupFileFormat.h:77
RoR::TuneupFlexbodyTweak
< Data of 'addonpart_tweak_flexbody <flexbody ID> <offsetX> <offsetY> <offsetZ> <rotX> <rotY> <rotZ> ...
Definition: TuneupFileFormat.h:73
RoR::TuneupUtil::getTweakedWheelMedia
static std::string getTweakedWheelMedia(TuneupDefPtr &tuneup_entry, WheelID_t wheel_id, int media_idx, const std::string &orig_val)
Definition: TuneupFileFormat.cpp:151
RoR::TuneupDef::isPropForceRemoved
bool isPropForceRemoved(PropID_t propid)
Definition: TuneupFileFormat.h:169
RoR
Definition: AppContext.h:36
RoR::TuneupManagedMatTweak::tmt_media
std::array< std::string, 3 > tmt_media
Arg#3, required, Arg#4, optional, Arg#5, optional.
Definition: TuneupFileFormat.h:86
RoR::TuneupDef::wheel_tweaks
std::map< WheelID_t, TuneupWheelTweak > wheel_tweaks
Mesh name and radius overrides via 'addonpart_tweak_wheel'.
Definition: TuneupFileFormat.h:112
RoR::TuneupDef::isManagedMatUnwanted
bool isManagedMatUnwanted(const std::string &matname)
Definition: TuneupFileFormat.h:164
RoR::PropID_t
int PropID_t
Index to GfxActor::m_props, use RoR::PROPID_INVALID as empty value.
Definition: ForwardDeclarations.h:59