#include "plugin.h"
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include "game_sa\common.h"
#include "game_sa\CFont.h"
using namespace plugin;
using namespace std;
vector<unsigned int> truckIDs;
class ZR350 {
public:
struct MyData {
unsigned int baseModelId;
float value;
};
static vector<MyData>& GetDataVector() {
static vector<MyData> vec; // глобальная переменная vec, доступ к которой осуществляется вызовом GetDataVector()
return vec;
}
static void ReadSettingsFile() {
ifstream stream("vehicle_advanced.dat");
for (string line; getline(stream, line); ) {
if (line[0] != ';' && line[0] != '#') {
if (!line.compare("zr350")) {
while (getline(stream, line) && line.compare("endzr350")) {
if (line[0] != ';' && line[0] != '#') {
MyData entry;
if (sscanf(line.c_str(), "%d, %f", &entry.baseModelId, &entry.value) == 2)
GetDataVector().push_back(entry); // теперь мы точно знаем, что обращаемся к уже построенному обьекту
else
Error("Failed to scan line: %s", line.c_str());
}
}
}
if (!line.compare("trucks")) {
while (getline(stream, line) && line.compare("endtrucks")) {
if (line[0] != ';' && line[0] != '#') {
std::stringstream ss(line);
int i;
while (ss >> i) {
truckIDs.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
}
}
}
}
}
}
static MyData *GetDataInfoForModel(unsigned int BaseModelId) {
for (unsigned int i = 0; i < GetDataVector().size(); i++) {
if (GetDataVector()[i].baseModelId == BaseModelId)
return &GetDataVector()[i];
}
return nullptr;
}
static bool IsTruckModel(unsigned int modelId) {
for (unsigned int i : truckIDs) {
if (i == modelId)
return true;
}
return false;
}
static void Test() {
CVehicle *vehicle = FindPlayerVehicle(-1, false);
if (vehicle) {
CFont::SetScale(0.5f, 1.0f);
CFont::SetColor(CRGBA(255, 255, 255, 255));
CFont::SetAlignment(ALIGN_LEFT);
CFont::SetOutlinePosition(1);
CFont::SetDropColor(CRGBA(0, 0, 0, 255));
CFont::SetBackground(false, false);
CFont::SetFontStyle(FONT_SUBTITLES);
CFont::SetProp(true);
CFont::SetWrapx(600.0f);
static char str[32];
MyData *entryModel = GetDataInfoForModel(vehicle->m_wModelIndex);
if (entryModel) {
sprintf(str, "yes %d %.2f", entryModel->baseModelId, entryModel->value);
CFont::PrintString(5.0f, 445.0f, str);
}
else {
sprintf(str, "no %d", vehicle->m_wModelIndex);
CFont::PrintString(5.0f, 445.0f, str);
}
if (IsTruckModel(vehicle->m_wModelIndex)) {
sprintf(str, "yes truck %d", vehicle->m_wModelIndex);
CFont::PrintString(205.0f, 445.0f, str);
}
else {
sprintf(str, "no truck %d", vehicle->m_wModelIndex);
CFont::PrintString(205.0f, 445.0f, str);
}
}
}
ZR350() {
ReadSettingsFile();
for (unsigned int i = 0; i < GetDataVector().size(); i++)
Error("Entry %d: %d - %.2f", i + 1, GetDataVector()[i].baseModelId, GetDataVector()[i].value);
Events::drawingEvent += Test;
}
} test;