Fixed produce() and NewScript not marking programs as loaded from level files (closes #613); refactored NewScript to std::vector and std::string
parent
bd9a56fe7b
commit
6711154762
|
@ -4372,45 +4372,34 @@ bool CRobotMain::ReadFileStack(CObject *obj, FILE *file, int objRank)
|
||||||
|
|
||||||
|
|
||||||
//! Empty the list
|
//! Empty the list
|
||||||
bool CRobotMain::FlushNewScriptName()
|
void CRobotMain::FlushNewScriptName()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAXNEWSCRIPTNAME; i++)
|
m_newScriptName.clear();
|
||||||
m_newScriptName[i].used = false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Adds a script name
|
//! Adds a script name
|
||||||
bool CRobotMain::AddNewScriptName(ObjectType type, char *name)
|
void CRobotMain::AddNewScriptName(ObjectType type, const std::string& name)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAXNEWSCRIPTNAME; i++)
|
NewScriptName newscript;
|
||||||
{
|
newscript.type = type;
|
||||||
if (!m_newScriptName[i].used)
|
newscript.name = name;
|
||||||
{
|
m_newScriptName.push_back(newscript);
|
||||||
m_newScriptName[i].used = true;
|
|
||||||
m_newScriptName[i].type = type;
|
|
||||||
strcpy(m_newScriptName[i].name, name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Seeks a script name for a given type
|
//! Seeks a script name for a given type
|
||||||
char* CRobotMain::GetNewScriptName(ObjectType type, int rank)
|
std::string CRobotMain::GetNewScriptName(ObjectType type, int rank)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAXNEWSCRIPTNAME; i++)
|
for (unsigned int i = 0; i < m_newScriptName.size(); i++)
|
||||||
{
|
{
|
||||||
if (m_newScriptName[i].used &&
|
if (m_newScriptName[i].type == type ||
|
||||||
(m_newScriptName[i].type == type ||
|
m_newScriptName[i].type == OBJECT_NULL )
|
||||||
m_newScriptName[i].type == OBJECT_NULL))
|
|
||||||
{
|
{
|
||||||
if (rank == 0) return m_newScriptName[i].name;
|
if (rank == 0) return m_newScriptName[i].name;
|
||||||
else rank --;
|
else rank --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -112,13 +112,10 @@ class CDisplayText;
|
||||||
class CDisplayInfo;
|
class CDisplayInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int MAXNEWSCRIPTNAME = 20;
|
|
||||||
|
|
||||||
struct NewScriptName
|
struct NewScriptName
|
||||||
{
|
{
|
||||||
bool used = false;
|
|
||||||
ObjectType type = OBJECT_NULL;
|
ObjectType type = OBJECT_NULL;
|
||||||
char name[40] = {};
|
std::string name = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,9 +277,9 @@ public:
|
||||||
bool SaveFileStack(CObject *pObj, FILE *file, int objRank);
|
bool SaveFileStack(CObject *pObj, FILE *file, int objRank);
|
||||||
bool ReadFileStack(CObject *pObj, FILE *file, int objRank);
|
bool ReadFileStack(CObject *pObj, FILE *file, int objRank);
|
||||||
|
|
||||||
bool FlushNewScriptName();
|
void FlushNewScriptName();
|
||||||
bool AddNewScriptName(ObjectType type, char *name);
|
void AddNewScriptName(ObjectType type, const std::string& name);
|
||||||
char* GetNewScriptName(ObjectType type, int rank);
|
std::string GetNewScriptName(ObjectType type, int rank);
|
||||||
|
|
||||||
void SelectPlayer(std::string playerName);
|
void SelectPlayer(std::string playerName);
|
||||||
CPlayerProfile* GetPlayerProfile();
|
CPlayerProfile* GetPlayerProfile();
|
||||||
|
@ -534,7 +531,7 @@ protected:
|
||||||
|
|
||||||
std::map<int, std::string> m_teamNames;
|
std::map<int, std::string> m_teamNames;
|
||||||
|
|
||||||
NewScriptName m_newScriptName[MAXNEWSCRIPTNAME];
|
std::vector<NewScriptName> m_newScriptName;
|
||||||
|
|
||||||
float m_cameraPan = 0.0f;
|
float m_cameraPan = 0.0f;
|
||||||
float m_cameraZoom = 0.0f;
|
float m_cameraZoom = 0.0f;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "level/robotmain.h"
|
#include "level/robotmain.h"
|
||||||
|
|
||||||
|
#include "level/parser/parser.h"
|
||||||
#include "level/parser/parserline.h"
|
#include "level/parser/parserline.h"
|
||||||
#include "level/parser/parserparam.h"
|
#include "level/parser/parserparam.h"
|
||||||
|
|
||||||
|
@ -665,11 +666,12 @@ bool CAutoFactory::CreateVehicle()
|
||||||
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(vehicle);
|
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(vehicle);
|
||||||
for ( int i=0 ; ; i++ )
|
for ( int i=0 ; ; i++ )
|
||||||
{
|
{
|
||||||
char* name = m_main->GetNewScriptName(m_type, i);
|
std::string name = m_main->GetNewScriptName(m_type, i);
|
||||||
if ( name == nullptr ) break;
|
if (name.empty()) break;
|
||||||
Program* prog = programStorage->GetOrAddProgram(i);
|
Program* prog = programStorage->GetOrAddProgram(i);
|
||||||
programStorage->ReadProgram(prog, name);
|
programStorage->ReadProgram(prog, InjectLevelPathsForCurrentLevel(name));
|
||||||
prog->readOnly = true;
|
prog->readOnly = true;
|
||||||
|
prog->filename = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1607,6 +1607,7 @@ bool CScriptFunctions::rProduce(CBotVar* var, CBotVar* result, int& exception, v
|
||||||
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(object);
|
CProgramStorageObject* programStorage = dynamic_cast<CProgramStorageObject*>(object);
|
||||||
Program* program = programStorage->AddProgram();
|
Program* program = programStorage->AddProgram();
|
||||||
programStorage->ReadProgram(program, name2.c_str());
|
programStorage->ReadProgram(program, name2.c_str());
|
||||||
|
program->filename = name;
|
||||||
dynamic_cast<CProgrammableObject*>(object)->RunProgram(program);
|
dynamic_cast<CProgrammableObject*>(object)->RunProgram(program);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue