2014-10-14 13:11:37 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2021-09-11 13:52:34 +00:00
|
|
|
* Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-08-22 14:40:02 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
2014-10-14 13:11:37 +00:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2015-08-15 12:02:07 +00:00
|
|
|
#include "common/global.h"
|
|
|
|
|
2012-09-11 21:11:34 +00:00
|
|
|
#include "graphics/engine/particle.h"
|
2013-02-16 21:37:43 +00:00
|
|
|
|
2015-06-20 18:02:40 +00:00
|
|
|
#include "object/object_manager.h"
|
2015-08-02 11:09:48 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
#include "object/subclass/exchange_post.h"
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-15 16:50:51 +00:00
|
|
|
#include <string.h>
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
2015-08-15 18:29:59 +00:00
|
|
|
CTaskInfo::CTaskInfo(COldObject* object) : CForegroundTask(object)
|
2015-06-27 21:22:55 +00:00
|
|
|
, m_progress(0.0f)
|
|
|
|
, m_speed(0.0f)
|
|
|
|
, m_time(0.0f)
|
|
|
|
, m_error(false)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
CTaskInfo::~CTaskInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
bool CTaskInfo::EventProcess(const Event &event)
|
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
if (m_engine->GetPause()) return true;
|
|
|
|
if (event.type != EVENT_FRAME) return true;
|
|
|
|
if (m_error) return false;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
m_progress += event.rTime*m_speed; // other advance
|
|
|
|
m_time += event.rTime;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Assigns the goal was achieved.
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
Error CTaskInfo::Start(const char *name, float value, float power, bool send)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
m_error = true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
CExchangePost* exchangePost = FindExchangePost(power);
|
|
|
|
if (exchangePost == nullptr)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return ERR_INFO_NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
int op = 1; // transmission impossible
|
|
|
|
if (send) // send?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
bool infoValueSet = exchangePost->SetInfo(name, value);
|
|
|
|
if (infoValueSet)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
op = 2; // start of reception (for terminal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // receive?
|
|
|
|
{
|
2015-08-17 09:44:05 +00:00
|
|
|
if (exchangePost->HasInfo(name))
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
op = 0; // beginning of transmission (for terminal)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
exchangePost->GetAuto()->Start(op);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
Math::Vector pos, goal;
|
|
|
|
if (op == 0) // transmission?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2015-07-12 09:01:16 +00:00
|
|
|
pos = exchangePost->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
pos.y += 9.5f;
|
2015-07-12 09:01:16 +00:00
|
|
|
goal = m_object->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
goal.y += 4.0f;
|
2021-12-24 17:39:45 +00:00
|
|
|
m_particle->CreateRay(pos, goal, Gfx::PARTIRAY3, { 2.0f, 2.0f }, 1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2015-06-27 21:22:55 +00:00
|
|
|
if (op == 2) // reception?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2015-07-12 09:01:16 +00:00
|
|
|
goal = exchangePost->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
goal.y += 9.5f;
|
2015-07-12 09:01:16 +00:00
|
|
|
pos = m_object->GetPosition();
|
2012-06-26 20:23:05 +00:00
|
|
|
pos.y += 4.0f;
|
2021-12-24 17:39:45 +00:00
|
|
|
m_particle->CreateRay(pos, goal, Gfx::PARTIRAY3, { 2.0f, 2.0f }, 1.0f);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_progress = 0.0f;
|
2015-06-27 21:22:55 +00:00
|
|
|
m_speed = 1.0f;
|
2012-06-26 20:23:05 +00:00
|
|
|
m_time = 0.0f;
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
m_error = false; // ok
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Indicates whether the action is finished.
|
|
|
|
|
|
|
|
Error CTaskInfo::IsEnded()
|
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
if (m_engine->GetPause()) return ERR_CONTINUE;
|
|
|
|
if (m_error) return ERR_STOP;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
if (m_progress < 1.0f) return ERR_CONTINUE;
|
2012-06-26 20:23:05 +00:00
|
|
|
m_progress = 0.0f;
|
|
|
|
|
|
|
|
Abort();
|
|
|
|
return ERR_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suddenly ends the current action.
|
|
|
|
|
|
|
|
bool CTaskInfo::Abort()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Seeks the nearest information terminal.
|
|
|
|
|
2015-06-27 21:22:55 +00:00
|
|
|
CExchangePost* CTaskInfo::FindExchangePost(float power)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2015-06-27 21:22:55 +00:00
|
|
|
return dynamic_cast<CExchangePost*>(
|
|
|
|
CObjectManager::GetInstancePointer()->FindNearest(m_object, OBJECT_INFO, power/g_unit));
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|