2014-10-14 13:11:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
|
|
|
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
|
|
|
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
|
*/
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "object/task/taskinfo.h"
|
|
|
|
|
|
2012-09-11 21:11:34 +00:00
|
|
|
|
#include "graphics/engine/particle.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
|
2014-12-21 16:06:55 +00:00
|
|
|
|
#include "object/objman.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
#include "object/auto/autoinfo.h"
|
|
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
|
#include <string.h>
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
|
2013-02-16 21:37:43 +00:00
|
|
|
|
CTaskInfo::CTaskInfo(CObject* object) : CTask(object)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
|
|
CTaskInfo::~CTaskInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
|
|
bool CTaskInfo::EventProcess(const Event &event)
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
if ( m_engine->GetPause() ) return true;
|
|
|
|
|
if ( event.type != EVENT_FRAME ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( m_bError ) return false;
|
|
|
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed; // other advance
|
|
|
|
|
m_time += event.rTime;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Assigns the goal was achieved.
|
|
|
|
|
|
2012-09-11 21:11:34 +00:00
|
|
|
|
Error CTaskInfo::Start(const char *name, float value, float power, bool bSend)
|
2012-06-26 20:23:05 +00:00
|
|
|
|
{
|
|
|
|
|
CObject* pInfo;
|
|
|
|
|
CAutoInfo* pAuto;
|
|
|
|
|
Math::Vector pos, goal;
|
|
|
|
|
Info info;
|
|
|
|
|
int i, total, op;
|
|
|
|
|
|
|
|
|
|
m_bError = true;
|
|
|
|
|
m_object->SetInfoReturn(NAN);
|
|
|
|
|
|
|
|
|
|
pInfo = SearchInfo(power); // seeks terminal
|
|
|
|
|
if ( pInfo == 0 )
|
|
|
|
|
{
|
|
|
|
|
return ERR_INFO_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 21:11:34 +00:00
|
|
|
|
pAuto = static_cast<CAutoInfo*>(pInfo->GetAuto());
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( pAuto == 0 )
|
|
|
|
|
{
|
|
|
|
|
return ERR_INFO_NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op = 1; // transmission impossible
|
|
|
|
|
if ( bSend ) // send?
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
total = pInfo->GetInfoTotal();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
for ( i=0 ; i<total ; i++ )
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
info = pInfo->GetInfo(i);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( strcmp(info.name, name) == 0 )
|
|
|
|
|
{
|
|
|
|
|
info.value = value;
|
|
|
|
|
pInfo->SetInfo(i, info);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( i == total )
|
|
|
|
|
{
|
|
|
|
|
if ( total < OBJECTMAXINFO )
|
|
|
|
|
{
|
|
|
|
|
strcpy(info.name, name);
|
|
|
|
|
info.value = value;
|
|
|
|
|
pInfo->SetInfo(total, info);
|
|
|
|
|
op = 2; // start of reception (for terminal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
op = 2; // start of reception (for terminal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // receive?
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
total = pInfo->GetInfoTotal();
|
2012-06-26 20:23:05 +00:00
|
|
|
|
for ( i=0 ; i<total ; i++ )
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
info = pInfo->GetInfo(i);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( strcmp(info.name, name) == 0 )
|
|
|
|
|
{
|
|
|
|
|
m_object->SetInfoReturn(info.value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( i < total )
|
|
|
|
|
{
|
|
|
|
|
op = 0; // beginning of transmission (for terminal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pAuto->Start(op);
|
|
|
|
|
|
|
|
|
|
if ( op == 0 ) // transmission?
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
pos = pInfo->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.y += 9.5f;
|
2012-09-11 21:11:34 +00:00
|
|
|
|
goal = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
goal.y += 4.0f;
|
2012-09-11 21:11:34 +00:00
|
|
|
|
m_particle->CreateRay(pos, goal, Gfx::PARTIRAY3, Math::Point(2.0f, 2.0f), 1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
if ( op == 2 ) // reception?
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
goal = pInfo->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
goal.y += 9.5f;
|
2012-09-11 21:11:34 +00:00
|
|
|
|
pos = m_object->GetPosition(0);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
pos.y += 4.0f;
|
2012-09-11 21:11:34 +00:00
|
|
|
|
m_particle->CreateRay(pos, goal, Gfx::PARTIRAY3, Math::Point(2.0f, 2.0f), 1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
m_speed = 1.0f/1.0f;
|
|
|
|
|
m_time = 0.0f;
|
|
|
|
|
|
|
|
|
|
m_bError = false; // ok
|
|
|
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Indicates whether the action is finished.
|
|
|
|
|
|
|
|
|
|
Error CTaskInfo::IsEnded()
|
|
|
|
|
{
|
2012-09-11 21:11:34 +00:00
|
|
|
|
if ( m_engine->GetPause() ) return ERR_CONTINUE;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
if ( m_bError ) return ERR_STOP;
|
|
|
|
|
|
|
|
|
|
if ( m_progress < 1.0f ) return ERR_CONTINUE;
|
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
|
|
|
|
|
Abort();
|
|
|
|
|
return ERR_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Suddenly ends the current action.
|
|
|
|
|
|
|
|
|
|
bool CTaskInfo::Abort()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Seeks the nearest information terminal.
|
|
|
|
|
|
|
|
|
|
CObject* CTaskInfo::SearchInfo(float power)
|
|
|
|
|
{
|
2014-12-21 16:06:55 +00:00
|
|
|
|
return CObjectManager::GetInstancePointer()->FindNearest(m_object, OBJECT_INFO, power/g_unit);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|