Added object.research(type)
parent
6798641a71
commit
f90a4b48f5
|
@ -42,7 +42,7 @@ const float LABO_DELAY = 20.0f; // duration of the analysis
|
|||
|
||||
// Object's constructor.
|
||||
|
||||
CAutoLabo::CAutoLabo(CObject* object) : CAuto(object)
|
||||
CAutoLabo::CAutoLabo(CObject* object) : CAuto(object)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -111,6 +111,48 @@ void CAutoLabo::Init()
|
|||
}
|
||||
|
||||
|
||||
// Starts an action
|
||||
|
||||
Error CAutoLabo::StartAction(int param)
|
||||
{
|
||||
CObject* power;
|
||||
|
||||
if ( m_phase != ALAP_WAIT )
|
||||
{
|
||||
return ERR_GENERIC;
|
||||
}
|
||||
|
||||
m_research = static_cast<ResearchType>(param);
|
||||
|
||||
if ( g_researchDone & m_research )
|
||||
{
|
||||
return ERR_LABO_ALREADY;
|
||||
}
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power == 0 )
|
||||
{
|
||||
return ERR_LABO_NULL;
|
||||
}
|
||||
if ( power->GetType() != OBJECT_BULLET )
|
||||
{
|
||||
return ERR_LABO_BAD;
|
||||
}
|
||||
|
||||
SetBusy(true);
|
||||
InitProgressTotal(1.0f+1.5f+1.5f+LABO_DELAY+1.5f+1.5f+1.0f);
|
||||
UpdateInterface();
|
||||
|
||||
power->SetLock(true); // ball longer usable
|
||||
|
||||
SoundManip(1.0f, 1.0f, 1.0f);
|
||||
m_phase = ALAP_OPEN1;
|
||||
m_progress = 0.0f;
|
||||
m_speed = 1.0f/1.0f;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
// Management of an event.
|
||||
|
||||
bool CAutoLabo::EventProcess(const Event &event)
|
||||
|
@ -130,46 +172,17 @@ bool CAutoLabo::EventProcess(const Event &event)
|
|||
if ( m_object->GetSelect() ) CreateInterface(true);
|
||||
}
|
||||
|
||||
if ( m_object->GetSelect() && // center selected?
|
||||
(event.type == EVENT_OBJECT_RiPAW ||
|
||||
event.type == EVENT_OBJECT_RiGUN) )
|
||||
if ( m_object->GetSelect() ) // center selected?
|
||||
{
|
||||
if ( m_phase != ALAP_WAIT )
|
||||
{
|
||||
Error err = ERR_GENERIC;
|
||||
if ( event.type == EVENT_OBJECT_RiPAW ) err = StartAction(RESEARCH_iPAW);
|
||||
if ( event.type == EVENT_OBJECT_RiGUN ) err = StartAction(RESEARCH_iGUN);
|
||||
|
||||
if( err != ERR_OK && err != ERR_GENERIC )
|
||||
m_displayText->DisplayError(err, m_object);
|
||||
|
||||
if( err != ERR_GENERIC )
|
||||
return false;
|
||||
}
|
||||
|
||||
m_research = event.type;
|
||||
|
||||
if ( TestResearch(m_research) )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_LABO_ALREADY, m_object);
|
||||
return false;
|
||||
}
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power == 0 )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_LABO_NULL, m_object);
|
||||
return false;
|
||||
}
|
||||
if ( power->GetType() != OBJECT_BULLET )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_LABO_BAD, m_object);
|
||||
return false;
|
||||
}
|
||||
|
||||
SetBusy(true);
|
||||
InitProgressTotal(1.0f+1.5f+1.5f+LABO_DELAY+1.5f+1.5f+1.0f);
|
||||
UpdateInterface();
|
||||
|
||||
power->SetLock(true); // ball longer usable
|
||||
|
||||
SoundManip(1.0f, 1.0f, 1.0f);
|
||||
m_phase = ALAP_OPEN1;
|
||||
m_progress = 0.0f;
|
||||
m_speed = 1.0f/1.0f;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( event.type != EVENT_FRAME ) return true;
|
||||
|
@ -341,7 +354,13 @@ bool CAutoLabo::EventProcess(const Event &event)
|
|||
}
|
||||
else
|
||||
{
|
||||
SetResearch(m_research); // research done
|
||||
g_researchDone |= m_research; // research done
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
UpdateInterface();
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power != 0 )
|
||||
|
@ -606,7 +625,7 @@ bool CAutoLabo::Read(char *line)
|
|||
m_phase = static_cast< AutoLaboPhase >(OpInt(line, "aPhase", ALAP_WAIT));
|
||||
m_progress = OpFloat(line, "aProgress", 0.0f);
|
||||
m_speed = OpFloat(line, "aSpeed", 1.0f);
|
||||
m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
|
||||
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
|
||||
|
||||
m_lastParticle = 0.0f;
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
void DeleteObject(bool bAll=false);
|
||||
|
||||
void Init();
|
||||
Error StartAction(int param);
|
||||
bool EventProcess(const Event &event);
|
||||
Error GetError();
|
||||
|
||||
|
@ -68,7 +69,7 @@ protected:
|
|||
float m_speed;
|
||||
float m_timeVirus;
|
||||
float m_lastParticle;
|
||||
EventType m_research;
|
||||
ResearchType m_research;
|
||||
int m_partiRank[3];
|
||||
int m_partiSphere;
|
||||
int m_soundChannel;
|
||||
|
|
|
@ -92,6 +92,60 @@ void CAutoResearch::Init()
|
|||
}
|
||||
|
||||
|
||||
// Starts an action
|
||||
|
||||
Error CAutoResearch::StartAction(int param)
|
||||
{
|
||||
CObject* power;
|
||||
float time;
|
||||
|
||||
if ( m_phase != ALP_WAIT )
|
||||
{
|
||||
return ERR_GENERIC;
|
||||
}
|
||||
|
||||
m_research = static_cast<ResearchType>(param);
|
||||
|
||||
if ( g_researchDone & m_research )
|
||||
{
|
||||
return ERR_RESEARCH_ALREADY;
|
||||
}
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power == 0 )
|
||||
{
|
||||
return ERR_RESEARCH_POWER;
|
||||
}
|
||||
if ( power->GetCapacity() > 1.0f )
|
||||
{
|
||||
return ERR_RESEARCH_TYPE;
|
||||
}
|
||||
if ( power->GetEnergy() < 1.0f )
|
||||
{
|
||||
return ERR_RESEARCH_ENERGY;
|
||||
}
|
||||
|
||||
time = SEARCH_TIME;
|
||||
if ( m_research == RESEARCH_TANK ) time *= 0.3f;
|
||||
if ( m_research == RESEARCH_FLY ) time *= 0.3f;
|
||||
if ( m_research == RESEARCH_ATOMIC ) time *= 2.0f;
|
||||
|
||||
SetBusy(true);
|
||||
InitProgressTotal(time);
|
||||
UpdateInterface();
|
||||
|
||||
m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(0), 0.0f, 1.0f, true);
|
||||
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
|
||||
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE);
|
||||
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
|
||||
|
||||
m_phase = ALP_SEARCH;
|
||||
m_progress = 0.0f;
|
||||
m_speed = 1.0f/time;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
// Management of an event.
|
||||
|
||||
bool CAutoResearch::EventProcess(const Event &event)
|
||||
|
@ -100,7 +154,7 @@ bool CAutoResearch::EventProcess(const Event &event)
|
|||
Math::Vector pos, speed;
|
||||
Error message;
|
||||
Math::Point dim;
|
||||
float angle, time;
|
||||
float angle;
|
||||
|
||||
CAuto::EventProcess(event);
|
||||
|
||||
|
@ -111,64 +165,23 @@ bool CAutoResearch::EventProcess(const Event &event)
|
|||
if ( m_object->GetSelect() ) CreateInterface(true);
|
||||
}
|
||||
|
||||
if ( m_object->GetSelect() && // center selected?
|
||||
(event.type == EVENT_OBJECT_RTANK ||
|
||||
event.type == EVENT_OBJECT_RFLY ||
|
||||
event.type == EVENT_OBJECT_RTHUMP ||
|
||||
event.type == EVENT_OBJECT_RCANON ||
|
||||
event.type == EVENT_OBJECT_RTOWER ||
|
||||
event.type == EVENT_OBJECT_RPHAZER ||
|
||||
event.type == EVENT_OBJECT_RSHIELD ||
|
||||
event.type == EVENT_OBJECT_RATOMIC ) )
|
||||
if ( m_object->GetSelect() ) // center selected?
|
||||
{
|
||||
if ( m_phase != ALP_WAIT )
|
||||
{
|
||||
Error err = ERR_GENERIC;
|
||||
if ( event.type == EVENT_OBJECT_RTANK ) err = StartAction(RESEARCH_TANK);
|
||||
if ( event.type == EVENT_OBJECT_RFLY ) err = StartAction(RESEARCH_FLY);
|
||||
if ( event.type == EVENT_OBJECT_RTHUMP ) err = StartAction(RESEARCH_THUMP);
|
||||
if ( event.type == EVENT_OBJECT_RCANON ) err = StartAction(RESEARCH_CANON);
|
||||
if ( event.type == EVENT_OBJECT_RTOWER ) err = StartAction(RESEARCH_TOWER);
|
||||
if ( event.type == EVENT_OBJECT_RPHAZER ) err = StartAction(RESEARCH_PHAZER);
|
||||
if ( event.type == EVENT_OBJECT_RSHIELD ) err = StartAction(RESEARCH_SHIELD);
|
||||
if ( event.type == EVENT_OBJECT_RATOMIC ) err = StartAction(RESEARCH_ATOMIC);
|
||||
|
||||
if( err != ERR_OK && err != ERR_GENERIC )
|
||||
m_displayText->DisplayError(err, m_object);
|
||||
|
||||
if( err != ERR_GENERIC )
|
||||
return false;
|
||||
}
|
||||
|
||||
m_research = event.type;
|
||||
|
||||
if ( TestResearch(m_research) )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_RESEARCH_ALREADY, m_object);
|
||||
return false;
|
||||
}
|
||||
|
||||
power = m_object->GetPower();
|
||||
if ( power == 0 )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_RESEARCH_POWER, m_object);
|
||||
return false;
|
||||
}
|
||||
if ( power->GetCapacity() > 1.0f )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_RESEARCH_TYPE, m_object);
|
||||
return false;
|
||||
}
|
||||
if ( power->GetEnergy() < 1.0f )
|
||||
{
|
||||
m_displayText->DisplayError(ERR_RESEARCH_ENERGY, m_object);
|
||||
return false;
|
||||
}
|
||||
|
||||
time = SEARCH_TIME;
|
||||
if ( event.type == EVENT_OBJECT_RTANK ) time *= 0.3f;
|
||||
if ( event.type == EVENT_OBJECT_RFLY ) time *= 0.3f;
|
||||
if ( event.type == EVENT_OBJECT_RATOMIC ) time *= 2.0f;
|
||||
|
||||
SetBusy(true);
|
||||
InitProgressTotal(time);
|
||||
UpdateInterface();
|
||||
|
||||
m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(0), 0.0f, 1.0f, true);
|
||||
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 2.0f, SOPER_CONTINUE);
|
||||
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE);
|
||||
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
|
||||
|
||||
m_phase = ALP_SEARCH;
|
||||
m_progress = 0.0f;
|
||||
m_speed = 1.0f/time;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( event.type != EVENT_FRAME ) return true;
|
||||
|
@ -236,18 +249,25 @@ bool CAutoResearch::EventProcess(const Event &event)
|
|||
}
|
||||
else
|
||||
{
|
||||
SetResearch(m_research); // research done
|
||||
g_researchDone |= m_research; // research done
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
UpdateInterface();
|
||||
|
||||
m_displayText->DisplayError(INFO_RESEARCH, m_object);
|
||||
|
||||
message = ERR_OK;
|
||||
if ( m_research == EVENT_OBJECT_RTANK ) message = INFO_RESEARCHTANK;
|
||||
if ( m_research == EVENT_OBJECT_RFLY ) message = INFO_RESEARCHFLY;
|
||||
if ( m_research == EVENT_OBJECT_RTHUMP ) message = INFO_RESEARCHTHUMP;
|
||||
if ( m_research == EVENT_OBJECT_RCANON ) message = INFO_RESEARCHCANON;
|
||||
if ( m_research == EVENT_OBJECT_RTOWER ) message = INFO_RESEARCHTOWER;
|
||||
if ( m_research == EVENT_OBJECT_RPHAZER ) message = INFO_RESEARCHPHAZER;
|
||||
if ( m_research == EVENT_OBJECT_RSHIELD ) message = INFO_RESEARCHSHIELD;
|
||||
if ( m_research == EVENT_OBJECT_RATOMIC ) message = INFO_RESEARCHATOMIC;
|
||||
if ( m_research == RESEARCH_TANK ) message = INFO_RESEARCHTANK;
|
||||
if ( m_research == RESEARCH_FLY ) message = INFO_RESEARCHFLY;
|
||||
if ( m_research == RESEARCH_THUMP ) message = INFO_RESEARCHTHUMP;
|
||||
if ( m_research == RESEARCH_CANON ) message = INFO_RESEARCHCANON;
|
||||
if ( m_research == RESEARCH_TOWER ) message = INFO_RESEARCHTOWER;
|
||||
if ( m_research == RESEARCH_PHAZER ) message = INFO_RESEARCHPHAZER;
|
||||
if ( m_research == RESEARCH_SHIELD ) message = INFO_RESEARCHSHIELD;
|
||||
if ( m_research == RESEARCH_ATOMIC ) message = INFO_RESEARCHATOMIC;
|
||||
if ( message != ERR_OK )
|
||||
{
|
||||
m_displayText->DisplayError(message, m_object);
|
||||
|
@ -474,27 +494,6 @@ bool CAutoResearch::TestResearch(EventType event)
|
|||
return false;
|
||||
}
|
||||
|
||||
// Indicates a search as made.
|
||||
|
||||
void CAutoResearch::SetResearch(EventType event)
|
||||
{
|
||||
|
||||
if ( event == EVENT_OBJECT_RTANK ) g_researchDone |= RESEARCH_TANK;
|
||||
if ( event == EVENT_OBJECT_RFLY ) g_researchDone |= RESEARCH_FLY;
|
||||
if ( event == EVENT_OBJECT_RTHUMP ) g_researchDone |= RESEARCH_THUMP;
|
||||
if ( event == EVENT_OBJECT_RCANON ) g_researchDone |= RESEARCH_CANON;
|
||||
if ( event == EVENT_OBJECT_RTOWER ) g_researchDone |= RESEARCH_TOWER;
|
||||
if ( event == EVENT_OBJECT_RPHAZER ) g_researchDone |= RESEARCH_PHAZER;
|
||||
if ( event == EVENT_OBJECT_RSHIELD ) g_researchDone |= RESEARCH_SHIELD;
|
||||
if ( event == EVENT_OBJECT_RATOMIC ) g_researchDone |= RESEARCH_ATOMIC;
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
UpdateInterface();
|
||||
}
|
||||
|
||||
|
||||
// Updates the stop lights.
|
||||
|
||||
|
@ -600,7 +599,7 @@ bool CAutoResearch::Read(char *line)
|
|||
m_phase = static_cast< AutoResearchPhase >(OpInt(line, "aPhase", ALP_WAIT));
|
||||
m_progress = OpFloat(line, "aProgress", 0.0f);
|
||||
m_speed = OpFloat(line, "aSpeed", 1.0f);
|
||||
m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
|
||||
m_research = static_cast< ResearchType >(OpInt(line, "aResearch", 0));
|
||||
|
||||
m_lastUpdateTime = 0.0f;
|
||||
m_lastParticle = 0.0f;
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
void DeleteObject(bool bAll=false);
|
||||
|
||||
void Init();
|
||||
Error StartAction(int result);
|
||||
bool EventProcess(const Event &event);
|
||||
Error GetError();
|
||||
|
||||
|
@ -54,7 +55,6 @@ protected:
|
|||
void UpdateInterface(float rTime);
|
||||
void OkayButton(Ui::CWindow *pw, EventType event);
|
||||
bool TestResearch(EventType event);
|
||||
void SetResearch(EventType event);
|
||||
void FireStopUpdate(float progress, bool bLightOn);
|
||||
|
||||
protected:
|
||||
|
@ -64,7 +64,7 @@ protected:
|
|||
float m_timeVirus;
|
||||
float m_lastUpdateTime;
|
||||
float m_lastParticle;
|
||||
EventType m_research;
|
||||
ResearchType m_research;
|
||||
int m_partiStop[6];
|
||||
int m_channelSound;
|
||||
};
|
||||
|
|
|
@ -873,9 +873,10 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
|
|||
bc->AddItem("energyCell", CBotTypResult(CBotTypPointer, "object"), PR_READ);
|
||||
bc->AddItem("load", CBotTypResult(CBotTypPointer, "object"), PR_READ);
|
||||
bc->AddItem("id", CBotTypResult(CBotTypInt), PR_READ);
|
||||
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
|
||||
bc->AddFunction("factory", CScript::rFactory, CScript::cFactory);
|
||||
bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
|
||||
bc->AddFunction("busy", CScript::rBusy, CScript::cBusy);
|
||||
bc->AddFunction("factory", CScript::rFactory, CScript::cFactory);
|
||||
bc->AddFunction("research", CScript::rResearch, CScript::cClassOneFloat);
|
||||
bc->AddFunction("destroy", CScript::rDestroy, CScript::cClassNull);
|
||||
|
||||
// Initializes the class FILE.
|
||||
InitClassFILE();
|
||||
|
|
|
@ -256,6 +256,7 @@ std::string GetHelpFilename(const char *token)
|
|||
if ( strcmp(token, "progfunc" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt");
|
||||
if ( strcmp(token, "busy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/busy.txt");
|
||||
if ( strcmp(token, "factory" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/factory.txt");
|
||||
if ( strcmp(token, "research" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/research.txt");
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/destroy.txt");
|
||||
if ( strcmp(token, "search" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/search.txt");
|
||||
if ( strcmp(token, "radar" ) == 0 ) return std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + std::string("/cbot/radar.txt");
|
||||
|
@ -382,6 +383,7 @@ bool IsFunction(const char *token)
|
|||
if ( strcmp(token, "progfunc" ) == 0 ) return true;
|
||||
if ( strcmp(token, "busy" ) == 0 ) return true;
|
||||
if ( strcmp(token, "factory" ) == 0 ) return true;
|
||||
if ( strcmp(token, "research" ) == 0 ) return true;
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return true;
|
||||
if ( strcmp(token, "search" ) == 0 ) return true;
|
||||
if ( strcmp(token, "radar" ) == 0 ) return true;
|
||||
|
@ -474,6 +476,7 @@ const char* GetHelpText(const char *token)
|
|||
if ( strcmp(token, "progfunc" ) == 0 ) return "progfunc ( funcname );";
|
||||
if ( strcmp(token, "busy" ) == 0 ) return "object.busy ( );";
|
||||
if ( strcmp(token, "factory" ) == 0 ) return "object.factory ( cat, program );";
|
||||
if ( strcmp(token, "research" ) == 0 ) return "object.research ( type );";
|
||||
if ( strcmp(token, "destroy" ) == 0 ) return "object.destroy ( );";
|
||||
if ( strcmp(token, "search" ) == 0 ) return "search ( );";
|
||||
if ( strcmp(token, "radar" ) == 0 ) return "radar ( cat, angle, focus, min, max, sens );";
|
||||
|
|
|
@ -86,6 +86,11 @@ CBotTypResult CScript::cOneFloat(CBotVar* &var, void* user)
|
|||
return CBotTypResult(CBotTypFloat);
|
||||
}
|
||||
|
||||
CBotTypResult CScript::cClassOneFloat(CBotVar* thisclass, CBotVar* &var)
|
||||
{
|
||||
return CScript::cOneFloat(var, nullptr);
|
||||
}
|
||||
|
||||
// Compiling a procedure with two real numbers.
|
||||
|
||||
CBotTypResult CScript::cTwoFloat(CBotVar* &var, void* user)
|
||||
|
@ -534,6 +539,7 @@ bool CScript::rProgFunc(CBotVar* var, CBotVar* result, int& exception, void* use
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Compilation of instruction "object.busy()"
|
||||
CBotTypResult CScript::cBusy(CBotVar* thisclass, CBotVar* &var)
|
||||
{
|
||||
|
@ -619,7 +625,7 @@ bool CScript::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e
|
|||
}
|
||||
|
||||
|
||||
// Compilation of instruction "object.factory(cat)"
|
||||
// Compilation of instruction "object.factory(cat, program)"
|
||||
|
||||
CBotTypResult CScript::cFactory(CBotVar* thisclass, CBotVar* &var)
|
||||
{
|
||||
|
@ -635,7 +641,7 @@ CBotTypResult CScript::cFactory(CBotVar* thisclass, CBotVar* &var)
|
|||
return CBotTypResult(CBotTypFloat);
|
||||
}
|
||||
|
||||
// Instruction "object.factory(cat)"
|
||||
// Instruction "object.factory(cat, program)"
|
||||
|
||||
bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
|
||||
{
|
||||
|
@ -812,6 +818,88 @@ bool CScript::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& e
|
|||
return true;
|
||||
}
|
||||
|
||||
// Instruction "object.research(type)"
|
||||
|
||||
bool CScript::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception)
|
||||
{
|
||||
Error err;
|
||||
|
||||
exception = 0;
|
||||
|
||||
ResearchType type = static_cast<ResearchType>(var->GetValInt());
|
||||
|
||||
CBotVar* classVars = thisclass->GetItemList(); // "category"
|
||||
ObjectType thisType = static_cast<ObjectType>(classVars->GetValInt());
|
||||
classVars = classVars->GetNext(); // "position"
|
||||
classVars = classVars->GetNext(); // "orientation"
|
||||
classVars = classVars->GetNext(); // "pitch"
|
||||
classVars = classVars->GetNext(); // "roll"
|
||||
classVars = classVars->GetNext(); // "energyLevel"
|
||||
classVars = classVars->GetNext(); // "shieldLevel"
|
||||
classVars = classVars->GetNext(); // "temperature"
|
||||
classVars = classVars->GetNext(); // "altitude"
|
||||
classVars = classVars->GetNext(); // "lifeTime"
|
||||
classVars = classVars->GetNext(); // "material"
|
||||
classVars = classVars->GetNext(); // "energyCell"
|
||||
classVars = classVars->GetNext(); // "load"
|
||||
classVars = classVars->GetNext(); // "id"
|
||||
int rank = classVars->GetValInt();
|
||||
CObject* center = CObjectManager::GetInstancePointer()->SearchInstance(rank);
|
||||
CAuto* automat = center->GetAuto();
|
||||
|
||||
if ( thisType == OBJECT_RESEARCH ||
|
||||
thisType == OBJECT_LABO )
|
||||
{
|
||||
bool ok = false;
|
||||
if ( type == RESEARCH_iPAW ||
|
||||
type == RESEARCH_iGUN )
|
||||
{
|
||||
if ( thisType != OBJECT_LABO )
|
||||
err = ERR_WRONG_OBJ;
|
||||
else
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( thisType != OBJECT_RESEARCH )
|
||||
err = ERR_WRONG_OBJ;
|
||||
else
|
||||
ok = true;
|
||||
}
|
||||
if ( ok )
|
||||
{
|
||||
bool bEnable = ( g_researchEnable & type );
|
||||
if ( bEnable )
|
||||
{
|
||||
if ( automat != nullptr )
|
||||
{
|
||||
err = automat->StartAction(type);
|
||||
}
|
||||
else
|
||||
err = ERR_GENERIC;
|
||||
}
|
||||
else
|
||||
err = ERR_BUILD_DISABLED;
|
||||
}
|
||||
}
|
||||
else
|
||||
err = ERR_WRONG_OBJ;
|
||||
|
||||
if ( err != ERR_OK )
|
||||
{
|
||||
result->SetValInt(err); // return error
|
||||
//TODO: if ( script->m_errMode == ERM_STOP )
|
||||
if( true )
|
||||
{
|
||||
exception = err;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Compilation of the instruction "delete(rank[, exploType[, force]])".
|
||||
|
||||
CBotTypResult CScript::cDelete(CBotVar* &var, void* user)
|
||||
|
|
|
@ -196,9 +196,11 @@ public:
|
|||
static CBotTypResult cBusy(CBotVar* thisclass, CBotVar* &var);
|
||||
static CBotTypResult cFactory(CBotVar* thisclass, CBotVar* &var);
|
||||
static CBotTypResult cClassNull(CBotVar* thisclass, CBotVar* &var);
|
||||
static CBotTypResult cClassOneFloat(CBotVar* thisclass, CBotVar* &var);
|
||||
|
||||
static bool rBusy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
|
||||
static bool rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
|
||||
static bool rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
|
||||
static bool rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* result, int& exception);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue