Refactored EnableBuild, EnableResearch and DoneResearch
* Moved from global variables to CRobotMain members * Added functions for accessing the values * Cleaned up some code related to building objects, BotFactory, ResearchCenter and AutoLabmaster
parent
38a0849e10
commit
3479c51bb9
|
@ -231,8 +231,4 @@ enum ResearchType
|
|||
|
||||
|
||||
// TODO: move to CRobotMain
|
||||
extern int g_build; // constructible buildings
|
||||
extern int g_researchDone; // research done
|
||||
extern long g_researchEnable; // research available
|
||||
extern float g_unit; // conversion factor
|
||||
|
||||
|
|
|
@ -158,6 +158,32 @@ void CAutoFactory::SetProgram(const char* program)
|
|||
strcpy(m_program, program);
|
||||
}
|
||||
|
||||
ObjectType ObjectTypeFromFactoryButton(EventType eventType)
|
||||
{
|
||||
if ( eventType == EVENT_OBJECT_FACTORYwa ) return OBJECT_MOBILEwa;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYta ) return OBJECT_MOBILEta;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYfa ) return OBJECT_MOBILEfa;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYia ) return OBJECT_MOBILEia;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYws ) return OBJECT_MOBILEws;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYts ) return OBJECT_MOBILEts;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYfs ) return OBJECT_MOBILEfs;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYis ) return OBJECT_MOBILEis;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYwc ) return OBJECT_MOBILEwc;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYtc ) return OBJECT_MOBILEtc;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYfc ) return OBJECT_MOBILEfc;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYic ) return OBJECT_MOBILEic;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYwi ) return OBJECT_MOBILEwi;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYti ) return OBJECT_MOBILEti;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYfi ) return OBJECT_MOBILEfi;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYii ) return OBJECT_MOBILEii;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYrt ) return OBJECT_MOBILErt;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYrc ) return OBJECT_MOBILErc;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYrr ) return OBJECT_MOBILErr;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYrs ) return OBJECT_MOBILErs;
|
||||
if ( eventType == EVENT_OBJECT_FACTORYsa ) return OBJECT_MOBILEsa;
|
||||
|
||||
return OBJECT_NULL;
|
||||
}
|
||||
|
||||
// Management of an event.
|
||||
|
||||
|
@ -184,28 +210,7 @@ bool CAutoFactory::EventProcess(const Event &event)
|
|||
CreateInterface(true);
|
||||
}
|
||||
|
||||
type = OBJECT_NULL;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYwa ) type = OBJECT_MOBILEwa;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYta ) type = OBJECT_MOBILEta;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYfa ) type = OBJECT_MOBILEfa;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYia ) type = OBJECT_MOBILEia;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYws ) type = OBJECT_MOBILEws;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYts ) type = OBJECT_MOBILEts;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYfs ) type = OBJECT_MOBILEfs;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYis ) type = OBJECT_MOBILEis;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYwc ) type = OBJECT_MOBILEwc;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYtc ) type = OBJECT_MOBILEtc;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYfc ) type = OBJECT_MOBILEfc;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYic ) type = OBJECT_MOBILEic;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYwi ) type = OBJECT_MOBILEwi;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYti ) type = OBJECT_MOBILEti;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYfi ) type = OBJECT_MOBILEfi;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYii ) type = OBJECT_MOBILEii;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYrt ) type = OBJECT_MOBILErt;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYrc ) type = OBJECT_MOBILErc;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYrr ) type = OBJECT_MOBILErr;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYrs ) type = OBJECT_MOBILErs;
|
||||
if ( event.type == EVENT_OBJECT_FACTORYsa ) type = OBJECT_MOBILEsa;
|
||||
type = ObjectTypeFromFactoryButton(event.type);
|
||||
|
||||
Error err = StartAction(type);
|
||||
if( err != ERR_OK && err != ERR_GENERIC )
|
||||
|
@ -817,110 +822,8 @@ void CAutoFactory::UpdateInterface()
|
|||
|
||||
void CAutoFactory::UpdateButton(Ui::CWindow *pw, EventType event, bool bBusy)
|
||||
{
|
||||
bool bEnable = true;
|
||||
|
||||
EnableInterface(pw, event, !bBusy);
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYta )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_TANK;
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYfa )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_FLY;
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYia )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_iPAW;
|
||||
}
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYws )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_SNIFFER;
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYts )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYfs )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYis )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYwc )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_CANON;
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYtc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYfc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYic )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYwi )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_iGUN;
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYti )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYfi )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYii )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYrt )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_THUMP) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYrc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_PHAZER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYrr )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_RECYCLER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( event == EVENT_OBJECT_FACTORYrs )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SHIELD) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
|
||||
if ( event == EVENT_OBJECT_FACTORYsa )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_SUBM;
|
||||
}
|
||||
|
||||
DeadInterface(pw, event, bEnable);
|
||||
DeadInterface(pw, event, m_main->CanFactory(ObjectTypeFromFactoryButton(event)));
|
||||
}
|
||||
|
||||
// Plays the sound of the manipulator arm.
|
||||
|
@ -934,4 +837,3 @@ void CAutoFactory::SoundManip(float time, float amplitude, float frequency)
|
|||
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, time-0.1f, SOPER_CONTINUE);
|
||||
m_sound->AddEnvelope(i, 0.0f, 0.3f*frequency, 0.1f, SOPER_STOP);
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ Error CAutoLabo::StartAction(int param)
|
|||
|
||||
m_research = static_cast<ResearchType>(param);
|
||||
|
||||
if ( g_researchDone & m_research )
|
||||
if ( m_main->IsResearchDone(m_research) )
|
||||
{
|
||||
return ERR_LABO_ALREADY;
|
||||
}
|
||||
|
@ -352,12 +352,9 @@ bool CAutoLabo::EventProcess(const Event &event)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_researchDone |= m_research; // research done
|
||||
m_main->MarkResearchDone(m_research); // research done
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
UpdateInterface();
|
||||
|
||||
power = m_object->GetPower();
|
||||
|
@ -514,8 +511,8 @@ void CAutoLabo::UpdateInterface()
|
|||
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
|
||||
if ( pw == 0 ) return;
|
||||
|
||||
DeadInterface(pw, EVENT_OBJECT_RiPAW, g_researchEnable&RESEARCH_iPAW);
|
||||
DeadInterface(pw, EVENT_OBJECT_RiGUN, g_researchEnable&RESEARCH_iGUN);
|
||||
DeadInterface(pw, EVENT_OBJECT_RiPAW, m_main->IsResearchEnabled(RESEARCH_iPAW));
|
||||
DeadInterface(pw, EVENT_OBJECT_RiGUN, m_main->IsResearchEnabled(RESEARCH_iGUN));
|
||||
|
||||
OkayButton(pw, EVENT_OBJECT_RiPAW);
|
||||
OkayButton(pw, EVENT_OBJECT_RiGUN);
|
||||
|
@ -541,27 +538,10 @@ void CAutoLabo::OkayButton(Ui::CWindow *pw, EventType event)
|
|||
|
||||
bool CAutoLabo::TestResearch(EventType event)
|
||||
{
|
||||
if ( event == EVENT_OBJECT_RiPAW ) return (g_researchDone & RESEARCH_iPAW);
|
||||
if ( event == EVENT_OBJECT_RiGUN ) return (g_researchDone & RESEARCH_iGUN);
|
||||
if ( event == EVENT_OBJECT_RiPAW ) return m_main->IsResearchDone(RESEARCH_iPAW);
|
||||
if ( event == EVENT_OBJECT_RiGUN ) return m_main->IsResearchDone(RESEARCH_iGUN);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Indicates a search as made.
|
||||
|
||||
void CAutoLabo::SetResearch(EventType event)
|
||||
{
|
||||
|
||||
|
||||
if ( event == EVENT_OBJECT_RiPAW ) g_researchDone |= RESEARCH_iPAW;
|
||||
if ( event == EVENT_OBJECT_RiGUN ) g_researchDone |= RESEARCH_iGUN;
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
// m_eventQueue->MakeEvent(newEvent, EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
UpdateInterface();
|
||||
return m_main;
|
||||
}
|
||||
|
||||
// Plays the sound of the manipulator arm.
|
||||
|
@ -609,4 +589,3 @@ bool CAutoLabo::Read(CLevelParserLine* line)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ protected:
|
|||
void UpdateInterface();
|
||||
void OkayButton(Ui::CWindow *pw, EventType event);
|
||||
bool TestResearch(EventType event);
|
||||
void SetResearch(EventType event);
|
||||
void SoundManip(float time, float amplitude, float frequency);
|
||||
|
||||
protected:
|
||||
|
@ -77,4 +76,3 @@ protected:
|
|||
int m_partiSphere;
|
||||
int m_soundChannel;
|
||||
};
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ Error CAutoResearch::StartAction(int param)
|
|||
|
||||
m_research = static_cast<ResearchType>(param);
|
||||
|
||||
if ( g_researchDone & m_research )
|
||||
if ( m_main->IsResearchDone(m_research) )
|
||||
{
|
||||
return ERR_RESEARCH_ALREADY;
|
||||
}
|
||||
|
@ -246,12 +246,9 @@ bool CAutoResearch::EventProcess(const Event &event)
|
|||
}
|
||||
else
|
||||
{
|
||||
g_researchDone |= m_research; // research done
|
||||
m_main->MarkResearchDone(m_research); // research done
|
||||
|
||||
m_main->WriteFreeParam();
|
||||
|
||||
Event newEvent(EVENT_UPDINTERFACE);
|
||||
m_eventQueue->AddEvent(newEvent);
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
UpdateInterface();
|
||||
|
||||
m_main->DisplayError(INFO_RESEARCH, m_object);
|
||||
|
@ -399,14 +396,14 @@ void CAutoResearch::UpdateInterface()
|
|||
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
|
||||
if ( pw == 0 ) return;
|
||||
|
||||
DeadInterface(pw, EVENT_OBJECT_RTANK, g_researchEnable&RESEARCH_TANK);
|
||||
DeadInterface(pw, EVENT_OBJECT_RFLY, g_researchEnable&RESEARCH_FLY);
|
||||
DeadInterface(pw, EVENT_OBJECT_RTHUMP, g_researchEnable&RESEARCH_THUMP);
|
||||
DeadInterface(pw, EVENT_OBJECT_RCANON, g_researchEnable&RESEARCH_CANON);
|
||||
DeadInterface(pw, EVENT_OBJECT_RTOWER, g_researchEnable&RESEARCH_TOWER);
|
||||
DeadInterface(pw, EVENT_OBJECT_RPHAZER, g_researchEnable&RESEARCH_PHAZER);
|
||||
DeadInterface(pw, EVENT_OBJECT_RSHIELD, g_researchEnable&RESEARCH_SHIELD);
|
||||
DeadInterface(pw, EVENT_OBJECT_RATOMIC, g_researchEnable&RESEARCH_ATOMIC);
|
||||
DeadInterface(pw, EVENT_OBJECT_RTANK, m_main->IsResearchEnabled(RESEARCH_TANK));
|
||||
DeadInterface(pw, EVENT_OBJECT_RFLY, m_main->IsResearchEnabled(RESEARCH_FLY));
|
||||
DeadInterface(pw, EVENT_OBJECT_RTHUMP, m_main->IsResearchEnabled(RESEARCH_THUMP));
|
||||
DeadInterface(pw, EVENT_OBJECT_RCANON, m_main->IsResearchEnabled(RESEARCH_CANON));
|
||||
DeadInterface(pw, EVENT_OBJECT_RTOWER, m_main->IsResearchEnabled(RESEARCH_TOWER));
|
||||
DeadInterface(pw, EVENT_OBJECT_RPHAZER, m_main->IsResearchEnabled(RESEARCH_PHAZER));
|
||||
DeadInterface(pw, EVENT_OBJECT_RSHIELD, m_main->IsResearchEnabled(RESEARCH_SHIELD));
|
||||
DeadInterface(pw, EVENT_OBJECT_RATOMIC, m_main->IsResearchEnabled(RESEARCH_ATOMIC));
|
||||
|
||||
OkayButton(pw, EVENT_OBJECT_RTANK);
|
||||
OkayButton(pw, EVENT_OBJECT_RFLY);
|
||||
|
@ -467,14 +464,14 @@ void CAutoResearch::OkayButton(Ui::CWindow *pw, EventType event)
|
|||
|
||||
bool CAutoResearch::TestResearch(EventType event)
|
||||
{
|
||||
if ( event == EVENT_OBJECT_RTANK ) return (g_researchDone & RESEARCH_TANK );
|
||||
if ( event == EVENT_OBJECT_RFLY ) return (g_researchDone & RESEARCH_FLY );
|
||||
if ( event == EVENT_OBJECT_RTHUMP ) return (g_researchDone & RESEARCH_THUMP );
|
||||
if ( event == EVENT_OBJECT_RCANON ) return (g_researchDone & RESEARCH_CANON );
|
||||
if ( event == EVENT_OBJECT_RTOWER ) return (g_researchDone & RESEARCH_TOWER );
|
||||
if ( event == EVENT_OBJECT_RPHAZER ) return (g_researchDone & RESEARCH_PHAZER );
|
||||
if ( event == EVENT_OBJECT_RSHIELD ) return (g_researchDone & RESEARCH_SHIELD);
|
||||
if ( event == EVENT_OBJECT_RATOMIC ) return (g_researchDone & RESEARCH_ATOMIC);
|
||||
if ( event == EVENT_OBJECT_RTANK ) return m_main->IsResearchDone(RESEARCH_TANK);
|
||||
if ( event == EVENT_OBJECT_RFLY ) return m_main->IsResearchDone(RESEARCH_FLY);
|
||||
if ( event == EVENT_OBJECT_RTHUMP ) return m_main->IsResearchDone(RESEARCH_THUMP);
|
||||
if ( event == EVENT_OBJECT_RCANON ) return m_main->IsResearchDone(RESEARCH_CANON);
|
||||
if ( event == EVENT_OBJECT_RTOWER ) return m_main->IsResearchDone(RESEARCH_TOWER);
|
||||
if ( event == EVENT_OBJECT_RPHAZER ) return m_main->IsResearchDone(RESEARCH_PHAZER);
|
||||
if ( event == EVENT_OBJECT_RSHIELD ) return m_main->IsResearchDone(RESEARCH_SHIELD);
|
||||
if ( event == EVENT_OBJECT_RATOMIC ) return m_main->IsResearchDone(RESEARCH_ATOMIC);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -578,4 +575,3 @@ bool CAutoResearch::Read(CLevelParserLine* line)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -573,7 +573,7 @@ bool CBrain::EventProcess(const Event &event)
|
|||
axeY *= 0.5f;
|
||||
}
|
||||
|
||||
if ( (g_researchDone&RESEARCH_FLY) == 0 )
|
||||
if ( !m_main->IsResearchDone(RESEARCH_FLY) )
|
||||
{
|
||||
axeZ = -1.0f; // tomb
|
||||
}
|
||||
|
@ -1540,85 +1540,81 @@ bool CBrain::CreateInterface(bool bSelect)
|
|||
pos.x = ox+sx*0.0f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+35, EVENT_OBJECT_BRESEARCH);
|
||||
DeadInterface(pw, EVENT_OBJECT_BRESEARCH, g_build&BUILD_RESEARCH);
|
||||
DeadInterface(pw, EVENT_OBJECT_BRESEARCH, m_main->CanBuild(OBJECT_RESEARCH));
|
||||
|
||||
pos.x = ox+sx*0.9f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+32, EVENT_OBJECT_BFACTORY);
|
||||
DeadInterface(pw, EVENT_OBJECT_BFACTORY, g_build&BUILD_FACTORY);
|
||||
DeadInterface(pw, EVENT_OBJECT_BFACTORY, m_main->CanBuild(OBJECT_FACTORY));
|
||||
|
||||
pos.x = ox+sx*1.8f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+34, EVENT_OBJECT_BCONVERT);
|
||||
DeadInterface(pw, EVENT_OBJECT_BCONVERT, g_build&BUILD_CONVERT);
|
||||
DeadInterface(pw, EVENT_OBJECT_BCONVERT, m_main->CanBuild(OBJECT_CONVERT));
|
||||
|
||||
pos.x = ox+sx*2.7f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+36, EVENT_OBJECT_BSTATION);
|
||||
DeadInterface(pw, EVENT_OBJECT_BSTATION, g_build&BUILD_STATION);
|
||||
DeadInterface(pw, EVENT_OBJECT_BSTATION, m_main->CanBuild(OBJECT_STATION));
|
||||
|
||||
pos.x = ox+sx*3.6f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+40, EVENT_OBJECT_BRADAR);
|
||||
DeadInterface(pw, EVENT_OBJECT_BRADAR, g_build&BUILD_RADAR);
|
||||
DeadInterface(pw, EVENT_OBJECT_BRADAR, m_main->CanBuild(OBJECT_RADAR));
|
||||
|
||||
pos.x = ox+sx*4.5f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+41, EVENT_OBJECT_BREPAIR);
|
||||
DeadInterface(pw, EVENT_OBJECT_BREPAIR, g_build&BUILD_REPAIR);
|
||||
DeadInterface(pw, EVENT_OBJECT_BREPAIR, m_main->CanBuild(OBJECT_REPAIR));
|
||||
|
||||
pos.x = ox+sx*5.4f;
|
||||
pos.y = oy+sy*1.0f;
|
||||
pw->CreateButton(pos, ddim, 128+44, EVENT_OBJECT_BINFO);
|
||||
DeadInterface(pw, EVENT_OBJECT_BINFO, g_build&BUILD_INFO);
|
||||
DeadInterface(pw, EVENT_OBJECT_BINFO, m_main->CanBuild(OBJECT_INFO));
|
||||
|
||||
pos.x = ox+sx*0.0f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+37, EVENT_OBJECT_BTOWER);
|
||||
DeadInterface(pw, EVENT_OBJECT_BTOWER,
|
||||
(g_build&BUILD_TOWER) &&
|
||||
(g_researchDone & RESEARCH_TOWER));
|
||||
DeadInterface(pw, EVENT_OBJECT_BTOWER, m_main->CanBuild(OBJECT_TOWER));
|
||||
|
||||
pos.x = ox+sx*0.9f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+39, EVENT_OBJECT_BENERGY);
|
||||
DeadInterface(pw, EVENT_OBJECT_BENERGY, g_build&BUILD_ENERGY);
|
||||
DeadInterface(pw, EVENT_OBJECT_BENERGY, m_main->CanBuild(OBJECT_ENERGY));
|
||||
|
||||
pos.x = ox+sx*1.8f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+33, EVENT_OBJECT_BDERRICK);
|
||||
DeadInterface(pw, EVENT_OBJECT_BDERRICK, g_build&BUILD_DERRICK);
|
||||
DeadInterface(pw, EVENT_OBJECT_BDERRICK, m_main->CanBuild(OBJECT_DERRICK));
|
||||
|
||||
pos.x = ox+sx*2.7f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+42, EVENT_OBJECT_BNUCLEAR);
|
||||
DeadInterface(pw, EVENT_OBJECT_BNUCLEAR,
|
||||
(g_build&BUILD_NUCLEAR) &&
|
||||
(g_researchDone & RESEARCH_ATOMIC));
|
||||
DeadInterface(pw, EVENT_OBJECT_BNUCLEAR, m_main->CanBuild(OBJECT_NUCLEAR));
|
||||
|
||||
pos.x = ox+sx*3.6f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+38, EVENT_OBJECT_BLABO);
|
||||
DeadInterface(pw, EVENT_OBJECT_BLABO, g_build&BUILD_LABO);
|
||||
DeadInterface(pw, EVENT_OBJECT_BLABO, m_main->CanBuild(OBJECT_LABO));
|
||||
|
||||
pos.x = ox+sx*4.5f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+46, EVENT_OBJECT_BPARA);
|
||||
DeadInterface(pw, EVENT_OBJECT_BPARA, g_build&BUILD_PARA);
|
||||
DeadInterface(pw, EVENT_OBJECT_BPARA, m_main->CanBuild(OBJECT_PARA));
|
||||
|
||||
pos.x = ox+sx*5.4f;
|
||||
pos.y = oy+sy*0.1f;
|
||||
pw->CreateButton(pos, ddim, 128+41, EVENT_OBJECT_BDESTROYER);
|
||||
DeadInterface(pw, EVENT_OBJECT_BDESTROYER, g_build&BUILD_DESTROYER);
|
||||
DeadInterface(pw, EVENT_OBJECT_BDESTROYER, m_main->CanBuild(OBJECT_DESTROYER));
|
||||
|
||||
if ( g_build&BUILD_GFLAT )
|
||||
if ( m_main->IsBuildingEnabled(BUILD_GFLAT) )
|
||||
{
|
||||
pos.x = ox+sx*9.0f;
|
||||
pos.y = oy+sy*0.5f;
|
||||
pw->CreateButton(pos, dim, 64+47, EVENT_OBJECT_GFLAT);
|
||||
}
|
||||
|
||||
if ( g_build&BUILD_FLAG )
|
||||
if ( m_main->IsBuildingEnabled(BUILD_FLAG) )
|
||||
{
|
||||
pos.x = ox+sx*10.1f;
|
||||
pos.y = oy+sy*0.5f;
|
||||
|
@ -1660,7 +1656,7 @@ bool CBrain::CreateInterface(bool bSelect)
|
|||
pw->CreateButton(pos, dim, 40, EVENT_OBJECT_SEARCH);
|
||||
DefaultEnter(pw, EVENT_OBJECT_SEARCH);
|
||||
|
||||
if ( g_build&BUILD_GFLAT )
|
||||
if ( m_main->IsBuildingEnabled(BUILD_GFLAT) )
|
||||
{
|
||||
pos.x = ox+sx*9.0f;
|
||||
pos.y = oy+sy*0.5f;
|
||||
|
@ -2407,8 +2403,8 @@ void CBrain::UpdateInterface()
|
|||
}
|
||||
else
|
||||
{
|
||||
DeadInterface(pw, EVENT_OBJECT_GASUP, g_researchDone&RESEARCH_FLY);
|
||||
DeadInterface(pw, EVENT_OBJECT_GASDOWN, g_researchDone&RESEARCH_FLY);
|
||||
DeadInterface(pw, EVENT_OBJECT_GASUP, m_main->IsResearchDone(RESEARCH_FLY));
|
||||
DeadInterface(pw, EVENT_OBJECT_GASDOWN, m_main->IsResearchDone(RESEARCH_FLY));
|
||||
}
|
||||
|
||||
if ( type == OBJECT_HUMAN ||
|
||||
|
@ -3224,4 +3220,4 @@ Program* CBrain::GetOrAddProgram(int index)
|
|||
AddProgram();
|
||||
}
|
||||
return AddProgram();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,13 @@ DriveType GetDriveFromObject(ObjectType type)
|
|||
case OBJECT_MOBILEis:
|
||||
return DriveType::Legged;
|
||||
|
||||
case OBJECT_MOBILErt:
|
||||
case OBJECT_MOBILErc:
|
||||
case OBJECT_MOBILErr:
|
||||
case OBJECT_MOBILErs:
|
||||
// NOTE: Subber is not BigTracked!
|
||||
return DriveType::BigTracked;
|
||||
|
||||
default:
|
||||
return DriveType::Other;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ enum class DriveType : unsigned int
|
|||
Tracked,
|
||||
Winged,
|
||||
Legged,
|
||||
BigTracked,
|
||||
};
|
||||
|
||||
DriveType GetDriveFromObject(ObjectType type);
|
||||
|
|
|
@ -638,6 +638,7 @@ DriveType CLevelParserParam::ToDriveType(std::string value)
|
|||
if (value == "Tracked") return DriveType::Tracked;
|
||||
if (value == "Winged" ) return DriveType::Winged;
|
||||
if (value == "Legged" ) return DriveType::Legged;
|
||||
if (value == "BigTracked") return DriveType::BigTracked;
|
||||
if (value == "Other" ) return DriveType::Other;
|
||||
return static_cast<DriveType>(Cast<int>(value, "drive"));
|
||||
}
|
||||
|
|
|
@ -113,9 +113,6 @@ const float UNIT = 4.0f;
|
|||
|
||||
// Global variables.
|
||||
|
||||
int g_build; // constructible buildings
|
||||
int g_researchDone; // research done
|
||||
long g_researchEnable; // research available
|
||||
float g_unit; // conversion factor
|
||||
|
||||
|
||||
|
@ -231,9 +228,9 @@ CRobotMain::CRobotMain(CController* controller)
|
|||
m_cameraPan = 0.0f;
|
||||
m_cameraZoom = 0.0f;
|
||||
|
||||
g_build = 0;
|
||||
g_researchDone = 0; // no research done
|
||||
g_researchEnable = 0;
|
||||
m_build = 0;
|
||||
m_researchDone = 0; // no research done
|
||||
m_researchEnable = 0;
|
||||
g_unit = UNIT;
|
||||
|
||||
m_gamerName = "";
|
||||
|
@ -1124,7 +1121,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
|
|||
|
||||
if (strcmp(cmd, "fly") == 0)
|
||||
{
|
||||
g_researchDone |= RESEARCH_FLY;
|
||||
m_researchDone |= RESEARCH_FLY;
|
||||
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return;
|
||||
|
@ -1132,7 +1129,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
|
|||
|
||||
if (strcmp(cmd, "allresearch") == 0)
|
||||
{
|
||||
g_researchDone = -1; // all research are done
|
||||
m_researchDone = -1; // all research are done
|
||||
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return;
|
||||
|
@ -1140,7 +1137,7 @@ void CRobotMain::ExecuteCmd(char *cmd)
|
|||
|
||||
if (strcmp(cmd, "allbuildings") == 0)
|
||||
{
|
||||
g_build = -1; // all buildings are available
|
||||
m_build = -1; // all buildings are available
|
||||
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return;
|
||||
|
@ -1148,8 +1145,8 @@ void CRobotMain::ExecuteCmd(char *cmd)
|
|||
|
||||
if (strcmp(cmd, "all") == 0)
|
||||
{
|
||||
g_researchDone = -1; // all research are done
|
||||
g_build = -1; // all buildings are available
|
||||
m_researchDone = -1; // all research are done
|
||||
m_build = -1; // all buildings are available
|
||||
|
||||
m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return;
|
||||
|
@ -2896,9 +2893,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
|
||||
if (!resetObject)
|
||||
{
|
||||
g_build = 0;
|
||||
g_researchDone = 0; // no research done
|
||||
g_researchEnable = 0;
|
||||
m_build = 0;
|
||||
m_researchDone = 0; // no research done
|
||||
m_researchEnable = 0;
|
||||
|
||||
FlushDisplayInfo();
|
||||
m_terrain->FlushMaterials();
|
||||
|
@ -3877,19 +3874,19 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
|
||||
if (line->GetCommand() == "EnableBuild" && !resetObject)
|
||||
{
|
||||
g_build |= line->GetParam("type")->AsBuildFlag();
|
||||
m_build |= line->GetParam("type")->AsBuildFlag();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line->GetCommand() == "EnableResearch" && !resetObject)
|
||||
{
|
||||
g_researchEnable |= line->GetParam("type")->AsResearchFlag();
|
||||
m_researchEnable |= line->GetParam("type")->AsResearchFlag();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line->GetCommand() == "DoneResearch" && read[0] == 0 && !resetObject) // not loading file?
|
||||
{
|
||||
g_researchDone |= line->GetParam("type")->AsResearchFlag();
|
||||
m_researchDone |= line->GetParam("type")->AsResearchFlag();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3913,14 +3910,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
|
||||
if (strcmp(base, "freemissions") == 0 && !resetObject) // free play?
|
||||
{
|
||||
g_researchDone = m_freeResearch;
|
||||
m_researchDone = m_freeResearch;
|
||||
|
||||
g_build = m_freeBuild;
|
||||
g_build &= ~BUILD_RESEARCH;
|
||||
g_build &= ~BUILD_LABO;
|
||||
g_build |= BUILD_FACTORY;
|
||||
g_build |= BUILD_GFLAT;
|
||||
g_build |= BUILD_FLAG;
|
||||
m_build = m_freeBuild;
|
||||
m_build &= ~BUILD_RESEARCH;
|
||||
m_build &= ~BUILD_LABO;
|
||||
m_build |= BUILD_FACTORY;
|
||||
m_build |= BUILD_GFLAT;
|
||||
m_build |= BUILD_FLAG;
|
||||
}
|
||||
|
||||
if (!resetObject && !fixScene)
|
||||
|
@ -4939,7 +4936,7 @@ bool CRobotMain::IOWriteScene(const char *filename, const char *filecbot, char *
|
|||
levelParser.AddLine(std::move(line));
|
||||
|
||||
line.reset(new CLevelParserLine("DoneResearch"));
|
||||
line->AddParam("bits", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(g_researchDone))});
|
||||
line->AddParam("bits", CLevelParserParamUPtr{new CLevelParserParam(static_cast<int>(m_researchDone))});
|
||||
levelParser.AddLine(std::move(line));
|
||||
|
||||
float sleep, delay, magnetic, progress;
|
||||
|
@ -5131,7 +5128,7 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
m_map->ZoomMap(line->GetParam("zoom")->AsFloat());
|
||||
|
||||
if (line->GetCommand() == "DoneResearch")
|
||||
g_researchDone = line->GetParam("bits")->AsInt();
|
||||
m_researchDone = line->GetParam("bits")->AsInt();
|
||||
|
||||
if (line->GetCommand() == "BlitzMode")
|
||||
{
|
||||
|
@ -5249,8 +5246,8 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
|
|||
//! Writes the global parameters for free play
|
||||
void CRobotMain::WriteFreeParam()
|
||||
{
|
||||
m_freeResearch |= g_researchDone;
|
||||
m_freeBuild |= g_build;
|
||||
m_freeResearch |= m_researchDone;
|
||||
m_freeBuild |= m_build;
|
||||
|
||||
if (m_gamerName == "") return;
|
||||
|
||||
|
@ -5577,7 +5574,7 @@ Error CRobotMain::CheckEndMission(bool frame)
|
|||
{
|
||||
if (m_endTakeResearch != 0)
|
||||
{
|
||||
if (m_endTakeResearch != (m_endTakeResearch&g_researchDone))
|
||||
if (m_endTakeResearch != (m_endTakeResearch&m_researchDone))
|
||||
{
|
||||
m_missionResult = ERR_MISSION_NOTERM;
|
||||
}
|
||||
|
@ -6224,4 +6221,120 @@ const std::string& CRobotMain::GetTeamName(int id)
|
|||
{
|
||||
if(m_teamNames.count(id) == 0) return NO_TEAM_NAME;
|
||||
return m_teamNames[id];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CRobotMain::GetEnableBuild()
|
||||
{
|
||||
return m_build;
|
||||
}
|
||||
|
||||
void CRobotMain::SetEnableBuild(int enableBuild)
|
||||
{
|
||||
m_build = enableBuild;
|
||||
}
|
||||
|
||||
int CRobotMain::GetEnableResearch()
|
||||
{
|
||||
return m_researchEnable;
|
||||
}
|
||||
|
||||
void CRobotMain::SetEnableResearch(int enableResearch)
|
||||
{
|
||||
m_researchEnable = enableResearch;
|
||||
}
|
||||
|
||||
int CRobotMain::GetDoneResearch()
|
||||
{
|
||||
return m_researchDone;
|
||||
}
|
||||
|
||||
void CRobotMain::SetDoneResearch(int doneResearch)
|
||||
{
|
||||
m_researchDone = doneResearch;
|
||||
}
|
||||
|
||||
|
||||
bool CRobotMain::IsBuildingEnabled(BuildType type)
|
||||
{
|
||||
return (m_build & type) != 0;
|
||||
}
|
||||
|
||||
bool CRobotMain::IsBuildingEnabled(ObjectType type)
|
||||
{
|
||||
if(type == OBJECT_DERRICK) return IsBuildingEnabled(BUILD_DERRICK);
|
||||
if(type == OBJECT_FACTORY) return IsBuildingEnabled(BUILD_FACTORY);
|
||||
if(type == OBJECT_STATION) return IsBuildingEnabled(BUILD_STATION);
|
||||
if(type == OBJECT_CONVERT) return IsBuildingEnabled(BUILD_CONVERT);
|
||||
if(type == OBJECT_REPAIR) return IsBuildingEnabled(BUILD_REPAIR);
|
||||
if(type == OBJECT_TOWER) return IsBuildingEnabled(BUILD_TOWER);
|
||||
if(type == OBJECT_RESEARCH) return IsBuildingEnabled(BUILD_RESEARCH);
|
||||
if(type == OBJECT_RADAR) return IsBuildingEnabled(BUILD_RADAR);
|
||||
if(type == OBJECT_ENERGY) return IsBuildingEnabled(BUILD_ENERGY);
|
||||
if(type == OBJECT_LABO) return IsBuildingEnabled(BUILD_LABO);
|
||||
if(type == OBJECT_NUCLEAR) return IsBuildingEnabled(BUILD_NUCLEAR);
|
||||
if(type == OBJECT_INFO) return IsBuildingEnabled(BUILD_INFO);
|
||||
if(type == OBJECT_PARA) return IsBuildingEnabled(BUILD_PARA);
|
||||
if(type == OBJECT_DESTROYER) return IsBuildingEnabled(BUILD_DESTROYER);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CRobotMain::IsResearchEnabled(ResearchType type)
|
||||
{
|
||||
return (m_researchEnable & type) != 0;
|
||||
}
|
||||
|
||||
bool CRobotMain::IsResearchDone(ResearchType type)
|
||||
{
|
||||
return (m_researchDone & type) != 0;
|
||||
}
|
||||
|
||||
void CRobotMain::MarkResearchDone(ResearchType type)
|
||||
{
|
||||
m_researchDone |= type;
|
||||
WriteFreeParam();
|
||||
}
|
||||
|
||||
Error CRobotMain::CanBuildError(ObjectType type)
|
||||
{
|
||||
if(!IsBuildingEnabled(type)) return ERR_BUILD_DISABLED;
|
||||
|
||||
if(type == OBJECT_TOWER && !IsResearchDone(RESEARCH_TOWER)) return ERR_BUILD_RESEARCH;
|
||||
if(type == OBJECT_ATOMIC && !IsResearchDone(RESEARCH_ATOMIC)) return ERR_BUILD_RESEARCH;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool CRobotMain::CanBuild(ObjectType type)
|
||||
{
|
||||
return CanBuildError(type) == ERR_OK;
|
||||
}
|
||||
|
||||
Error CRobotMain::CanFactoryError(ObjectType type)
|
||||
{
|
||||
ToolType tool = GetToolFromObject(type);
|
||||
DriveType drive = GetDriveFromObject(type);
|
||||
|
||||
if (tool == ToolType::Sniffer && !IsResearchDone(RESEARCH_SNIFFER) ) return ERR_BUILD_RESEARCH;
|
||||
if (tool == ToolType::Shooter && !IsResearchDone(RESEARCH_CANON) ) return ERR_BUILD_RESEARCH;
|
||||
if (tool == ToolType::OrganicShooter && !IsResearchDone(RESEARCH_iGUN) ) return ERR_BUILD_RESEARCH;
|
||||
|
||||
if (drive == DriveType::Tracked && !IsResearchDone(RESEARCH_TANK) ) return ERR_BUILD_RESEARCH;
|
||||
if (drive == DriveType::Winged && !IsResearchDone(RESEARCH_FLY) ) return ERR_BUILD_RESEARCH;
|
||||
if (drive == DriveType::Legged && !IsResearchDone(RESEARCH_iPAW) ) return ERR_BUILD_RESEARCH;
|
||||
if (drive == DriveType::BigTracked && !IsResearchDone(RESEARCH_TANK) ) return ERR_BUILD_RESEARCH; // NOTE: Subber is not BigTracked! It currently counts as Other
|
||||
|
||||
if (type == OBJECT_MOBILErt && !IsResearchDone(RESEARCH_THUMP) ) return ERR_BUILD_RESEARCH;
|
||||
if (type == OBJECT_MOBILErc && !IsResearchDone(RESEARCH_PHAZER) ) return ERR_BUILD_RESEARCH;
|
||||
if (type == OBJECT_MOBILErr && !IsResearchDone(RESEARCH_RECYCLER)) return ERR_BUILD_RESEARCH;
|
||||
if (type == OBJECT_MOBILErs && !IsResearchDone(RESEARCH_SHIELD) ) return ERR_BUILD_RESEARCH;
|
||||
if (type == OBJECT_MOBILEsa && !IsResearchDone(RESEARCH_SUBM) ) return ERR_BUILD_DISABLED; // Can be only researched manually in Scene file
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool CRobotMain::CanFactory(ObjectType type)
|
||||
{
|
||||
return CanFactoryError(type) == ERR_OK;
|
||||
}
|
||||
|
|
|
@ -331,6 +331,46 @@ public:
|
|||
//! Returns team name for the given team id
|
||||
const std::string& GetTeamName(int id);
|
||||
|
||||
//! Get/set enabled buildings
|
||||
//@{
|
||||
int GetEnableBuild();
|
||||
void SetEnableBuild(int enableBuild);
|
||||
//@}
|
||||
//! Get/set enabled researches
|
||||
//@{
|
||||
int GetEnableResearch();
|
||||
void SetEnableResearch(int enableResearch);
|
||||
//@}
|
||||
//! Get/set done researches
|
||||
//@{
|
||||
int GetDoneResearch();
|
||||
void SetDoneResearch(int doneResearch);
|
||||
//@}
|
||||
|
||||
//! Returns true if the given building is enabled
|
||||
//@{
|
||||
bool IsBuildingEnabled(BuildType type);
|
||||
bool IsBuildingEnabled(ObjectType type);
|
||||
//@}
|
||||
//! Returns true if the given research is enabled
|
||||
bool IsResearchEnabled(ResearchType type);
|
||||
//! Returns true if the given research is done
|
||||
bool IsResearchDone(ResearchType type);
|
||||
//! Marks research as done
|
||||
void MarkResearchDone(ResearchType type);
|
||||
|
||||
//! Retruns true if all requirements to build this object are met (EnableBuild + DoneResearch)
|
||||
//@{
|
||||
bool CanBuild(ObjectType type);
|
||||
Error CanBuildError(ObjectType type);
|
||||
//@}
|
||||
|
||||
//! Retruns true if all requirements to create this object in BotFactory are met (DoneResearch)
|
||||
//@{
|
||||
bool CanFactory(ObjectType type);
|
||||
Error CanFactoryError(ObjectType type);
|
||||
//@}
|
||||
|
||||
protected:
|
||||
bool EventFrame(const Event &event);
|
||||
bool EventObject(const Event &event);
|
||||
|
@ -508,6 +548,10 @@ protected:
|
|||
|
||||
std::string m_gamerName;
|
||||
|
||||
int m_build; // constructible buildings
|
||||
int m_researchDone; // research done
|
||||
long m_researchEnable; // research available
|
||||
|
||||
int m_freeBuild; // constructible buildings
|
||||
int m_freeResearch; // researches possible
|
||||
|
||||
|
@ -534,4 +578,3 @@ protected:
|
|||
int m_autosaveSlots;
|
||||
float m_autosaveLast;
|
||||
};
|
||||
|
||||
|
|
|
@ -470,7 +470,7 @@ bool CScriptFunctions::rStopMusic(CBotVar* var, CBotVar* result, int& exception,
|
|||
|
||||
bool CScriptFunctions::rGetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
result->SetValInt(g_build);
|
||||
result->SetValInt(CRobotMain::GetInstancePointer()->GetEnableBuild());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -478,7 +478,7 @@ bool CScriptFunctions::rGetBuild(CBotVar* var, CBotVar* result, int& exception,
|
|||
|
||||
bool CScriptFunctions::rGetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
result->SetValInt(g_researchEnable);
|
||||
result->SetValInt(CRobotMain::GetInstancePointer()->GetEnableResearch());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -486,7 +486,7 @@ bool CScriptFunctions::rGetResearchEnable(CBotVar* var, CBotVar* result, int& ex
|
|||
|
||||
bool CScriptFunctions::rGetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
result->SetValInt(g_researchDone);
|
||||
result->SetValInt(CRobotMain::GetInstancePointer()->GetDoneResearch());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ bool CScriptFunctions::rGetResearchDone(CBotVar* var, CBotVar* result, int& exce
|
|||
|
||||
bool CScriptFunctions::rSetBuild(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
g_build = var->GetValInt();
|
||||
CRobotMain::GetInstancePointer()->SetEnableBuild(var->GetValInt());
|
||||
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return true;
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ bool CScriptFunctions::rSetBuild(CBotVar* var, CBotVar* result, int& exception,
|
|||
|
||||
bool CScriptFunctions::rSetResearchEnable(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
g_researchEnable = var->GetValInt();
|
||||
CRobotMain::GetInstancePointer()->SetEnableResearch(var->GetValInt());
|
||||
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return true;
|
||||
}
|
||||
|
@ -512,7 +512,7 @@ bool CScriptFunctions::rSetResearchEnable(CBotVar* var, CBotVar* result, int& ex
|
|||
|
||||
bool CScriptFunctions::rSetResearchDone(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
g_researchDone = var->GetValInt();
|
||||
CRobotMain::GetInstancePointer()->SetDoneResearch(var->GetValInt());
|
||||
CApplication::GetInstancePointer()->GetEventQueue()->AddEvent(Event(EVENT_UPDINTERFACE));
|
||||
return true;
|
||||
}
|
||||
|
@ -749,112 +749,9 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
return false;
|
||||
}
|
||||
|
||||
bool bEnable = false;
|
||||
err = CRobotMain::GetInstancePointer()->CanFactoryError(type);
|
||||
|
||||
if ( type == OBJECT_MOBILEwa )
|
||||
{
|
||||
bEnable = true;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEta )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_TANK;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEfa )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_FLY;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEia )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_iPAW;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_MOBILEws )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_SNIFFER;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEts )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEfs )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEis )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SNIFFER) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( type == OBJECT_MOBILEwc )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_CANON;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEtc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEfc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEic )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_CANON) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( type == OBJECT_MOBILEwi )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_iGUN;
|
||||
}
|
||||
if ( type == OBJECT_MOBILEti )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEfi )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_FLY) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILEii )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_iGUN) &&
|
||||
(g_researchDone&RESEARCH_iPAW) );
|
||||
}
|
||||
|
||||
if ( type == OBJECT_MOBILErt )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_THUMP) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILErc )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_PHAZER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILErr )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_RECYCLER) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
if ( type == OBJECT_MOBILErs )
|
||||
{
|
||||
bEnable = ( (g_researchDone&RESEARCH_SHIELD) &&
|
||||
(g_researchDone&RESEARCH_TANK) );
|
||||
}
|
||||
|
||||
if ( type == OBJECT_MOBILEsa )
|
||||
{
|
||||
bEnable = g_researchDone&RESEARCH_SUBM;
|
||||
}
|
||||
|
||||
if ( bEnable )
|
||||
if ( err == ERR_OK )
|
||||
{
|
||||
if ( automat != nullptr )
|
||||
{
|
||||
|
@ -864,8 +761,6 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
|
|||
else
|
||||
err = ERR_GENERIC;
|
||||
}
|
||||
else
|
||||
err = ERR_BUILD_DISABLED;
|
||||
}
|
||||
else
|
||||
err = ERR_WRONG_OBJ;
|
||||
|
@ -914,11 +809,11 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu
|
|||
CAuto* automat = center->GetAuto();
|
||||
|
||||
if ( thisType == OBJECT_RESEARCH ||
|
||||
thisType == OBJECT_LABO )
|
||||
thisType == OBJECT_LABO )
|
||||
{
|
||||
bool ok = false;
|
||||
if ( type == RESEARCH_iPAW ||
|
||||
type == RESEARCH_iGUN )
|
||||
type == RESEARCH_iGUN )
|
||||
{
|
||||
if ( thisType != OBJECT_LABO )
|
||||
err = ERR_WRONG_OBJ;
|
||||
|
@ -934,7 +829,7 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu
|
|||
}
|
||||
if ( ok )
|
||||
{
|
||||
bool bEnable = ( g_researchEnable & type );
|
||||
bool bEnable = CRobotMain::GetInstancePointer()->IsResearchEnabled(type);
|
||||
if ( bEnable )
|
||||
{
|
||||
if ( automat != nullptr )
|
||||
|
@ -1499,41 +1394,7 @@ bool CScriptFunctions::rCanBuild(CBotVar* var, CBotVar* result, int& exception,
|
|||
ObjectType category = static_cast<ObjectType>(var->GetValInt()); //get category parameter
|
||||
exception = 0;
|
||||
|
||||
bool can = false;
|
||||
|
||||
if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) ||
|
||||
(category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) ||
|
||||
(category == OBJECT_STATION && (g_build & BUILD_STATION)) ||
|
||||
(category == OBJECT_CONVERT && (g_build & BUILD_CONVERT)) ||
|
||||
(category == OBJECT_REPAIR && (g_build & BUILD_REPAIR)) ||
|
||||
(category == OBJECT_TOWER && (g_build & BUILD_TOWER)) ||
|
||||
(category == OBJECT_RESEARCH && (g_build & BUILD_RESEARCH)) ||
|
||||
(category == OBJECT_RADAR && (g_build & BUILD_RADAR)) ||
|
||||
(category == OBJECT_ENERGY && (g_build & BUILD_ENERGY)) ||
|
||||
(category == OBJECT_LABO && (g_build & BUILD_LABO)) ||
|
||||
(category == OBJECT_NUCLEAR && (g_build & BUILD_NUCLEAR)) ||
|
||||
(category == OBJECT_INFO && (g_build & BUILD_INFO)) ||
|
||||
(category == OBJECT_PARA && (g_build & BUILD_PARA)) ||
|
||||
(category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER)))
|
||||
{
|
||||
|
||||
// if we want to build not researched one
|
||||
if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
|
||||
(category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
|
||||
)
|
||||
{
|
||||
can = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
can = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
result->SetValInt(can);
|
||||
|
||||
|
||||
result->SetValInt(CRobotMain::GetInstancePointer()->CanBuild(category));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1546,53 +1407,25 @@ bool CScriptFunctions::rBuild(CBotVar* var, CBotVar* result, int& exception, voi
|
|||
CObject* pThis = static_cast<CObject *>(user);
|
||||
ObjectType oType;
|
||||
ObjectType category;
|
||||
Error err = ERR_BUILD_DISABLED;
|
||||
Error err;
|
||||
|
||||
exception = 0;
|
||||
|
||||
oType = pThis->GetType();
|
||||
|
||||
if ( oType != OBJECT_MOBILEfa && // allowed only for grabber bots && humans
|
||||
oType != OBJECT_MOBILEta &&
|
||||
oType != OBJECT_MOBILEwa &&
|
||||
oType != OBJECT_MOBILEia &&
|
||||
oType != OBJECT_HUMAN &&
|
||||
oType != OBJECT_TECH)
|
||||
oType != OBJECT_MOBILEta &&
|
||||
oType != OBJECT_MOBILEwa &&
|
||||
oType != OBJECT_MOBILEia &&
|
||||
oType != OBJECT_HUMAN &&
|
||||
oType != OBJECT_TECH )
|
||||
{
|
||||
err = ERR_MANIP_VEH; // Wrong object
|
||||
}
|
||||
else
|
||||
{
|
||||
category = static_cast<ObjectType>(var->GetValInt()); // get category parameter
|
||||
if ( (category == OBJECT_DERRICK && (g_build & BUILD_DERRICK)) ||
|
||||
(category == OBJECT_FACTORY && (g_build & BUILD_FACTORY)) ||
|
||||
(category == OBJECT_STATION && (g_build & BUILD_STATION)) ||
|
||||
(category == OBJECT_CONVERT && (g_build & BUILD_CONVERT)) ||
|
||||
(category == OBJECT_REPAIR && (g_build & BUILD_REPAIR)) ||
|
||||
(category == OBJECT_TOWER && (g_build & BUILD_TOWER)) ||
|
||||
(category == OBJECT_RESEARCH && (g_build & BUILD_RESEARCH)) ||
|
||||
(category == OBJECT_RADAR && (g_build & BUILD_RADAR)) ||
|
||||
(category == OBJECT_ENERGY && (g_build & BUILD_ENERGY)) ||
|
||||
(category == OBJECT_LABO && (g_build & BUILD_LABO)) ||
|
||||
(category == OBJECT_NUCLEAR && (g_build & BUILD_NUCLEAR)) ||
|
||||
(category == OBJECT_INFO && (g_build & BUILD_INFO)) ||
|
||||
(category == OBJECT_PARA && (g_build & BUILD_PARA)) ||
|
||||
(category == OBJECT_DESTROYER && (g_build & BUILD_DESTROYER)))
|
||||
{
|
||||
|
||||
// if we want to build not researched one
|
||||
if ( (category == OBJECT_TOWER && !(g_researchDone & RESEARCH_TOWER)) ||
|
||||
(category == OBJECT_NUCLEAR && !(g_researchDone & RESEARCH_ATOMIC))
|
||||
)
|
||||
{
|
||||
err = ERR_BUILD_RESEARCH;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = ERR_OK;
|
||||
}
|
||||
|
||||
}
|
||||
err = CRobotMain::GetInstancePointer()->CanBuildError(category);
|
||||
|
||||
if (pThis->GetIgnoreBuildCheck())
|
||||
err = ERR_OK;
|
||||
|
@ -3617,7 +3450,7 @@ bool CScriptFunctions::rfread(CBotVar* pThis, CBotVar* pVar, CBotVar* pResult, i
|
|||
Exception = CBotErrNotOpen;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
char chaine[2000];
|
||||
int i;
|
||||
for (i = 0; i < 2000; i++) chaine[i] = 0;
|
||||
|
|
Loading…
Reference in New Issue