Forgotten fix in dev-graphics

dev-ui
Piotr Dziwinski 2012-09-19 22:53:06 +02:00
commit 7479f486b6
230 changed files with 15041 additions and 16000 deletions

View File

@ -422,7 +422,7 @@ public:
}
bool ConvertToStore(const SI_CHAR * a_pszString) {
size_t uLen = SizeToStore(a_pszString);
if (uLen == (size_t)(-1)) {
if (uLen == static_cast<size_t>(-1)) {
return false;
}
while (uLen > m_scratch.size()) {
@ -1360,7 +1360,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadFile(
}
fseek(a_fpFile, 0, SEEK_SET);
size_t uRead = fread(pData, sizeof(char), lSize, a_fpFile);
if (uRead != (size_t) lSize) {
if (uRead != static_cast<size_t>(lSize)) {
delete[] pData;
return SI_FILE;
}
@ -1394,7 +1394,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
// determine the length of the converted data
size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen);
if (uLen == (size_t)(-1)) {
if (uLen == static_cast<size_t>(-1)) {
return SI_FAIL;
}
@ -1753,7 +1753,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadMultiLineText(
// move this line down to the location that it should be if necessary
if (pDataLine < pCurrLine) {
size_t nLen = (size_t) (a_pData - pCurrLine);
size_t nLen = static_cast<size_t> (a_pData - pCurrLine);
memmove(pDataLine, pCurrLine, nLen * sizeof(SI_CHAR));
pDataLine[nLen] = '\0';
}
@ -1816,10 +1816,10 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::CopyString(
{
size_t uLen = 0;
if (sizeof(SI_CHAR) == sizeof(char)) {
uLen = strlen((const char *)a_pString);
uLen = strlen(static_cast<const char *>(a_pString));
}
else if (sizeof(SI_CHAR) == sizeof(wchar_t)) {
uLen = wcslen((const wchar_t *)a_pString);
uLen = wcslen(reinterpret_cast<const wchar_t *>(a_pString));
}
else {
for ( ; a_pString[uLen]; ++uLen) /*loop*/ ;
@ -2225,7 +2225,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetSectionSize(
// if multi-key isn't permitted then the section size is
// the number of keys that we have.
if (!m_bAllowMultiKey || section.empty()) {
return (int) section.size();
return static_cast<int> (section.size());
}
// otherwise we need to count them
@ -2626,7 +2626,7 @@ struct SI_GenericCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
long cmp;
for ( ;*pLeft && *pRight; ++pLeft, ++pRight) {
cmp = (long) *pLeft - (long) *pRight;
cmp = static_cast<long> (*pLeft) - static_cast<long> (*pRight);
if (cmp != 0) {
return cmp < 0;
}
@ -2649,7 +2649,7 @@ struct SI_GenericNoCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
long cmp;
for ( ;*pLeft && *pRight; ++pLeft, ++pRight) {
cmp = (long) locase(*pLeft) - (long) locase(*pRight);
cmp = static_cast<long> (locase(*pLeft)) - static_cast<long> (locase(*pRight));
if (cmp != 0) {
return cmp < 0;
}
@ -2741,7 +2741,7 @@ public:
const SI_CHAR * a_pInputData)
{
// ASCII/MBCS/UTF-8 needs no conversion
return strlen((const char *)a_pInputData) + 1;
return strlen(static_cast<const char *>(a_pInputData)) + 1;
}
/** Convert the input string to the storage format of this data.
@ -2763,7 +2763,7 @@ public:
size_t a_uOutputDataSize)
{
// calc input string length (SI_CHAR type and size independent)
size_t uInputLen = strlen((const char *)a_pInputData) + 1;
size_t uInputLen = strlen(static_cast<const char *>(a_pInputData)) + 1;
if (uInputLen > a_uOutputDataSize) {
return false;
}
@ -3195,12 +3195,12 @@ template<class SI_CHAR>
struct SI_NoCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
if (sizeof(SI_CHAR) == sizeof(char)) {
return _mbsicmp((const unsigned char *)pLeft,
(const unsigned char *)pRight) < 0;
return _mbsicmp(reinterpret_cast<const unsigned char *>(pLeft),
reinterpret_cast<const unsigned char *>(pRight)) < 0;
}
if (sizeof(SI_CHAR) == sizeof(wchar_t)) {
return _wcsicmp((const wchar_t *)pLeft,
(const wchar_t *)pRight) < 0;
return _wcsicmp(reinterpret_cast<const wchar_t *>(pLeft),
reinterpret_cast<const wchar_t *>(pRight)) < 0;
}
return SI_GenericNoCase<SI_CHAR>()(pLeft, pRight);
}
@ -3251,9 +3251,9 @@ public:
int retval = MultiByteToWideChar(
m_uCodePage, 0,
a_pInputData, (int) a_uInputDataLen,
a_pInputData, static_cast<int> (a_uInputDataLen),
0, 0);
return (size_t)(retval > 0 ? retval : -1);
return static_cast<size_t>(retval > 0 ? retval : -1);
}
/** Convert the input string from the storage format to SI_CHAR.
@ -3277,8 +3277,8 @@ public:
{
int nSize = MultiByteToWideChar(
m_uCodePage, 0,
a_pInputData, (int) a_uInputDataLen,
(wchar_t *) a_pOutputData, (int) a_uOutputDataSize);
a_pInputData, static_cast<int> (a_uInputDataLen),
static_cast<wchar_t *> (a_pOutputData), static_cast<int> (a_uOutputDataSize));
return (nSize > 0);
}
@ -3297,9 +3297,9 @@ public:
{
int retval = WideCharToMultiByte(
m_uCodePage, 0,
(const wchar_t *) a_pInputData, -1,
static_cast<const wchar_t *> (a_pInputData), -1,
0, 0, 0, 0);
return (size_t) (retval > 0 ? retval : -1);
return static_cast<size_t> (retval > 0 ? retval : -1);
}
/** Convert the input string to the storage format of this data.
@ -3322,8 +3322,8 @@ public:
{
int retval = WideCharToMultiByte(
m_uCodePage, 0,
(const wchar_t *) a_pInputData, -1,
a_pOutputData, (int) a_uOutputDataSize, 0, 0);
static_cast<const wchar_t *> (a_pInputData), -1,
a_pOutputData, static_cast<int> (a_uOutputDataSize), 0, 0);
return retval > 0;
}
};

View File

@ -597,18 +597,6 @@ static void DestructElements(CBotString* pOldData, int nCount)
}
}
static void CopyElements(CBotString* pDest, CBotString* pSrc, int nCount)
{
while (nCount--)
{
*pDest = *pSrc;
++pDest;
++pSrc;
}
}
// set the array size
void CBotStringArray::SetSize(int nNewSize)
@ -618,15 +606,14 @@ void CBotStringArray::SetSize(int nNewSize)
// shrink to nothing
DestructElements(m_pData, m_nSize);
// delete[] static_cast<unsigned char *>(m_pData);
delete[] (unsigned char *)m_pData;
delete[] reinterpret_cast<unsigned char *>(m_pData);
m_pData = NULL;
m_nSize = m_nMaxSize = 0;
}
else if (m_pData == NULL)
{
// create one with exact size
m_pData = (CBotString*) new unsigned char[nNewSize * sizeof(CBotString)];
m_pData = reinterpret_cast<CBotString*> (new unsigned char[nNewSize * sizeof(CBotString)]);
ConstructElements(m_pData, nNewSize);
@ -663,7 +650,7 @@ void CBotStringArray::SetSize(int nNewSize)
else
nNewMax = nNewSize; // no slush
CBotString* pNewData = (CBotString*) new unsigned char[nNewMax * sizeof(CBotString)];
CBotString* pNewData = reinterpret_cast<CBotString*> (new unsigned char[nNewMax * sizeof(CBotString)]);
// copy new data from old
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString));
@ -673,7 +660,7 @@ void CBotStringArray::SetSize(int nNewSize)
// Get rid of old stuff (note: no destructors called)
delete[] (unsigned char *)m_pData;
delete[] reinterpret_cast<unsigned char *>(m_pData);
m_pData = pNewData;
m_nSize = nNewSize;
m_nMaxSize = nNewMax;

View File

@ -6,6 +6,7 @@ add_subdirectory(tools)
# Tests
add_subdirectory(graphics/engine/test)
add_subdirectory(math/test)
# Configure options
@ -17,6 +18,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(PLATFORM_WINDOWS 1)
set(PLATFORM_LINUX 0)
set(PLATFORM_OTHER 0)
set(PLATFORM_LIBS "-lintl")
# On Windows, GLEW is required
if (${USE_GLEW} MATCHES "auto")
set(USE_GLEW 1)
@ -64,12 +66,11 @@ app/main.cpp
app/system.cpp
common/event.cpp
common/image.cpp
common/logger.cpp
common/iman.cpp
# common/metafile.cpp
# common/misc.cpp
# common/modfile.cpp
# common/profile.cpp
common/logger.cpp
common/metafile.cpp
common/misc.cpp
common/profile.cpp
common/restext.cpp
common/restext_strings.c
common/stringutils.cpp
@ -87,97 +88,96 @@ graphics/engine/terrain.cpp
graphics/engine/text.cpp
graphics/engine/water.cpp
graphics/opengl/gldevice.cpp
# object/auto/auto.cpp
# object/auto/autobase.cpp
# object/auto/autoconvert.cpp
# object/auto/autoderrick.cpp
# object/auto/autodestroyer.cpp
# object/auto/autoegg.cpp
# object/auto/autoenergy.cpp
# object/auto/autofactory.cpp
# object/auto/autoflag.cpp
# object/auto/autohuston.cpp
# object/auto/autoinfo.cpp
# object/auto/autojostle.cpp
# object/auto/autokid.cpp
# object/auto/autolabo.cpp
# object/auto/automush.cpp
# object/auto/autonest.cpp
# object/auto/autonuclear.cpp
# object/auto/autopara.cpp
# object/auto/autoportico.cpp
# object/auto/autoradar.cpp
# object/auto/autorepair.cpp
# object/auto/autoresearch.cpp
# object/auto/autoroot.cpp
# object/auto/autosafe.cpp
# object/auto/autostation.cpp
# object/auto/autotower.cpp
# object/brain.cpp
# object/mainmovie.cpp
# object/motion/motion.cpp
# object/motion/motionant.cpp
# object/motion/motionbee.cpp
# object/motion/motionhuman.cpp
# object/motion/motionmother.cpp
# object/motion/motionspider.cpp
# object/motion/motiontoto.cpp
# object/motion/motionvehicle.cpp
# object/motion/motionworm.cpp
# object/object.cpp
# object/robotmain.cpp
# object/task/task.cpp
# object/task/taskadvance.cpp
# object/task/taskbuild.cpp
# object/task/taskfire.cpp
# object/task/taskfireant.cpp
# object/task/taskflag.cpp
# object/task/taskgoto.cpp
# object/task/taskgungoal.cpp
# object/task/taskinfo.cpp
# object/task/taskmanager.cpp
# object/task/taskmanip.cpp
# object/task/taskpen.cpp
# object/task/taskrecover.cpp
# object/task/taskreset.cpp
# object/task/tasksearch.cpp
# object/task/taskshield.cpp
# object/task/taskspiderexplo.cpp
# object/task/tasktake.cpp
# object/task/taskterraform.cpp
# object/task/taskturn.cpp
# object/task/taskwait.cpp
# physics/physics.cpp
# script/cbottoken.cpp
# script/cmdtoken.cpp
# script/script.cpp
# sound/sound.cpp
# ui/button.cpp
# ui/check.cpp
# ui/color.cpp
# ui/compass.cpp
# ui/control.cpp
# ui/displayinfo.cpp
# ui/displaytext.cpp
# ui/edit.cpp
# ui/editvalue.cpp
# ui/gauge.cpp
# ui/group.cpp
# ui/image.cpp
# ui/interface.cpp
# ui/key.cpp
# ui/label.cpp
# ui/list.cpp
# ui/maindialog.cpp
# ui/mainmap.cpp
# ui/mainshort.cpp
# ui/map.cpp
# ui/scroll.cpp
# ui/shortcut.cpp
# ui/slider.cpp
# ui/studio.cpp
# ui/target.cpp
# ui/window.cpp
object/auto/auto.cpp
object/auto/autobase.cpp
object/auto/autoconvert.cpp
object/auto/autoderrick.cpp
object/auto/autodestroyer.cpp
object/auto/autoegg.cpp
object/auto/autoenergy.cpp
object/auto/autofactory.cpp
object/auto/autoflag.cpp
object/auto/autohuston.cpp
object/auto/autoinfo.cpp
object/auto/autojostle.cpp
object/auto/autokid.cpp
object/auto/autolabo.cpp
object/auto/automush.cpp
object/auto/autonest.cpp
object/auto/autonuclear.cpp
object/auto/autopara.cpp
object/auto/autoportico.cpp
object/auto/autoradar.cpp
object/auto/autorepair.cpp
object/auto/autoresearch.cpp
object/auto/autoroot.cpp
object/auto/autosafe.cpp
object/auto/autostation.cpp
object/auto/autotower.cpp
object/brain.cpp
object/mainmovie.cpp
object/motion/motion.cpp
object/motion/motionant.cpp
object/motion/motionbee.cpp
object/motion/motionhuman.cpp
object/motion/motionmother.cpp
object/motion/motionspider.cpp
object/motion/motiontoto.cpp
object/motion/motionvehicle.cpp
object/motion/motionworm.cpp
object/object.cpp
object/robotmain.cpp
object/task/task.cpp
object/task/taskadvance.cpp
object/task/taskbuild.cpp
object/task/taskfire.cpp
object/task/taskfireant.cpp
object/task/taskflag.cpp
object/task/taskgoto.cpp
object/task/taskgungoal.cpp
object/task/taskinfo.cpp
object/task/taskmanager.cpp
object/task/taskmanip.cpp
object/task/taskpen.cpp
object/task/taskrecover.cpp
object/task/taskreset.cpp
object/task/tasksearch.cpp
object/task/taskshield.cpp
object/task/taskspiderexplo.cpp
object/task/tasktake.cpp
object/task/taskterraform.cpp
object/task/taskturn.cpp
object/task/taskwait.cpp
physics/physics.cpp
script/cbottoken.cpp
script/cmdtoken.cpp
script/script.cpp
ui/button.cpp
ui/check.cpp
ui/color.cpp
ui/compass.cpp
ui/control.cpp
ui/displayinfo.cpp
ui/displaytext.cpp
ui/edit.cpp
ui/editvalue.cpp
ui/gauge.cpp
ui/group.cpp
ui/image.cpp
ui/interface.cpp
ui/key.cpp
ui/label.cpp
ui/list.cpp
ui/maindialog.cpp
ui/mainmap.cpp
ui/mainshort.cpp
ui/map.cpp
ui/scroll.cpp
ui/shortcut.cpp
ui/slider.cpp
ui/studio.cpp
ui/target.cpp
ui/window.cpp
)
set(LIBS
@ -191,12 +191,16 @@ ${PLATFORM_LIBS}
CBot
)
include_directories(. ${CMAKE_CURRENT_BINARY_DIR}
include_directories(
.
..
${CMAKE_CURRENT_BINARY_DIR}
${SDL_INCLUDE_DIR}
${SDL_IMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
${OPTIONAL_INCLUDE_DIRS}
..
)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/CBot)

View File

@ -23,16 +23,24 @@
#include "common/logger.h"
#include "common/iman.h"
#include "common/image.h"
#include "common/key.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <libintl.h>
template<> CApplication* CSingleton<CApplication>::mInstance = NULL;
template<> CApplication* CSingleton<CApplication>::mInstance = nullptr;
//! Static buffer for putenv locale
static char S_LANGUAGE[50] = { 0 };
//! Interval of timer called to update joystick state
@ -62,8 +70,8 @@ struct ApplicationPrivate
ApplicationPrivate()
{
memset(&currentEvent, 0, sizeof(SDL_Event));
surface = NULL;
joystick = NULL;
surface = nullptr;
joystick = nullptr;
joystickTimer = 0;
}
};
@ -76,14 +84,10 @@ CApplication::CApplication()
m_iMan = new CInstanceManager();
m_eventQueue = new CEventQueue(m_iMan);
m_engine = NULL;
m_device = NULL;
m_robotMain = NULL;
m_sound = NULL;
m_keyState = 0;
m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f);
m_axeJoy = Math::Vector(0.0f, 0.0f, 0.0f);
m_engine = nullptr;
m_device = nullptr;
m_robotMain = nullptr;
m_sound = nullptr;
m_exitCode = 0;
m_active = false;
@ -91,29 +95,57 @@ CApplication::CApplication()
m_windowTitle = "COLOBOT";
m_simulationSuspended = false;
m_simulationSpeed = 1.0f;
m_realAbsTimeBase = 0LL;
m_realAbsTime = 0LL;
m_realRelTime = 0LL;
m_absTimeBase = 0LL;
m_exactAbsTime = 0LL;
m_exactRelTime = 0LL;
m_absTime = 0.0f;
m_relTime = 0.0f;
m_baseTimeStamp = CreateTimeStamp();
m_curTimeStamp = CreateTimeStamp();
m_lastTimeStamp = CreateTimeStamp();
m_joystickEnabled = false;
m_kmodState = 0;
m_mouseButtonsState = 0;
m_trackedKeys = 0;
m_dataPath = "./data";
ResetKey();
m_language = LANG_ENGLISH;
}
CApplication::~CApplication()
{
delete m_private;
m_private = NULL;
m_private = nullptr;
delete m_eventQueue;
m_eventQueue = NULL;
m_eventQueue = nullptr;
delete m_iMan;
m_iMan = NULL;
m_iMan = nullptr;
DestroyTimeStamp(m_baseTimeStamp);
DestroyTimeStamp(m_curTimeStamp);
DestroyTimeStamp(m_lastTimeStamp);
}
bool CApplication::ParseArguments(int argc, char *argv[])
ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
{
bool waitDataDir = false;
bool waitLogLevel = false;
bool waitLanguage = false;
for (int i = 1; i < argc; ++i)
{
@ -123,6 +155,7 @@ bool CApplication::ParseArguments(int argc, char *argv[])
{
waitDataDir = false;
m_dataPath = arg;
GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str());
continue;
}
@ -142,7 +175,23 @@ bool CApplication::ParseArguments(int argc, char *argv[])
else if (arg == "none")
GetLogger()->SetLogLevel(LOG_NONE);
else
return false;
return PARSE_ARGS_FAIL;
continue;
}
if (waitLanguage)
{
waitLanguage = false;
if (arg == "en")
m_language = LANG_ENGLISH;
else if (arg == "de")
m_language = LANG_GERMAN;
else if (arg == "fr")
m_language = LANG_FRENCH;
else if (arg == "pl")
m_language = LANG_POLISH;
else
return PARSE_ARGS_FAIL;
continue;
}
@ -158,34 +207,95 @@ bool CApplication::ParseArguments(int argc, char *argv[])
{
waitDataDir = true;
}
else if (arg == "-language")
{
waitLanguage = true;
}
else if (arg == "-help")
{
GetLogger()->Message("\n");
GetLogger()->Message("COLOBOT GOLD pre-alpha\n");
GetLogger()->Message("\n");
GetLogger()->Message("List of available options:\n");
GetLogger()->Message(" -help this help\n");
GetLogger()->Message(" -datadir path set custom data directory path\n");
GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n");
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl)\n");
return PARSE_ARGS_HELP;
}
else
{
m_exitCode = 1;
return false;
return PARSE_ARGS_FAIL;
}
}
// Args not given?
if (waitDataDir || waitLogLevel)
return false;
if (waitDataDir || waitLogLevel || waitLanguage)
return PARSE_ARGS_FAIL;
return true;
return PARSE_ARGS_OK;
}
bool CApplication::Create()
{
GetLogger()->Info("Creating CApplication\n");
// TODO: verify that data directory exists
// I know, a primitive way to check for dir, but works
std::string readmePath = m_dataPath + "/README.txt";
std::ifstream testReadme;
testReadme.open(readmePath.c_str(), std::ios_base::in);
if (!testReadme.good())
{
GetLogger()->Error("Could not open test file in data dir: '%s'\n", readmePath.c_str());
m_errorMessage = std::string("Could not read from data directory:\n") +
std::string("'") + m_dataPath + std::string("'\n") +
std::string("Please check your installation, or supply a valid data directory by -datadir option.");
m_exitCode = 1;
return false;
}
/* Gettext initialization */
std::string locale = "C";
switch (m_language)
{
case LANG_ENGLISH:
locale = "en_US.utf8";
break;
case LANG_GERMAN:
locale = "de_DE.utf8";
break;
case LANG_FRENCH:
locale = "fr_FR.utf8";
break;
case LANG_POLISH:
locale = "pl_PL.utf8";
break;
}
std::string langStr = "LANGUAGE=";
langStr += locale;
strcpy(S_LANGUAGE, langStr.c_str());
putenv(S_LANGUAGE);
setlocale(LC_ALL, locale.c_str());
std::string trPath = m_dataPath + std::string("/i18n");
bindtextdomain("colobot", trPath.c_str());
bind_textdomain_codeset("colobot", "UTF-8");
textdomain("colobot");
GetLogger()->Debug("Testing gettext translation: '%s'\n", gettext("Colobot rules!"));
// Temporarily -- only in windowed mode
m_deviceConfig.fullScreen = false;
/* // Create the sound instance.
m_sound = new CSound(m_iMan);
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan); */
// Create the sound instance.
m_sound = new CSoundInterface();
std::string standardInfoMessage =
@ -218,7 +328,7 @@ bool CApplication::Create()
if (! CreateVideoSurface())
return false; // dialog is in function
if (m_private->surface == NULL)
if (m_private->surface == nullptr)
{
m_errorMessage = std::string("SDL error while setting video mode:\n") +
std::string(SDL_GetError());
@ -261,6 +371,11 @@ bool CApplication::Create()
return false;
}
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan, this);
m_robotMain->ChangePhase(PHASE_WELCOME1);
GetLogger()->Info("CApplication created successfully\n");
return true;
@ -269,7 +384,7 @@ bool CApplication::Create()
bool CApplication::CreateVideoSurface()
{
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL)
if (videoInfo == nullptr)
{
m_errorMessage = std::string("SDL error while getting video info:\n ") +
std::string(SDL_GetError());
@ -321,44 +436,46 @@ bool CApplication::CreateVideoSurface()
void CApplication::Destroy()
{
/*if (m_robotMain != NULL)
m_joystickEnabled = false;
if (m_robotMain != nullptr)
{
delete m_robotMain;
m_robotMain = NULL;
m_robotMain = nullptr;
}
if (m_sound != NULL)
if (m_sound != nullptr)
{
delete m_sound;
m_sound = NULL;
}*/
m_sound = nullptr;
}
if (m_engine != NULL)
if (m_engine != nullptr)
{
m_engine->Destroy();
delete m_engine;
m_engine = NULL;
m_engine = nullptr;
}
if (m_device != NULL)
if (m_device != nullptr)
{
m_device->Destroy();
delete m_device;
m_device = NULL;
m_device = nullptr;
}
if (m_private->joystick != NULL)
if (m_private->joystick != nullptr)
{
SDL_JoystickClose(m_private->joystick);
m_private->joystick = NULL;
m_private->joystick = nullptr;
}
if (m_private->surface != NULL)
if (m_private->surface != nullptr)
{
SDL_FreeSurface(m_private->surface);
m_private->surface = NULL;
m_private->surface = nullptr;
}
IMG_Quit();
@ -383,7 +500,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
return false;
}
if (m_private->surface == NULL)
if (m_private->surface == nullptr)
{
if (! restore)
{
@ -426,7 +543,7 @@ bool CApplication::OpenJoystick()
return false;
m_private->joystick = SDL_JoystickOpen(m_joystick.index);
if (m_private->joystick == NULL)
if (m_private->joystick == nullptr)
return false;
m_joystick.axisCount = SDL_JoystickNumAxes(m_private->joystick);
@ -437,7 +554,7 @@ bool CApplication::OpenJoystick()
m_joyButtonState = std::vector<bool>(m_joystick.buttonCount, false);
// Create a timer for polling joystick state
m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, NULL);
m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, nullptr);
return true;
}
@ -447,7 +564,7 @@ void CApplication::CloseJoystick()
// Timer will remove itself automatically
SDL_JoystickClose(m_private->joystick);
m_private->joystick = NULL;
m_private->joystick = nullptr;
}
bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
@ -455,7 +572,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
if ( (newJoystick.index < 0) || (newJoystick.index >= SDL_NumJoysticks()) )
return false;
if (m_private->joystick != NULL)
if (m_private->joystick != nullptr)
CloseJoystick();
return OpenJoystick();
@ -464,7 +581,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
Uint32 JoystickTimerCallback(Uint32 interval, void *)
{
CApplication *app = CApplication::GetInstancePointer();
if ((app == NULL) || (! app->GetJoystickEnabled()))
if ((app == nullptr) || (! app->GetJoystickEnabled()))
return 0; // don't run the timer again
app->UpdateJoystick();
@ -540,6 +657,10 @@ int CApplication::Run()
{
m_active = true;
GetCurrentTimeStamp(m_baseTimeStamp);
GetCurrentTimeStamp(m_lastTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
while (true)
{
// To be sure no old event remains
@ -577,12 +698,24 @@ int CApplication::Run()
{
bool passOn = ProcessEvent(event);
if (m_engine != NULL && passOn)
if (m_engine != nullptr && passOn)
passOn = m_engine->ProcessEvent(event);
if (passOn)
m_eventQueue->AddEvent(event);
}
Event virtualEvent = CreateVirtualEvent(event);
if (virtualEvent.type != EVENT_NULL)
{
bool passOn = ProcessEvent(virtualEvent);
if (m_engine != nullptr && passOn)
passOn = m_engine->ProcessEvent(virtualEvent);
if (passOn)
m_eventQueue->AddEvent(virtualEvent);
}
}
}
@ -602,12 +735,12 @@ int CApplication::Run()
{
passOn = ProcessEvent(event);
if (passOn && m_engine != NULL)
if (passOn && m_engine != nullptr)
passOn = m_engine->ProcessEvent(event);
}
/*if (passOn && m_robotMain != NULL)
m_robotMain->ProcessEvent(event); */
if (passOn && m_robotMain != nullptr)
m_robotMain->EventProcess(event);
}
/* Update mouse position explicitly right before rendering
@ -616,6 +749,9 @@ int CApplication::Run()
// Update game and render a frame during idle time (no messages are waiting)
Render();
// Update simulation state
StepSimulation();
}
}
@ -664,6 +800,7 @@ Event CApplication::ParseEvent()
else
event.type = EVENT_KEY_UP;
event.key.virt = false;
event.key.key = m_private->currentEvent.key.keysym.sym;
event.key.mod = m_private->currentEvent.key.keysym.mod;
event.key.state = TranslatePressState(m_private->currentEvent.key.state);
@ -672,15 +809,32 @@ Event CApplication::ParseEvent()
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
{
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
event.type = EVENT_MOUSE_BUTTON_DOWN;
if ((m_private->currentEvent.button.button == SDL_BUTTON_WHEELUP) ||
(m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN))
{
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) // ignore the following up event
{
event.type = EVENT_MOUSE_WHEEL;
if (m_private->currentEvent.button.button == SDL_BUTTON_WHEELDOWN)
event.mouseWheel.dir = WHEEL_DOWN;
else
event.mouseWheel.dir = WHEEL_UP;
event.mouseWheel.pos = m_engine->WindowToInterfaceCoords(
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
}
}
else
event.type = EVENT_MOUSE_BUTTON_UP;
{
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
event.type = EVENT_MOUSE_BUTTON_DOWN;
else
event.type = EVENT_MOUSE_BUTTON_UP;
event.mouseButton.button = m_private->currentEvent.button.button;
event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state);
event.mouseButton.pos = m_engine->WindowToInterfaceCoords(
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
event.mouseButton.button = m_private->currentEvent.button.button;
event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state);
event.mouseButton.pos = m_engine->WindowToInterfaceCoords(
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
}
}
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
{
@ -725,18 +879,93 @@ Event CApplication::ParseEvent()
return event;
}
/** Processes incoming events. It is the first function called after an event is captures.
Function returns \c true if the event is to be passed on to other processing functions
or \c false if not. */
bool CApplication::ProcessEvent(const Event &event)
/**
* Processes incoming events. It is the first function called after an event is captured.
* Event is modified, updating its tracked keys state and mouse position to current values.
* Function returns \c true if the event is to be passed on to other processing functions
* or \c false if not. */
bool CApplication::ProcessEvent(Event &event)
{
CLogger *l = GetLogger();
event.trackedKeys = m_trackedKeys;
if (GetSystemMouseVisibile())
event.mousePos = m_systemMousePos;
else
event.mousePos = m_engine->GetMousePos();
if (event.type == EVENT_ACTIVE)
{
m_active = event.active.gain;
if (m_debugMode)
l->Info("Focus change: active = %s\n", m_active ? "true" : "false");
l->Info("Focus change: active = %s\n", event.active.gain ? "true" : "false");
/*if (m_active != event.active.gain)
{
m_active = event.active.gain;
if (m_active)
ResumeSimulation();
else
SuspendSimulation();
}*/
}
else if (event.type == EVENT_KEY_DOWN)
{
m_kmodState = event.key.mod;
if ((m_kmodState & KEY_MOD(SHIFT)) != 0)
m_trackedKeys |= TRKEY_SHIFT;
else if ((m_kmodState & KEY_MOD(CTRL)) != 0)
m_trackedKeys |= TRKEY_CONTROL;
else if (event.key.key == KEY(KP8))
m_trackedKeys |= TRKEY_NUM_UP;
else if (event.key.key == KEY(KP2))
m_trackedKeys |= TRKEY_NUM_DOWN;
else if (event.key.key == KEY(KP4))
m_trackedKeys |= TRKEY_NUM_LEFT;
else if (event.key.key == KEY(KP6))
m_trackedKeys |= TRKEY_NUM_RIGHT;
else if (event.key.key == KEY(KP_PLUS))
m_trackedKeys |= TRKEY_NUM_PLUS;
else if (event.key.key == KEY(KP_MINUS))
m_trackedKeys |= TRKEY_NUM_MINUS;
else if (event.key.key == KEY(PAGEUP))
m_trackedKeys |= TRKEY_PAGE_UP;
else if (event.key.key == KEY(PAGEDOWN))
m_trackedKeys |= TRKEY_PAGE_DOWN;
}
else if (event.type == EVENT_KEY_UP)
{
m_kmodState = event.key.mod;
if ((m_kmodState & KEY_MOD(SHIFT)) != 0)
m_trackedKeys &= ~TRKEY_SHIFT;
else if ((m_kmodState & KEY_MOD(CTRL)) != 0)
m_trackedKeys &= ~TRKEY_CONTROL;
else if (event.key.key == KEY(KP8))
m_trackedKeys &= ~TRKEY_NUM_UP;
else if (event.key.key == KEY(KP2))
m_trackedKeys &= ~TRKEY_NUM_DOWN;
else if (event.key.key == KEY(KP4))
m_trackedKeys &= ~TRKEY_NUM_LEFT;
else if (event.key.key == KEY(KP6))
m_trackedKeys &= ~TRKEY_NUM_RIGHT;
else if (event.key.key == KEY(KP_PLUS))
m_trackedKeys &= ~TRKEY_NUM_PLUS;
else if (event.key.key == KEY(KP_MINUS))
m_trackedKeys &= ~TRKEY_NUM_MINUS;
else if (event.key.key == KEY(PAGEUP))
m_trackedKeys &= ~TRKEY_PAGE_UP;
else if (event.key.key == KEY(PAGEDOWN))
m_trackedKeys &= ~TRKEY_PAGE_DOWN;
}
else if (event.type == EVENT_MOUSE_BUTTON_DOWN)
{
m_mouseButtonsState |= 1 << event.mouseButton.button;
}
else if (event.type == EVENT_MOUSE_BUTTON_UP)
{
m_mouseButtonsState &= ~(1 << event.mouseButton.button);
}
// Print the events in debug mode to test the code
@ -747,6 +976,7 @@ bool CApplication::ProcessEvent(const Event &event)
case EVENT_KEY_DOWN:
case EVENT_KEY_UP:
l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP");
l->Info(" virt = %s\n", (event.key.virt) ? "true" : "false");
l->Info(" key = %4x\n", event.key.key);
l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
l->Info(" mod = %4x\n", event.key.mod);
@ -764,6 +994,11 @@ bool CApplication::ProcessEvent(const Event &event)
l->Info(" state = %s\n", (event.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
l->Info(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y);
break;
case EVENT_MOUSE_WHEEL:
l->Info("EVENT_MOUSE_WHEEL:\n");
l->Info(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP");
l->Info(" pos = (%f, %f)\n", event.mouseWheel.pos.x, event.mouseWheel.pos.y);
break;
case EVENT_JOY_AXIS:
l->Info("EVENT_JOY_AXIS:\n");
l->Info(" axis = %d\n", event.joyAxis.axis);
@ -789,6 +1024,48 @@ bool CApplication::ProcessEvent(const Event &event)
return true;
}
Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
{
Event virtualEvent;
virtualEvent.systemEvent = true;
if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP))
{
virtualEvent.type = sourceEvent.type;
virtualEvent.key = sourceEvent.key;
virtualEvent.key.virt = true;
if (sourceEvent.key.key == KEY(LCTRL) || sourceEvent.key.key == KEY(RCTRL))
virtualEvent.key.key = VIRTUAL_KMOD(CTRL);
else if (sourceEvent.key.key == KEY(LSHIFT) || sourceEvent.key.key == KEY(RSHIFT))
virtualEvent.key.key = VIRTUAL_KMOD(SHIFT);
else if (sourceEvent.key.key == KEY(LALT) || sourceEvent.key.key == KEY(RALT))
virtualEvent.key.key = VIRTUAL_KMOD(ALT);
else if (sourceEvent.key.key == KEY(LMETA) || sourceEvent.key.key == KEY(RMETA))
virtualEvent.key.key = VIRTUAL_KMOD(META);
else
virtualEvent.type = EVENT_NULL;
}
else if ((sourceEvent.type == EVENT_JOY_BUTTON_DOWN) || (sourceEvent.type == EVENT_JOY_BUTTON_UP))
{
if (sourceEvent.type == EVENT_JOY_BUTTON_DOWN)
virtualEvent.type = EVENT_KEY_DOWN;
else
virtualEvent.type = EVENT_KEY_UP;
virtualEvent.key.virt = true;
virtualEvent.key.key = VIRTUAL_JOY(sourceEvent.joyButton.button);
virtualEvent.key.mod = 0;
virtualEvent.key.unicode = 0;
}
else
{
virtualEvent.type = EVENT_NULL;
}
return virtualEvent;
}
/** Renders the frame and swaps buffers as necessary */
void CApplication::Render()
{
@ -798,9 +1075,101 @@ void CApplication::Render()
SDL_GL_SwapBuffers();
}
void CApplication::StepSimulation(float rTime)
void CApplication::SuspendSimulation()
{
// TODO
m_simulationSuspended = true;
GetLogger()->Info("Suspend simulation\n");
}
void CApplication::ResumeSimulation()
{
m_simulationSuspended = false;
GetCurrentTimeStamp(m_baseTimeStamp);
CopyTimeStamp(m_curTimeStamp, m_baseTimeStamp);
m_realAbsTimeBase = m_realAbsTime;
m_absTimeBase = m_exactAbsTime;
GetLogger()->Info("Resume simulation\n");
}
bool CApplication::GetSimulationSuspended()
{
return m_simulationSuspended;
}
void CApplication::SetSimulationSpeed(float speed)
{
m_simulationSpeed = speed;
GetCurrentTimeStamp(m_baseTimeStamp);
m_realAbsTimeBase = m_realAbsTime;
m_absTimeBase = m_exactAbsTime;
GetLogger()->Info("Simulation speed = %.2f\n", speed);
}
void CApplication::StepSimulation()
{
if (m_simulationSuspended)
return;
CopyTimeStamp(m_lastTimeStamp, m_curTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
long long absDiff = TimeStampExactDiff(m_baseTimeStamp, m_curTimeStamp);
m_realAbsTime = m_realAbsTimeBase + absDiff;
// m_baseTimeStamp is updated on simulation speed change, so this is OK
m_exactAbsTime = m_absTimeBase + m_simulationSpeed * absDiff;
m_absTime = (m_absTimeBase + m_simulationSpeed * absDiff) / 1e9f;
m_realRelTime = TimeStampExactDiff(m_lastTimeStamp, m_curTimeStamp);
m_exactRelTime = m_simulationSpeed * m_realRelTime;
m_relTime = (m_simulationSpeed * m_realRelTime) / 1e9f;
m_engine->FrameUpdate();
m_sound->FrameMove(m_relTime);
Event frameEvent(EVENT_FRAME);
frameEvent.rTime = m_relTime;
m_eventQueue->AddEvent(frameEvent);
}
float CApplication::GetSimulationSpeed()
{
return m_simulationSpeed;
}
float CApplication::GetAbsTime()
{
return m_absTime;
}
long long CApplication::GetExactAbsTime()
{
return m_exactAbsTime;
}
long long CApplication::GetRealAbsTime()
{
return m_realAbsTime;
}
float CApplication::GetRelTime()
{
return m_relTime;
}
long long CApplication::GetExactRelTime()
{
return m_exactRelTime;
}
long long CApplication::GetRealRelTime()
{
return m_realRelTime;
}
Gfx::GLDeviceConfig CApplication::GetVideoConfig()
@ -814,7 +1183,7 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint
resolutions.clear();
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL)
if (videoInfo == nullptr)
return VIDEO_QUERY_ERROR;
Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
@ -861,25 +1230,31 @@ bool CApplication::GetDebugMode()
return m_debugMode;
}
void CApplication::FlushPressKey()
int CApplication::GetKmods()
{
// TODO
return m_kmodState;
}
void CApplication::ResetKey()
bool CApplication::GetKmodState(int kmod)
{
// TODO
return (m_kmodState & kmod) != 0;
}
void CApplication::SetKey(int keyRank, int option, int key)
bool CApplication::GetTrackedKeyState(TrackedKey key)
{
// TODO
return (m_trackedKeys & key) != 0;
}
int CApplication::GetKey(int keyRank, int option)
bool CApplication::GetMouseButtonState(int index)
{
// TODO
return 0;
return (m_mouseButtonsState & (1<<index)) != 0;
}
void CApplication::ResetKeyStates()
{
m_trackedKeys = 0;
m_kmodState = 0;
m_robotMain->ResetKeyStates();
}
void CApplication::SetGrabInput(bool grab)
@ -964,3 +1339,13 @@ std::string CApplication::GetDataFilePath(const std::string& dirName, const std:
{
return m_dataPath + "/" + dirName + "/" + fileName;
}
Language CApplication::GetLanguage()
{
return m_language;
}
void CApplication::SetLanguage(Language language)
{
m_language = language;
}

View File

@ -22,8 +22,7 @@
#pragma once
#include "common/misc.h"
#include "common/global.h"
#include "common/singleton.h"
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
@ -36,11 +35,12 @@
class CInstanceManager;
class CEvent;
class CRobotMain;
class CSound;
class CSoundInterface;
/**
\struct JoystickDevice
\brief Information about a joystick device */
* \struct JoystickDevice
* \brief Information about a joystick device
*/
struct JoystickDevice
{
//! Device index (-1 = invalid device)
@ -57,8 +57,9 @@ struct JoystickDevice
};
/**
\enum VideoQueryResult
\brief Result of querying for available video resolutions */
* \enum VideoQueryResult
* \brief Result of querying for available video resolutions
*/
enum VideoQueryResult
{
VIDEO_QUERY_ERROR,
@ -68,6 +69,35 @@ enum VideoQueryResult
};
/**
* \enum TrackedKeys
* \brief Keys (or kmods) whose state (pressed/released) is tracked by CApplication
*/
enum TrackedKey
{
TRKEY_SHIFT = (1<<0),
TRKEY_CONTROL = (1<<1),
TRKEY_NUM_UP = (1<<2),
TRKEY_NUM_DOWN = (1<<3),
TRKEY_NUM_LEFT = (1<<4),
TRKEY_NUM_RIGHT = (1<<5),
TRKEY_NUM_PLUS = (1<<6),
TRKEY_NUM_MINUS = (1<<7),
TRKEY_PAGE_UP = (1<<8),
TRKEY_PAGE_DOWN = (1<<9)
};
/**
* \enum ParseArgsStatus
* \brief State of parsing commandline arguments
*/
enum ParseArgsStatus
{
PARSE_ARGS_OK = 1, //! < all ok
PARSE_ARGS_FAIL = 2, //! < invalid syntax
PARSE_ARGS_HELP = 3 //! < -help requested
};
struct ApplicationPrivate;
/**
@ -82,7 +112,7 @@ struct ApplicationPrivate;
* \section Creation Creation of other main objects
*
* The class creates the only instance of CInstanceManager, CEventQueue, CEngine,
* CRobotMain and CSound classes.
* CRobotMain and CSoundInterface classes.
*
* \section Window Window management
*
@ -123,7 +153,7 @@ public:
public:
//! Parses commandline arguments
bool ParseArguments(int argc, char *argv[]);
ParseArgsStatus ParseArguments(int argc, char *argv[]);
//! Initializes the application
bool Create();
//! Main event loop
@ -147,8 +177,37 @@ public:
//! Change the video mode to given mode
bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig);
//! Suspends animation (time will not be updated)
void SuspendSimulation();
//! Resumes animation
void ResumeSimulation();
//! Returns whether simulation is suspended
bool GetSimulationSuspended();
//! Updates the simulation state
void StepSimulation(float rTime);
void StepSimulation();
//@{
//! Management of simulation speed
void SetSimulationSpeed(float speed);
float GetSimulationSpeed();
//@}
//! Returns the absolute time counter [seconds]
float GetAbsTime();
//! Returns the exact absolute time counter [nanoseconds]
long long GetExactAbsTime();
//! Returns the exact absolute time counter disregarding speed setting [nanoseconds]
long long GetRealAbsTime();
//! Returns the relative time since last update [seconds]
float GetRelTime();
//! Returns the exact realative time since last update [nanoseconds]
long long GetExactRelTime();
//! Returns the exact relative time since last update disregarding speed setting [nanoseconds]
long long GetRealRelTime();
//! Returns a list of available joystick devices
std::vector<JoystickDevice> GetJoystickList();
@ -159,10 +218,11 @@ public:
//! Change the current joystick device
bool ChangeJoystick(const JoystickDevice &newJoystick);
//! Enables/disables joystick
//! Management of joystick enable state
//@{
void SetJoystickEnabled(bool enable);
//! Returns whether joystick is enabled
bool GetJoystickEnabled();
//@}
//! Polls the state of joystick axes and buttons
void UpdateJoystick();
@ -170,42 +230,63 @@ public:
//! Updates the mouse position explicitly
void UpdateMouse();
void FlushPressKey();
void ResetKey();
void SetKey(int keyRank, int option, int key);
int GetKey(int keyRank, int option);
//! Returns the current key modifiers
int GetKmods();
//! Returns whether the given kmod is active
bool GetKmodState(int kmod);
//! Sets the grab mode for input (keyboard & mouse)
//! Returns whether the tracked key is pressed
bool GetTrackedKeyState(TrackedKey key);
//! Returns whether the mouse button is pressed
bool GetMouseButtonState(int index);
//! Resets tracked key states and modifiers
void ResetKeyStates();
//! Management of the grab mode for input (keyboard & mouse)
//@{
void SetGrabInput(bool grab);
//! Returns the grab mode
bool GetGrabInput();
//@}
//! Sets the visiblity of system mouse cursor
//! Management of the visiblity of system mouse cursor
//@{
void SetSystemMouseVisible(bool visible);
//! Returns the visiblity of system mouse cursor
bool GetSystemMouseVisibile();
//@}
//! Sets the position of system mouse cursor (in interface coords)
//! Management of the position of system mouse cursor (in interface coords)
//@{
void SetSystemMousePos(Math::Point pos);
//! Returns the position of system mouse cursor (in interface coords)
Math::Point GetSystemMousePos();
//@}
//! Enables/disables debug mode (prints more info in logger)
//! Management of debug mode (prints more info in logger)
//@{
void SetDebugMode(bool mode);
//! Returns whether debug mode is enabled
bool GetDebugMode();
//@}
//! Returns the full path to a file in data directory
std::string GetDataFilePath(const std::string &dirName, const std::string &fileName);
//! Management of language
//@{
Language GetLanguage();
void SetLanguage(Language language);
//@}
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
//! Processes the captured SDL event to Event struct
Event ParseEvent();
//! If applicable, creates a virtual event to match the changed state as of new event
Event CreateVirtualEvent(const Event& sourceEvent);
//! Handles some incoming events
bool ProcessEvent(const Event &event);
bool ProcessEvent(Event &event);
//! Renders the image in window
void Render();
@ -226,7 +307,7 @@ protected:
//! Graphics device
Gfx::CDevice* m_device;
//! Sound subsystem
CSound* m_sound;
CSoundInterface* m_sound;
//! Main class of the proper game engine
CRobotMain* m_robotMain;
@ -248,13 +329,36 @@ protected:
//! Text set as window title
std::string m_windowTitle;
int m_keyState;
Math::Vector m_axeKey;
Math::Vector m_axeJoy;
Math::Point m_systemMousePos;
long m_mouseWheel;
//! Animation time stamps, etc.
//@{
SystemTimeStamp* m_baseTimeStamp;
SystemTimeStamp* m_lastTimeStamp;
SystemTimeStamp* m_curTimeStamp;
long m_key[50][2];
long long m_realAbsTimeBase;
long long m_realAbsTime;
long long m_realRelTime;
long long m_absTimeBase;
long long m_exactAbsTime;
long long m_exactRelTime;
float m_absTime;
float m_relTime;
float m_simulationSpeed;
bool m_simulationSuspended;
//@}
//! Current state of key modifiers (mask of SDLMod)
unsigned int m_kmodState;
//! Current state of some tracked keys (mask of TrackedKey)
unsigned int m_trackedKeys;
//! Current state of mouse buttons (mask of button indexes)
unsigned int m_mouseButtonsState;
//! Current system mouse position
Math::Point m_systemMousePos;
//! Info about current joystick device
JoystickDevice m_joystick;
@ -267,5 +371,8 @@ protected:
//! Path to directory with data files
std::string m_dataPath;
//! Application language
Language m_language;
};

View File

@ -78,11 +78,16 @@ int main(int argc, char *argv[])
CApplication app; // single instance of the application
if (! app.ParseArguments(argc, argv))
ParseArgsStatus status = app.ParseArguments(argc, argv);
if (status == PARSE_ARGS_FAIL)
{
SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
return app.GetExitCode();
}
else if (status == PARSE_ARGS_HELP)
{
return app.GetExitCode();
}
int code = 0;

View File

@ -48,18 +48,18 @@ struct SystemTimeStamp
// Convert a wide Unicode string to an UTF8 string
std::string UTF8_Encode_Windows(const std::wstring &wstr)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), NULL, 0, NULL, NULL);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], static_cast<int>(wstr.size()), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
// Convert an UTF8 string to a wide Unicode String
std::wstring UTF8_Decode_Windows(const std::string &str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
MultiByteToWideChar(CP_UTF8, 0, &str[0], static_cast<int>(str.size()), &wstrTo[0], size_needed);
return wstrTo;
}

View File

@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// TODO: move to global.h after restext rewrite
#pragma once
enum Error
@ -23,8 +26,6 @@ enum Error
ERR_CONTINUE = 2, // continues
ERR_STOP = 3, // stops
ERR_CMD = 4, // unknown command
ERR_INSTALL = 20, // incorrectly installed program
ERR_NOCD = 21, // CD not found
ERR_MANIP_VEH = 100, // inappropriate vehicle
ERR_MANIP_FLY = 101, // impossible in flight
ERR_MANIP_BUSY = 102, // taking: hands already occupied

View File

@ -19,6 +19,16 @@
#include "common/event.h"
#include "common/iman.h"
static EventType g_uniqueEventType = EVENT_USER;
EventType GetUniqueEventType()
{
int i = static_cast<int>(g_uniqueEventType+1);
g_uniqueEventType = static_cast<EventType>(i);
return g_uniqueEventType;
}
CEventQueue::CEventQueue(CInstanceManager* iMan)

View File

@ -14,23 +14,26 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// event.h
/**
* \file common/event.h
* \brief Event types, structs and event queue
*/
#pragma once
#include <common/key.h>
#include <common/event_ids.h>
#include <math/point.h>
#include <string.h>
#include "common/key.h"
#include "common/event_ids.h"
#include "math/point.h"
#include "math/vector.h"
class CInstanceManager;
/** \enum PressState
\brief State of key/mouse button */
/**
* \enum PressState
* \brief State of key/mouse button
*/
enum PressState
{
STATE_PRESSED,
@ -38,21 +41,22 @@ enum PressState
};
/** \struct KeyEventData
\brief Additional data for keyboard event */
/**
* \struct KeyEventData
* \brief Additional data for keyboard event
*/
struct KeyEventData
{
//! STATE_PRESSED or STATE_RELEASED */
PressState state;
//! Key symbol: KEY(...) macro value (from common/key.h)
//! If true, the key is a virtual code generated by key modifier press or joystick button press
bool virt;
//! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h)
unsigned int key;
//! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h)
unsigned int mod;
//! Unicode character
unsigned int unicode;
KeyEventData()
: state(STATE_PRESSED), key(0), mod(0), unicode(0) {}
};
/** \struct MouseMotionEventData
@ -60,16 +64,15 @@ struct KeyEventData
struct MouseMoveEventData
{
//! Current button state
unsigned char state;
PressState state;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
MouseMoveEventData()
: state(STATE_PRESSED) {}
};
/** \struct MouseButtonEventData
\brief Additional data mouse button event */
/**
* \struct MouseButtonEventData
* \brief Additional data mouse button event
*/
struct MouseButtonEventData
{
//! The mouse button index
@ -78,39 +81,58 @@ struct MouseButtonEventData
PressState state;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
MouseButtonEventData()
: button(0), state(STATE_PRESSED) {}
};
/** \struct JoyAxisEventData
\brief Additional data for joystick axis event */
/**
* \enum WheelDirection
* \brief Direction of mouse wheel movement
*/
enum WheelDirection
{
WHEEL_UP,
WHEEL_DOWN
};
/**
* \enum MouseWheelEventData
* \brief Additional data for mouse wheel event.
*/
struct MouseWheelEventData
{
//! Wheel direction
WheelDirection dir;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
};
/**
* \struct JoyAxisEventData
* \brief Additional data for joystick axis event
*/
struct JoyAxisEventData
{
//! The joystick axis index
unsigned char axis;
//! The axis value (range: -32768 to 32767)
int value;
JoyAxisEventData()
: axis(axis), value(value) {}
};
/** \struct JoyButtonEventData
\brief Additional data for joystick button event */
/**
* \struct JoyButtonEventData
* \brief Additional data for joystick button event
*/
struct JoyButtonEventData
{
//! The joystick button index
unsigned char button;
//! STATE_PRESSED or STATE_RELEASED
PressState state;
JoyButtonEventData()
: button(0), state(STATE_PRESSED) {}
};
/** \enum ActiveEventFlags
\brief Type of focus gained/lost */
/**
* \enum ActiveEventFlags
* \brief Type of focus gained/lost
*/
enum ActiveEventFlags
{
//! Application window focus
@ -122,30 +144,29 @@ enum ActiveEventFlags
};
/** \struct ActiveEventData
\brief Additional data for active event */
/**
* \struct ActiveEventData
* \brief Additional data for active event
*/
struct ActiveEventData
{
//! Flags (bitmask of enum values ActiveEventFlags)
unsigned char flags;
//! True if the focus was gained; false otherwise
bool gain;
ActiveEventData()
: flags(0), gain(false) {}
};
/**
\struct Event
\brief Event sent by system, interface or game
Event is described by its type (EventType) and the union
\a data contains additional data about the event.
Different members of the union are filled with different event types.
With some events, nothing is filled (it's zeroed out).
The union contains roughly the same information as SDL_Event struct
but packaged to independent structs and fields.
* \struct Event
* \brief Event sent by system, interface or game
*
* Event is described by its type (EventType) and the union
* \a data contains additional data about the event.
* Different members of the union are filled with different event types.
* With some events, nothing is filled (it's zeroed out).
* The union contains roughly the same information as SDL_Event struct
* but packaged to independent structs and fields.
**/
struct Event
{
@ -163,6 +184,8 @@ struct Event
MouseButtonEventData mouseButton;
//! Additional data for EVENT_MOUSE_MOVE
MouseMoveEventData mouseMove;
//! Additional data for EVENT_MOUSE_WHEEL
MouseWheelEventData mouseWheel;
//! Additional data for EVENT_JOY
JoyAxisEventData joyAxis;
//! Additional data for EVENT_JOY_AXIS
@ -171,70 +194,49 @@ struct Event
ActiveEventData active;
};
// TODO: refactor/rewrite
//! State of tracked keys (mask of TrackedKey enum values)
unsigned int trackedKeys;
//! Mouse position is provided also for other types of events besides mouse events
Math::Point mousePos;
//! Motion vector set by keyboard or joystick
Math::Vector motionInput;
// TODO: remove and replace references with trackedKeys
short keyState;
// TODO: remove and replace references with mousePos
Math::Point pos;
// TODO: remove
long param; // parameter
Math::Point pos; // mouse position (0 .. 1)
float axeX; // control the X axis (-1 .. 1)
float axeY; // control of the Y axis (-1 .. 1)
float axeZ; // control the Z axis (-1 .. 1)
short keyState; // state of the keyboard (KS_ *)
// TODO: remove in longer term (use CApplication's new time functions instead)
float rTime; // relative time
Event(EventType aType = EVENT_NULL)
{
type = aType;
systemEvent = false;
trackedKeys = 0;
param = 0;
axeX = axeY = axeZ = 0.0f;
keyState = 0;
rTime = 0.0f;
}
};
/**
\enum KeyRank
\brief Slots for key assignment of user controls
*/
// TODO: move to global.h ?
enum KeyRank
{
KEYRANK_LEFT = 0,
KEYRANK_RIGHT = 1,
KEYRANK_UP = 2,
KEYRANK_DOWN = 3,
KEYRANK_GUP = 4,
KEYRANK_GDOWN = 5,
KEYRANK_CAMERA = 6,
KEYRANK_DESEL = 7,
KEYRANK_ACTION = 8,
KEYRANK_NEAR = 9,
KEYRANK_AWAY = 10,
KEYRANK_NEXT = 11,
KEYRANK_HUMAN = 12,
KEYRANK_QUIT = 13,
KEYRANK_HELP = 14,
KEYRANK_PROG = 15,
KEYRANK_VISIT = 16,
KEYRANK_SPEED10 = 17,
KEYRANK_SPEED15 = 18,
KEYRANK_SPEED20 = 19,
KEYRANK_SPEED30 = 20,
KEYRANK_AIMUP = 21,
KEYRANK_AIMDOWN = 22,
KEYRANK_CBOT = 23,
};
//! Returns an unique event type (above the standard IDs)
EventType GetUniqueEventType();
/**
\class CEventQueue
\brief Global event queue
Provides an interface to a global FIFO queue with events (both system- and user-generated).
The queue has a fixed maximum size but it should not be a problem.
* \class CEventQueue
* \brief Global event queue
*
* Provides an interface to a global FIFO queue with events (both system- and user-generated).
* The queue has a fixed maximum size but it should not be a problem.
*/
class CEventQueue
{
@ -261,5 +263,3 @@ protected:
int m_tail;
int m_total;
};

View File

@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// TODO: move to event.h after restext rewrite
#pragma once
/**
@ -38,6 +41,8 @@ enum EventType
EVENT_MOUSE_BUTTON_DOWN = 3,
//! Event sent after releasing a mouse button
EVENT_MOUSE_BUTTON_UP = 4,
//! Event sent after moving mouse wheel up or down
EVENT_MOUSE_WHEEL = 5,
//! Event sent after moving the mouse
EVENT_MOUSE_MOVE = 7,
//! Event sent after pressing a key
@ -48,9 +53,6 @@ enum EventType
//! Event sent when application window loses/gains focus
EVENT_ACTIVE = 10,
//? EVENT_CHAR = 10,
//? EVENT_FOCUS = 11,
//! Event sent after moving joystick axes
EVENT_JOY_AXIS = 12,
//! Event sent after pressing a joystick button

View File

@ -14,53 +14,124 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// global.h
/**
* \file common/global.h
* \brief Some common, global definitions
*/
#pragma once
#include "error_ids.h"
/**
* \enum Language
* \brief Application language
*/
enum Language
{
LANG_ENGLISH = 0,
LANG_FRENCH = 1,
LANG_GERMAN = 2,
LANG_POLISH = 3
};
/**
* \enum BuildType
* \brief Construction actions (buildings, etc.) available to user
*
* TODO: refactor
*/
enum BuildType
{
BUILD_FACTORY = (1<<0), // factory
BUILD_DERRICK = (1<<1), // derrick
BUILD_CONVERT = (1<<2), // converter
BUILD_RADAR = (1<<3), // radar
BUILD_ENERGY = (1<<4), // factory of cells
BUILD_NUCLEAR = (1<<5), // nuclear power plant
BUILD_STATION = (1<<6), // base station
BUILD_REPAIR = (1<<7), // repair center
BUILD_TOWER = (1<<8), // defense tower
BUILD_RESEARCH = (1<<9), // research center
BUILD_LABO = (1<<10), // laboratory
BUILD_PARA = (1<<11), // lightning protection
BUILD_INFO = (1<<12), // information terminal
BUILD_GFLAT = (1<<16), // flat floor
BUILD_FLAG = (1<<17) // puts / removes colored flag
BUILD_FACTORY = (1<<0), //! < factory
BUILD_DERRICK = (1<<1), //! < derrick
BUILD_CONVERT = (1<<2), //! < converter
BUILD_RADAR = (1<<3), //! < radar
BUILD_ENERGY = (1<<4), //! < factory of cells
BUILD_NUCLEAR = (1<<5), //! < nuclear power plant
BUILD_STATION = (1<<6), //! < base station
BUILD_REPAIR = (1<<7), //! < repair center
BUILD_TOWER = (1<<8), //! < defense tower
BUILD_RESEARCH = (1<<9), //! < research center
BUILD_LABO = (1<<10), //! < laboratory
BUILD_PARA = (1<<11), //! < lightning protection
BUILD_INFO = (1<<12), //! < information terminal
BUILD_GFLAT = (1<<16), //! < flat floor
BUILD_FLAG = (1<<17) //! < puts / removes colored flag
};
// Do not change values was because of backups (bits = ...).
/**
* \enum ResearchType
* \brief Research actions available to user
*/
enum ResearchType
{
RESEARCH_TANK = (1<<0), // caterpillars
RESEARCH_FLY = (1<<1), // wings
RESEARCH_CANON = (1<<2), // cannon
RESEARCH_TOWER = (1<<3), // defense tower
RESEARCH_ATOMIC = (1<<4), // nuclear
RESEARCH_THUMP = (1<<5), // thumper
RESEARCH_SHIELD = (1<<6), // shield
RESEARCH_PHAZER = (1<<7), // phazer gun
RESEARCH_iPAW = (1<<8), // legs of insects
RESEARCH_iGUN = (1<<9), // cannon of insects
RESEARCH_RECYCLER = (1<<10), // recycler
RESEARCH_SUBM = (1<<11), // submarine
RESEARCH_SNIFFER = (1<<12) // sniffer
RESEARCH_TANK = (1<<0), //! < caterpillars
RESEARCH_FLY = (1<<1), //! < wings
RESEARCH_CANON = (1<<2), //! < cannon
RESEARCH_TOWER = (1<<3), //! < defense tower
RESEARCH_ATOMIC = (1<<4), //! < nuclear
RESEARCH_THUMP = (1<<5), //! < thumper
RESEARCH_SHIELD = (1<<6), //! < shield
RESEARCH_PHAZER = (1<<7), //! < phazer gun
RESEARCH_iPAW = (1<<8), //! < legs of insects
RESEARCH_iGUN = (1<<9), //! < cannon of insects
RESEARCH_RECYCLER = (1<<10), //! < recycler
RESEARCH_SUBM = (1<<11), //! < submarine
RESEARCH_SNIFFER = (1<<12) //! < sniffer
};
/**
* \enum InputSlot
* \brief Available slots for input bindings
*/
enum InputSlot
{
INPUT_SLOT_LEFT = 0,
INPUT_SLOT_RIGHT = 1,
INPUT_SLOT_UP = 2,
INPUT_SLOT_DOWN = 3,
INPUT_SLOT_GUP = 4,
INPUT_SLOT_GDOWN = 5,
INPUT_SLOT_CAMERA = 6,
INPUT_SLOT_DESEL = 7,
INPUT_SLOT_ACTION = 8,
INPUT_SLOT_NEAR = 9,
INPUT_SLOT_AWAY = 10,
INPUT_SLOT_NEXT = 11,
INPUT_SLOT_HUMAN = 12,
INPUT_SLOT_QUIT = 13,
INPUT_SLOT_HELP = 14,
INPUT_SLOT_PROG = 15,
INPUT_SLOT_VISIT = 16,
INPUT_SLOT_SPEED10 = 17,
INPUT_SLOT_SPEED15 = 18,
INPUT_SLOT_SPEED20 = 19,
INPUT_SLOT_SPEED30 = 20,
INPUT_SLOT_AIMUP = 21,
INPUT_SLOT_AIMDOWN = 22,
INPUT_SLOT_CBOT = 23,
INPUT_SLOT_MAX
};
/**
* \enum JoyAxisSlot
* \brief Slots for joystick axes inputs
*/
enum JoyAxisSlot
{
JOY_AXIS_SLOT_X,
JOY_AXIS_SLOT_Y,
JOY_AXIS_SLOT_Z,
JOY_AXIS_SLOT_MAX
};
// TODO: move to CRobotMain
extern long g_id; // unique identifier
extern long g_build; // constructible buildings
extern long g_researchDone; // research done
extern int g_build; // constructible buildings
extern int g_researchDone; // research done
extern long g_researchEnable; // research available
extern float g_unit; // conversion factor

View File

@ -21,6 +21,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <png.h>
@ -88,21 +90,21 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
/* Opening output file */
fp = fopen(filename, "wb");
if (fp == NULL)
if (fp == nullptr)
{
PNG_ERROR = std::string("Could not open file '") + std::string(filename) + std::string("' for saving");
return false;
}
/* Initializing png structures and callbacks */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNGUserError, NULL);
if (png_ptr == NULL)
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGUserError, nullptr);
if (png_ptr == nullptr)
return false;
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
if (info_ptr == nullptr)
{
png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(nullptr));
PNG_ERROR = "png_create_info_struct() error!";
return false;
}
@ -142,7 +144,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
CImage::CImage()
{
m_data = NULL;
m_data = nullptr;
}
CImage::~CImage()
@ -150,22 +152,22 @@ CImage::~CImage()
Free();
}
bool CImage::IsEmpty()
bool CImage::IsEmpty() const
{
return m_data == NULL;
return m_data == nullptr;
}
void CImage::Free()
{
if (m_data != NULL)
if (m_data != nullptr)
{
if (m_data->surface != NULL)
if (m_data->surface != nullptr)
{
SDL_FreeSurface(m_data->surface);
m_data->surface = NULL;
m_data->surface = nullptr;
}
delete m_data;
m_data = NULL;
m_data = nullptr;
}
}
@ -174,6 +176,118 @@ ImageData* CImage::GetData()
return m_data;
}
Math::IntPoint CImage::GetSize() const
{
if (m_data == nullptr)
return Math::IntPoint();
return Math::IntPoint(m_data->surface->w, m_data->surface->h);
}
/**
* Image must be valid and pixel coords in valid range.
*
* \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
* \returns color
*/
Gfx::Color CImage::GetPixel(Math::IntPoint pixel)
{
assert(m_data != nullptr);
assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
int bpp = m_data->surface->format->BytesPerPixel;
int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index];
Uint32 u = 0;
switch (bpp)
{
case 1:
u = *p;
break;
case 2:
u = *reinterpret_cast<Uint16*>(p);
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
u = (p[0] << 16) | (p[1] << 8) | p[2];
else
u = p[0] | (p[1] << 8) | (p[2] << 16);
break;
case 4:
u = *reinterpret_cast<Uint32*>(p);
break;
default:
assert(false);
}
Uint8 r = 0, g = 0, b = 0, a = 0;
SDL_GetRGBA(u, m_data->surface->format, &r, &g, &b, &a);
return Gfx::Color(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
}
/**
* Image must be valid and pixel coords in valid range.
*
* \param pixel pixel coords (range x: 0..width-1 y: 0..height-1)
* \param color color
*/
void CImage::SetPixel(Math::IntPoint pixel, Gfx::Color color)
{
assert(m_data != nullptr);
assert(pixel.x >= 0 || pixel.x <= m_data->surface->w);
assert(pixel.y >= 0 || pixel.y <= m_data->surface->h);
int bpp = m_data->surface->format->BytesPerPixel;
int index = pixel.y * m_data->surface->pitch + pixel.x * bpp;
Uint8* p = &static_cast<Uint8*>(m_data->surface->pixels)[index];
Uint8 r = static_cast<Uint8>(color.r * 255.0f);
Uint8 g = static_cast<Uint8>(color.g * 255.0f);
Uint8 b = static_cast<Uint8>(color.b * 255.0f);
Uint8 a = static_cast<Uint8>(color.a * 255.0f);
Uint32 u = SDL_MapRGBA(m_data->surface->format, r, g, b, a);
switch(bpp)
{
case 1:
*p = u;
break;
case 2:
*reinterpret_cast<Uint16*>(p) = u;
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (u >> 16) & 0xFF;
p[1] = (u >> 8) & 0xFF;
p[2] = u & 0xFF;
}
else
{
p[0] = u & 0xFF;
p[1] = (u >> 8) & 0xFF;
p[2] = (u >> 16) & 0xFF;
}
break;
case 4:
*reinterpret_cast<Uint32*>(p) = u;
break;
default:
assert(false);
}
}
std::string CImage::GetError()
{
return m_error;
@ -189,10 +303,10 @@ bool CImage::Load(const std::string& fileName)
m_error = "";
m_data->surface = IMG_Load(fileName.c_str());
if (m_data->surface == NULL)
if (m_data->surface == nullptr)
{
delete m_data;
m_data = NULL;
m_data = nullptr;
m_error = std::string(IMG_GetError());
return false;

View File

@ -14,10 +14,15 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// image.h
/**
* \file common/image.h
* \brief Class for loading and saving images
*/
#pragma once
#include "graphics/core/color.h"
#include "math/intpoint.h"
#include <stddef.h>
#include <string>
@ -61,12 +66,21 @@ public:
//! Frees the allocated image data
void Free();
//! Returns whether the image is empty (has NULL data)
bool IsEmpty();
//! Returns whether the image is empty (has null data)
bool IsEmpty() const;
//! Returns the image data; if empty - returns NULL
//! Returns the image data; if empty - returns nullptr
ImageData* GetData();
//! Returns the image size
Math::IntPoint GetSize() const;
//! Sets the color at given pixel
void SetPixel(Math::IntPoint pixel, Gfx::Color color);
//! Returns the color at given pixel
Gfx::Color GetPixel(Math::IntPoint pixel);
//! Loads an image from the specified file
bool Load(const std::string &fileName);

View File

@ -16,12 +16,10 @@
// iman.cpp
#include <stdio.h>
#include "common/struct.h"
#include "common/iman.h"
#include <cassert>
template<> CInstanceManager* CSingleton<CInstanceManager>::mInstance = nullptr;
@ -39,139 +37,91 @@ CInstanceManager* CInstanceManager::GetInstancePointer()
return mInstance;
}
// Object's constructor.
CInstanceManager::CInstanceManager()
{
int i;
for ( i=0 ; i<CLASS_MAX ; i++ )
for (int i = 0; i < CLASS_MAX; i++)
{
m_table[i].totalPossible = 0;
m_table[i].totalUsed = 0;
m_table[i].classPointer = 0;
m_table[i].maxCount = 0;
m_table[i].usedCount = 0;
m_table[i].instances = nullptr;
}
}
// Object's destructor.
CInstanceManager::~CInstanceManager()
{
int i;
for ( i=0 ; i<CLASS_MAX ; i++ )
{
if ( m_table[i].classPointer != 0 )
{
free(m_table[i].classPointer);
}
}
Flush();
}
// Empty the list of all classes.
void CInstanceManager::Flush()
{
int i;
for ( i=0 ; i<CLASS_MAX ; i++ )
for (int i = 0; i < CLASS_MAX; i++)
{
if ( m_table[i].classPointer != 0 )
{
free(m_table[i].classPointer);
}
m_table[i].classPointer = 0;
if (m_table[i].instances != nullptr)
delete[] m_table[i].instances;
m_table[i].instances = nullptr;
}
}
// Empty all instances of a given class.
void CInstanceManager::Flush(ClassType classType)
void CInstanceManager::Flush(ManagedClassType classType)
{
if ( classType < 0 || classType >= CLASS_MAX ) return;
if ( m_table[classType].classPointer == 0 ) return;
if (classType < 0 || classType >= CLASS_MAX) return;
if (m_table[classType].instances == nullptr) return;
free(m_table[classType].classPointer);
m_table[classType].classPointer = 0;
delete[] m_table[classType].instances;
m_table[classType].instances = nullptr;
}
// Adds a new instance of a class.
bool CInstanceManager::AddInstance(ClassType classType, void* pointer, int max)
bool CInstanceManager::AddInstance(ManagedClassType classType, void* instance, int max)
{
int i;
if (classType < 0 || classType >= CLASS_MAX) return false;
if ( classType < 0 || classType >= CLASS_MAX ) return false;
if ( m_table[classType].classPointer == 0 )
if (m_table[classType].instances == nullptr)
{
m_table[classType].classPointer = static_cast<void**>( malloc(max*sizeof(void*)) );
m_table[classType].totalPossible = max;
m_table[classType].totalUsed = 0;
m_table[classType].instances = new void*[max];
m_table[classType].maxCount = max;
m_table[classType].usedCount = 0;
}
if ( m_table[classType].totalUsed >= m_table[classType].totalPossible ) return false;
if (m_table[classType].usedCount >= m_table[classType].maxCount) return false;
i = m_table[classType].totalUsed++;
m_table[classType].classPointer[i] = pointer;
int i = m_table[classType].usedCount++;
m_table[classType].instances[i] = instance;
return true;
}
// Deletes an instance of a class.
bool CInstanceManager::DeleteInstance(ClassType classType, void* pointer)
bool CInstanceManager::DeleteInstance(ManagedClassType classType, void* instance)
{
int i;
if (classType < 0 || classType >= CLASS_MAX) return false;
if ( classType < 0 || classType >= CLASS_MAX ) return false;
for ( i=0 ; i<m_table[classType].totalUsed ; i++ )
for (int i = 0; i < m_table[classType].usedCount; i++)
{
if ( m_table[classType].classPointer[i] == pointer )
{
m_table[classType].classPointer[i] = 0;
}
if (m_table[classType].instances[i] == instance)
m_table[classType].instances[i] = nullptr;
}
Compress(classType);
return true;
}
// Seeking an existing instance. Returns 0 if it does not exist.
// Must be super fast!
void* CInstanceManager::SearchInstance(ClassType classType, int rank)
void* CInstanceManager::SearchInstance(ManagedClassType classType, int rank)
{
#if _DEBUG
if ( classType < 0 || classType >= CLASS_MAX ) return 0;
if ( m_table[classType].classPointer == 0 ) return 0;
#endif
if ( rank >= m_table[classType].totalUsed ) return 0;
if (classType < 0 || classType >= CLASS_MAX) return nullptr;
if (m_table[classType].instances == nullptr) return nullptr;
if (rank >= m_table[classType].usedCount) return nullptr;
return m_table[classType].classPointer[rank];
return m_table[classType].instances[rank];
}
// Fills holes in a table.
void CInstanceManager::Compress(ClassType classType)
void CInstanceManager::Compress(ManagedClassType classType)
{
int i, j;
if (classType < 0 || classType >= CLASS_MAX) return;
if ( classType < 0 || classType >= CLASS_MAX ) return;
j = 0;
for ( i=0 ; i<m_table[classType].totalUsed ; i++ )
int j = 0;
for (int i = 0; i < m_table[classType].usedCount; i++)
{
if ( m_table[classType].classPointer[i] != 0 )
{
m_table[classType].classPointer[j++] = m_table[classType].classPointer[i];
}
if (m_table[classType].instances[i] != nullptr)
m_table[classType].instances[j++] = m_table[classType].instances[i];
}
m_table[classType].totalUsed = j;
m_table[classType].usedCount = j;
}

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// iman.h
/**
* \file iman.h
* \brief Instance manager for managed classes
*/
#pragma once
@ -22,36 +25,119 @@
#include <common/misc.h>
/**
* \enum ManagedClassType
* \brief Type of class managed by CInstanceManager
*/
struct BaseClass
// TODO: remove unnecessary, refactor to singletons, move to CRobotMain, keep others?
enum ManagedClassType
{
int totalPossible;
int totalUsed;
void** classPointer;
//! CEventQueue
CLASS_EVENT = 1,
//! Ui::CInterface
CLASS_INTERFACE = 2,
//! CRobotMain
CLASS_MAIN = 3,
//! Gfx::CEngine
CLASS_ENGINE = 4,
//! Gfx::CTerrain
CLASS_TERRAIN = 5,
//! CObject
CLASS_OBJECT = 6,
//! CPhysics
CLASS_PHYSICS = 7,
//! CBrain
CLASS_BRAIN = 8,
//! Gfx::CCamera
CLASS_CAMERA = 9,
//! Gfx::CLightManager
CLASS_LIGHT = 10,
//! Gfx::CParticle
CLASS_PARTICULE = 11,
//! CAuto; TODO: remove (unused)
CLASS_AUTO = 12,
//! Ui::CDisplayText
CLASS_DISPLAYTEXT = 13,
//! Gfx::CPyro
CLASS_PYRO = 14,
//! Ui::CScript; TODO: remove (unused)
CLASS_SCRIPT = 15,
//! Gfx::CText
CLASS_TEXT = 16,
//! Ui::CStudio, Ui::CDisplayText; TODO: remove (unused)
CLASS_STUDIO = 17,
//! Gfx::CWater
CLASS_WATER = 18,
//! Gfx::CCloud; TODO: remove (unused)
CLASS_CLOUD = 19,
//! CMotion; TODO: remove (unused)
CLASS_MOTION = 20,
//! CSoundInterface
CLASS_SOUND = 21,
//! Gfx::CPlanet
CLASS_PLANET = 22,
//! CTaskManager; TODO: remove (unused)
CLASS_TASKMANAGER = 23,
//! Ui::CMainDialog; TODO: remove (unused)
CLASS_DIALOG = 24,
//! Ui::CMainMap; TODO: remove (unused)
CLASS_MAP = 25,
//! Ui::CMainShort, CMainMovie; TODO: remove (unused)
CLASS_SHORT = 26,
//! Gfx::CLightning; TODO: remove (unused)
CLASS_BLITZ = 27,
//! Maximum (number of managed classes)
CLASS_MAX = 30
};
/**
* \enum ManagedClassInstances
* \brief Instances of class managed by CInstanceManager
*/
struct ManagedClassInstances
{
int maxCount;
int usedCount;
void** instances;
};
/**
* \class CInstanceManager
* \brief Manager for instances of certain classes
*
* Instance manager (often shortened to iMan) allows to register instances of
* classes and search them.
*/
class CInstanceManager : public CSingleton<CInstanceManager>
{
public:
CInstanceManager();
~CInstanceManager();
//! Remove all managed instances
void Flush();
void Flush(ClassType classType);
bool AddInstance(ClassType classType, void* pointer, int max=1);
bool DeleteInstance(ClassType classType, void* pointer);
void* SearchInstance(ClassType classType, int rank=0);
//! Removes instances of one type of class
void Flush(ManagedClassType classType);
//! Registers new instance of class type
bool AddInstance(ManagedClassType classType, void* instance, int max=1);
//! Deletes the registered instance of class type
bool DeleteInstance(ManagedClassType classType, void* instance);
//! Seeks a class instance of given type
void* SearchInstance(ManagedClassType classType, int rank=0);
static CInstanceManager& GetInstance();
static CInstanceManager* GetInstancePointer();
protected:
void Compress(ClassType classType);
//! Fills holes in instance table
void Compress(ManagedClassType classType);
protected:
BaseClass m_table[CLASS_MAX];
ManagedClassInstances m_table[CLASS_MAX];
};

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// ioutils.h
/**
* \file ioutils.h
* \brief Functions for binary I/O
*/
#pragma once

View File

@ -29,6 +29,32 @@
// If need arises, it can be changed to custom function or anything else
#define KEY(x) SDLK_ ## x
// Key modifier defined as concatenation to KMOD_...
// If need arises, it can be changed to custom function or anything else
#define KEY_MOD(x) KMOD_ ## x
/**
* \enum VirtualKmod
* \brief Virtual key codes generated on kmod presses
*
* These are provided here because left and right pair of keys generate different codes.
*/
enum VirtualKmod
{
VIRTUAL_KMOD_CTRL = SDLK_LAST + 100, //! < control (left or right)
VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right)
VIRTUAL_KMOD_ALT = SDLK_LAST + 102, //! < alt (left or right)
VIRTUAL_KMOD_META = SDLK_LAST + 103 //! < win key (left or right)
};
// Just syntax sugar
// So it is the same as other macros
#define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
// Virtual key code generated on joystick button presses
// num is number of joystick button
#define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
//! Special value for invalid key bindings
const unsigned int KEY_INVALID = SDLK_LAST + 1000;

View File

@ -1,54 +0,0 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * 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://www.gnu.org/licenses/.
// language.h
#pragma once
#define _FULL true // CoLoBoT
#define _SCHOOL false // CeeBot-A or Teen
#define _TEEN false // false for CeeBot-A, true for CeeBot-Teen
#define _EDU false
#define _PERSO false
#define _CEEBOTDEMO false
#define _NET false
#define _DEMO false // DEMO only CoLoBoT (with _Full = false)!
#define _FRENCH false
#define _ENGLISH true
#define _GERMAN false
#define _WG false
#define _POLISH false
#define _NEWLOOK false // false for CoLoBoT, true for all CeeBot
#define _SOUNDTRACKS false // always false since InitAudioTrackVolume crop in Vista
// Verifications
#if !_FULL & !_SCHOOL & !_NET & !_DEMO
-> no version chosen!
#endif
#if _SCHOOL
#if !_EDU & !_PERSO & !_CEEBOTDEMO
-> EDU or PERSO or CEEBOTDEMO?
#endif
#if _EDU & _PERSO & _CEEBOTDEMO
-> EDU and PERSO and CEEBOTDEMO not at the same time!!!
#endif
#endif

View File

@ -14,22 +14,20 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// logger.h
/**
* \file common/logger.h
* \brief Class for logging information to file or console
*/
#pragma once
#include "common/singleton.h"
#include <string>
#include <cstdarg>
#include <cstdio>
#include <common/singleton.h>
/**
* @file common/logger.h
* @brief Class for loggin information to file or console
*/
/**
* \public

View File

@ -16,17 +16,15 @@
// metafile.cpp
#include <windows.h>
#include <stdio.h>
#include "common/language.h"
#include "common/metafile.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if _FULL | _NET
//#if _FULL | _NET
static unsigned char table_codec[23] =
{
0x85, 0x91, 0x73, 0xcf, 0xa2, 0xbb, 0xf4, 0x77,
@ -36,7 +34,7 @@ static unsigned char table_codec[23] =
void Codec(void* buffer, int len, int start)
{
unsigned char *b = (unsigned char*)buffer;
unsigned char *b = static_cast<unsigned char*>(buffer);
int i;
for ( i=0 ; i<len ; i++ )
@ -44,9 +42,9 @@ void Codec(void* buffer, int len, int start)
b[i] ^= table_codec[(start++)%23];
}
}
#endif
//#endif
#if _SCHOOL
/*#if _SCHOOL
#if _CEEBOTDEMO
static unsigned char table_codec[136] =
{
@ -99,9 +97,9 @@ void Codec(void* buffer, int len, int start)
}
}
#endif
#endif
#endif*/
#if _DEMO
/*#if _DEMO
static unsigned char table_codec[27] =
{
0x85, 0x91, 0x77, 0xcf, 0xa3, 0xbb, 0xf4, 0x77,
@ -120,7 +118,7 @@ void Codec(void* buffer, int len, int start)
b[i] ^= table_codec[(start++)%27];
}
}
#endif
#endif*/
@ -286,7 +284,7 @@ int CMetaFile::Read(void *buffer, int size)
int CMetaFile::GetByte()
{
BYTE b;
int b;
if ( !m_bOpen ) return 1;
@ -303,7 +301,7 @@ int CMetaFile::GetByte()
int CMetaFile::GetWord()
{
WORD w;
int w;
if ( !m_bOpen ) return 1;
@ -352,7 +350,7 @@ int CMetaFile::MetaOpen(char *metaname)
strcpy(m_list[i].name, metaname); // memorized the name
fread(&m_list[i].total, sizeof(int), 1, m_list[i].stream);
m_list[i].headers = (MetaHeader*)malloc(sizeof(MetaHeader)*m_list[i].total);
m_list[i].headers = static_cast<MetaHeader*>(malloc(sizeof(MetaHeader)*m_list[i].total));
offset = 4;
for ( j=0 ; j<m_list[i].total ; j++ )

View File

@ -17,195 +17,171 @@
// misc.cpp
#include "common/misc.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <direct.h>
#include <time.h>
#include <d3d.h>
#include "common/struct.h"
#include "old/d3dengine.h"
#include "old/d3dmath.h"
#include "old/d3dutil.h"
#include "common/language.h"
#include "common/event.h"
#include "common/misc.h"
CMetaFile g_metafile;
static EventMsg g_uniqueEventMsg = EVENT_USER;
static bool g_bUserDir = false;
static char g_userDir[100] = "";
// Gives a single user event.
EventMsg GetUniqueEventMsg()
{
int i;
i = (int)g_uniqueEventMsg+1;
g_uniqueEventMsg = (EventMsg)i;
return g_uniqueEventMsg;
}
// Returns a non-accented letter.
char RetNoAccent(char letter)
char GetNoAccent(char letter)
{
/*
if ( letter < 0 )
{
if ( letter == 'á' ||
letter == 'à' ||
letter == 'â' ||
letter == 'ä' ||
letter == 'ã' ) return 'a';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'a';
if ( letter == 'é' ||
letter == 'è' ||
letter == 'ê' ||
letter == 'ë' ) return 'e';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'e';
if ( letter == 'í' ||
letter == 'ì' ||
letter == 'î' ||
letter == 'ï' ) return 'i';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'i';
if ( letter == 'ó' ||
letter == 'ò' ||
letter == 'ô' ||
letter == 'ö' ||
letter == 'õ' ) return 'o';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'o';
if ( letter == 'ú' ||
letter == 'ù' ||
letter == 'û' ||
letter == 'ü' ) return 'u';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'u';
if ( letter == 'ç' ) return 'c';
if ( letter == '<EFBFBD>' ) return 'c';
if ( letter == 'ñ' ) return 'n';
if ( letter == '<EFBFBD>' ) return 'n';
if ( letter == 'Á' ||
letter == 'À' ||
letter == 'Â' ||
letter == 'Ä' ||
letter == 'Ã' ) return 'A';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'A';
if ( letter == 'É' ||
letter == 'È' ||
letter == 'Ê' ||
letter == 'Ë' ) return 'E';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'E';
if ( letter == 'Í' ||
letter == 'Ì' ||
letter == 'Î' ||
letter == 'Ï' ) return 'I';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'I';
if ( letter == 'Ó' ||
letter == 'Ò' ||
letter == 'Ô' ||
letter == 'Ö' ||
letter == 'Õ' ) return 'O';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'O';
if ( letter == 'Ú' ||
letter == 'Ù' ||
letter == 'Û' ||
letter == 'Ü' ) return 'U';
if ( letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ||
letter == '<EFBFBD>' ) return 'U';
if ( letter == 'Ç' ) return 'C';
if ( letter == '<EFBFBD>' ) return 'C';
if ( letter == 'Ñ' ) return 'N';
}
if ( letter == '<EFBFBD>' ) return 'N';
}*/
return letter;
}
// Returns an uppercase letter.
char RetToUpper(char letter)
char GetToUpper(char letter)
{
if ( letter < 0 )
/*if ( letter < 0 )
{
if ( letter == 'á' ) return 'Á';
if ( letter == 'à' ) return 'À';
if ( letter == 'â' ) return 'Â';
if ( letter == 'ä' ) return 'Ä';
if ( letter == 'ã' ) return 'Ã';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'é' ) return 'É';
if ( letter == 'è' ) return 'È';
if ( letter == 'ê' ) return 'Ê';
if ( letter == 'ë' ) return 'Ë';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'í' ) return 'Í';
if ( letter == 'ì' ) return 'Ì';
if ( letter == 'î' ) return 'Î';
if ( letter == 'ï' ) return 'Ï';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ó' ) return 'Ó';
if ( letter == 'ò' ) return 'Ò';
if ( letter == 'ô' ) return 'Ô';
if ( letter == 'ö' ) return 'Ö';
if ( letter == 'õ' ) return 'Õ';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ú' ) return 'Ú';
if ( letter == 'ù' ) return 'Ù';
if ( letter == 'û' ) return 'Û';
if ( letter == 'ü' ) return 'Ü';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ç' ) return 'Ç';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ñ' ) return 'Ñ';
}
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
}*/
return toupper(letter);
}
// Returns a lowercase letter.
char RetToLower(char letter)
char GetToLower(char letter)
{
if ( letter < 0 )
/*if ( letter < 0 )
{
if ( letter == 'Á' ) return 'á';
if ( letter == 'À' ) return 'à';
if ( letter == 'Â' ) return 'â';
if ( letter == 'Ä' ) return 'ä';
if ( letter == 'Ã' ) return 'ã';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'É' ) return 'é';
if ( letter == 'È' ) return 'è';
if ( letter == 'Ê' ) return 'ê';
if ( letter == 'Ë' ) return 'ë';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Í' ) return 'í';
if ( letter == 'Ì' ) return 'ì';
if ( letter == 'Î' ) return 'î';
if ( letter == 'Ï' ) return 'ï';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ó' ) return 'ó';
if ( letter == 'Ò' ) return 'ò';
if ( letter == 'Ô' ) return 'ô';
if ( letter == 'Ö' ) return 'ö';
if ( letter == 'Õ' ) return 'õ';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ú' ) return 'ú';
if ( letter == 'Ù' ) return 'ù';
if ( letter == 'Û' ) return 'û';
if ( letter == 'Ü' ) return 'ü';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ç' ) return 'ç';
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ñ' ) return 'ñ';
}
if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
}*/
return tolower(letter);
}
@ -222,6 +198,7 @@ void TimeToAscii(time_t time, char *buffer)
year = when.tm_year+1900;
if ( year < 2000 ) year -= 1900;
else year -= 2000;
/* TODO
#if _FRENCH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year,
@ -232,7 +209,7 @@ void TimeToAscii(time_t time, char *buffer)
when.tm_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min);
#endif
#if _ENGLISH
#if _ENGLISH*/
char format[10];
int hour;
@ -251,12 +228,12 @@ void TimeToAscii(time_t time, char *buffer)
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s",
when.tm_mon+1, when.tm_mday, year,
hour, when.tm_min, format);
#endif
/*#endif
#if _POLISH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min);
#endif
#endif*/
}
@ -281,7 +258,7 @@ bool Xfer(char* src, char* dst)
return false;
}
buffer = (char*)malloc(10000);
buffer = static_cast<char*>(malloc(10000));
while ( true )
{
@ -311,7 +288,9 @@ bool CopyFileToTemp(char* filename)
UserDir(dst, filename, "textures");
strcpy(g_userDir, save);
_mkdir("temp");
//_mkdir("temp");
system("mkdir temp");
if ( !Xfer(src, dst) ) return false;
strcpy(filename, dst);
@ -359,7 +338,7 @@ bool CopyFileListToTemp(char* filename, int* list, int total)
// Adds an extension to file, if doesn't already one.
void AddExt(char* filename, char* ext)
void AddExt(char* filename, const char* ext)
{
if ( strchr(filename, '.') != 0 ) return; // already an extension?
strcat(filename, ext);
@ -368,7 +347,7 @@ void AddExt(char* filename, char* ext)
// Specifies the user folder.
void UserDir(bool bUser, char* dir)
void UserDir(bool bUser, const char* dir)
{
g_bUserDir = bUser;
strcpy(g_userDir, dir);
@ -379,10 +358,10 @@ void UserDir(bool bUser, char* dir)
// def = "abc\"
// out: buffer = "abc\toto.txt"
void UserDir(char* buffer, char* dir, char* def)
void UserDir(char* buffer, const char* dir, const char* def)
{
char ddir[100];
char* add;
const char* add;
if ( strstr(dir, "\\") == 0 && def[0] != 0 )
{
@ -418,24 +397,3 @@ void UserDir(char* buffer, char* dir, char* def)
}
*buffer = 0;
}
// Returns the letter corresponding to the language.
char RetLanguageLetter()
{
#if _FRENCH
return 'F';
#endif
#if _ENGLISH
return 'E';
#endif
#if _GERMAN | _WG
return 'D';
#endif
#if _POLISH
return 'P';
#endif
return 'X';
}

View File

@ -22,55 +22,7 @@
#include <time.h>
#include "common/metafile.h"
#include "common/event.h"
#include "common/error_ids.h"
extern CMetaFile g_metafile;
// Existing classes.
enum ClassType
{
CLASS_EVENT = 1,
CLASS_INTERFACE = 2,
CLASS_MAIN = 3,
CLASS_ENGINE = 4,
CLASS_TERRAIN = 5,
CLASS_OBJECT = 6,
CLASS_PHYSICS = 7,
CLASS_BRAIN = 8,
CLASS_CAMERA = 9,
CLASS_LIGHT = 10,
CLASS_PARTICULE = 11,
CLASS_AUTO = 12,
CLASS_DISPLAYTEXT = 13,
CLASS_PYRO = 14,
CLASS_SCRIPT = 15,
CLASS_TEXT = 16,
CLASS_STUDIO = 17,
CLASS_WATER = 18,
CLASS_CLOUD = 19,
CLASS_MOTION = 20,
CLASS_SOUND = 21,
CLASS_PLANET = 22,
CLASS_TASKMANAGER = 23,
CLASS_DIALOG = 24,
CLASS_MAP = 25,
CLASS_SHORT = 26,
CLASS_BLITZ = 27,
};
const int CLASS_MAX = 30;
// Keyboard state.
// TODO: to be removed (replaced by TrackedKey enum and mouse states in app.h)
const int KS_PAGEUP = (1<<4);
const int KS_PAGEDOWN = (1<<5);
const int KS_SHIFT = (1<<6);
@ -84,23 +36,16 @@ const int KS_NUMRIGHT = (1<<13);
const int KS_NUMPLUS = (1<<14);
const int KS_NUMMINUS = (1<<15);
// TODO: rewrite/refactor or remove
// Procedures.
extern EventType GetUniqueEventType();
extern char RetNoAccent(char letter);
extern char RetToUpper(char letter);
extern char RetToLower(char letter);
extern char GetNoAccent(char letter);
extern char GetToUpper(char letter);
extern char GetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer);
extern bool CopyFileToTemp(char* filename);
extern bool CopyFileListToTemp(char* filename, int* list, int total);
extern void AddExt(char* filename, char* ext);
extern void UserDir(bool bUser, char* dir);
extern void UserDir(char* buffer, char* dir, char* def);
extern char RetLanguageLetter();
extern void AddExt(char* filename, const char* ext);
extern void UserDir(bool bUser, const char* dir);
extern void UserDir(char* buffer, const char* dir, const char* def);

View File

@ -17,7 +17,10 @@
// profile.cpp
#include <common/profile.h>
#include "common/profile.h"
#include <utility>
#include <cstring>
template<> CProfile* CSingleton<CProfile>::mInstance = nullptr;

View File

@ -14,22 +14,19 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// profile.h
/**
* \file common/profile.h
* \brief Class for loading profile (currently for loading ini config file)
*/
#pragma once
#include <cstdlib>
#include "lib/simpleini/SimpleIni.h"
#include "common/singleton.h"
#include <string>
#include <vector>
#include <utility>
#include <lib/simpleini/SimpleIni.h>
#include <common/singleton.h>
/**
* @file common/profile.h
* @brief Class for loading profile (currently for loading ini config file)
*/
/**

View File

@ -14,29 +14,21 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.// restext.cpp
#include <libintl.h>
#include <SDL/SDL_keyboard.h>
#include "common/struct.h"
#include "common/language.h"
#include "common/misc.h"
#include "common/event.h"
#include "object/object.h"
#include "CBot/resource.h"
#include "common/restext.h"
#include "common/global.h"
#include "common/event.h"
#include "common/logger.h"
#include "CBot/resource.h"
#include "object/object.h"
#include "object/robotmain.h"
#include <libintl.h>
#include <SDL/SDL_keyboard.h>
// Gives the pointer to the engine.
static CD3DEngine* g_engine;
static char g_gamerName[100];
void SetEngine(CD3DEngine *engine)
{
g_engine = engine;
}
// Give the player's name.
void SetGlobalGamerName(char *name)
{
strcpy(g_gamerName, name);
@ -46,39 +38,38 @@ void SetGlobalGamerName(char *name)
struct KeyDesc
{
KeyRank key;
InputSlot key;
char name[20];
};
static KeyDesc keyTable[22] =
{
{ KEYRANK_LEFT, "left;" },
{ KEYRANK_RIGHT, "right;" },
{ KEYRANK_UP, "up;" },
{ KEYRANK_DOWN, "down;" },
{ KEYRANK_GUP, "gup;" },
{ KEYRANK_GDOWN, "gdown;" },
{ KEYRANK_CAMERA, "camera;" },
{ KEYRANK_DESEL, "desel;" },
{ KEYRANK_ACTION, "action;" },
{ KEYRANK_NEAR, "near;" },
{ KEYRANK_AWAY, "away;" },
{ KEYRANK_NEXT, "next;" },
{ KEYRANK_HUMAN, "human;" },
{ KEYRANK_QUIT, "quit;" },
{ KEYRANK_HELP, "help;" },
{ KEYRANK_PROG, "prog;" },
{ KEYRANK_CBOT, "cbot;" },
{ KEYRANK_VISIT, "visit;" },
{ KEYRANK_SPEED10, "speed10;" },
{ KEYRANK_SPEED15, "speed15;" },
{ KEYRANK_SPEED20, "speed20;" },
{ KEYRANK_SPEED30, "speed30;" },
{ INPUT_SLOT_LEFT, "left;" },
{ INPUT_SLOT_RIGHT, "right;" },
{ INPUT_SLOT_UP, "up;" },
{ INPUT_SLOT_DOWN, "down;" },
{ INPUT_SLOT_GUP, "gup;" },
{ INPUT_SLOT_GDOWN, "gdown;" },
{ INPUT_SLOT_CAMERA, "camera;" },
{ INPUT_SLOT_DESEL, "desel;" },
{ INPUT_SLOT_ACTION, "action;" },
{ INPUT_SLOT_NEAR, "near;" },
{ INPUT_SLOT_AWAY, "away;" },
{ INPUT_SLOT_NEXT, "next;" },
{ INPUT_SLOT_HUMAN, "human;" },
{ INPUT_SLOT_QUIT, "quit;" },
{ INPUT_SLOT_HELP, "help;" },
{ INPUT_SLOT_PROG, "prog;" },
{ INPUT_SLOT_CBOT, "cbot;" },
{ INPUT_SLOT_VISIT, "visit;" },
{ INPUT_SLOT_SPEED10, "speed10;" },
{ INPUT_SLOT_SPEED15, "speed15;" },
{ INPUT_SLOT_SPEED20, "speed20;" }
};
// Seeks a key.
bool SearchKey(const char *cmd, KeyRank &key)
bool SearchKey(const char *cmd, InputSlot &key)
{
int i;
@ -97,9 +88,10 @@ bool SearchKey(const char *cmd, KeyRank &key)
static void PutKeyName(char* dst, const char* src)
{
KeyRank key;
InputSlot key;
char name[50];
int s, d, n, res;
int s, d, n;
unsigned int res;
s = d = 0;
while ( src[s] != 0 )
@ -112,9 +104,8 @@ static void PutKeyName(char* dst, const char* src)
{
if ( SearchKey(src+s+5, key) )
{
// FIXME: res = g_engine->RetKey(key, 0);
res = 0;
if ( res != 0 )
res = CRobotMain::GetInstancePointer()->GetInputBinding(key).key;
if (res != KEY_INVALID)
{
if ( GetResource(RES_KEY, res, name) )
{
@ -150,7 +141,12 @@ static const char* GetResourceBase(ResType type, int num)
str = strings_text[num];
break;
case RES_EVENT:
assert(num < strings_event_len);
// assert(num < strings_event_len);
if (num >= strings_event_len)
{
GetLogger()->Warn("GetResource invalid event num: %d\n", num);
return "";
}
str = strings_event[num];
break;
case RES_OBJECT:
@ -169,6 +165,7 @@ static const char* GetResourceBase(ResType type, int num)
break;
case RES_KEY:
assert(num < SDLK_LAST);
// TODO: virtual keys
str = SDL_GetKeyName(static_cast<SDLKey>(num));
break;
default:

View File

@ -14,32 +14,36 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// restext.h
/**
* \file common/restext.h
* \brief Translation and string resource utilities
*/
#pragma once
#include "common/global.h"
#include "common/restext_ids.h"
class CD3DEngine;
// Possible types of the text resources.
/**
* \enum ResType
* \brief Types of text resources
*/
enum ResType
{
RES_TEXT = 0, // RT_*
RES_EVENT = 1, // EVENT_* (EventMsg)
RES_OBJECT = 2, // OBJECT_* (ObjectType)
RES_ERR = 3, // ERR_* (Error)
RES_KEY = 4, // VK_* (keys)
RES_CBOT = 5, // TX_* (cbot.dll)
RES_TEXT = 0, //! < RT_*
RES_EVENT = 1, //! < EVENT_* (EventMsg)
RES_OBJECT = 2, //! < OBJECT_* (ObjectType)
RES_ERR = 3, //! < ERR_* (Error)
RES_KEY = 4, //! < KEY() (keys)
RES_CBOT = 5, //! < TX_* (CBot)
};
extern void SetEngine(CD3DEngine *engine);
// TODO: move to CRobotMain
extern void SetGlobalGamerName(char *name);
extern bool SearchKey(char *cmd, KeyRank &key);
extern bool SearchKey(const char *cmd, InputSlot& slot);
extern bool GetResource(ResType type, int num, char* text);
extern const char * const strings_text[];

View File

@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// TODO: move to restext.h after restext rewrite
#pragma once
enum ResTextType

View File

@ -22,36 +22,8 @@
const char * const strings_text[] =
{
#if _FULL
[RT_VERSION_ID] = "1.18 /e",
#endif
#if _NET
[RT_VERSION_ID] = "CeeBot-A 1.18",
#endif
#if _SCHOOL & _EDU
#if _TEEN
[RT_VERSION_ID] = "CeeBot-Teen EDU 1.18",
#else
[RT_VERSION_ID] = "CeeBot-A EDU 1.18",
#endif
#endif
#if _SCHOOL & _PERSO
#if _TEEN
[RT_VERSION_ID] = "CeeBot-Teen PERSO 1.18",
#else
[RT_VERSION_ID] = "CeeBot-A PERSO 1.18",
#endif
#endif
#if _SCHOOL & _CEEBOTDEMO
#if _TEEN
[RT_VERSION_ID] = "CeeBot-Teen DEMO 1.18",
#else
[RT_VERSION_ID] = "CeeBot-A DEMO 1.18",
#endif
#endif
#if _DEMO
[RT_VERSION_ID] = "Demo 1.18 /e",
#endif
[RT_VERSION_ID] = "Colobot Gold",
[RT_DISINFO_TITLE] = "SatCom",
[RT_WINDOW_MAXIMIZED] = "Maximize",
[RT_WINDOW_MINIMIZED] = "Minimize",
@ -64,13 +36,8 @@ const char * const strings_text[] =
[RT_IO_NEW] = "New ...",
[RT_KEY_OR] = " or ",
#if _NEWLOOK
[RT_TITLE_BASE] = "CeeBot",
[RT_TITLE_INIT] = "CeeBot",
#else
[RT_TITLE_BASE] = "COLOBOT",
[RT_TITLE_INIT] = "COLOBOT",
#endif
[RT_TITLE_TRAINER] = "Programming exercises",
[RT_TITLE_DEFI] = "Challenges",
[RT_TITLE_MISSION] = "Missions",
@ -111,15 +78,9 @@ const char * const strings_text[] =
[RT_PERSO_COMBI] = "Suit color:",
[RT_PERSO_BAND] = "Strip color:",
#if _NEWLOOK
[RT_DIALOG_QUIT] = "Do you want to quit CeeBot ?",
[RT_DIALOG_TITLE] = "CeeBot",
[RT_DIALOG_YESQUIT] = "Quit\\Quit CeeBot",
#else
[RT_DIALOG_QUIT] = "Do you want to quit COLOBOT ?",
[RT_DIALOG_TITLE] = "COLOBOT",
[RT_DIALOG_YESQUIT] = "Quit\\Quit COLOBOT",
#endif
[RT_DIALOG_ABORT] = "Quit the mission?",
[RT_DIALOG_YES] = "Abort\\Abort the current mission",
[RT_DIALOG_NO] = "Continue\\Continue the current mission",
@ -182,13 +143,8 @@ const char * const strings_event[] =
[EVENT_INTERFACE_AGAIN] = "Restart\\Restart the mission from the beginning",
[EVENT_INTERFACE_WRITE] = "Save\\Save the current mission ",
[EVENT_INTERFACE_READ] = "Load\\Load a saved mission",
#if _NEWLOOK
[EVENT_INTERFACE_ABORT] = "\\Return to CeeBot",
[EVENT_INTERFACE_QUIT] = "Quit\\Quit CeeBot",
#else
[EVENT_INTERFACE_ABORT] = "\\Return to COLOBOT",
[EVENT_INTERFACE_QUIT] = "Quit\\Quit COLOBOT",
#endif
[EVENT_INTERFACE_BACK] = "<< Back \\Back to the previous screen",
[EVENT_INTERFACE_PLAY] = "Play\\Start mission!",
[EVENT_INTERFACE_SETUPd] = "Device\\Driver and resolution settings",
@ -432,11 +388,7 @@ const char * const strings_event[] =
[EVENT_HYPER_SIZE4] = "Size 4",
[EVENT_HYPER_SIZE5] = "Size 5",
[EVENT_SATCOM_HUSTON] = "Instructions from Houston",
#if _TEEN
[EVENT_SATCOM_SAT] = "Dictionnary",
#else
[EVENT_SATCOM_SAT] = "Satellite report",
#endif
[EVENT_SATCOM_LOADING] = "Programs dispatched by Houston",
[EVENT_SATCOM_OBJECT] = "List of objects",
[EVENT_SATCOM_PROG] = "Programming help",
@ -475,11 +427,7 @@ const char * const strings_object[] =
[OBJECT_RESEARCH] = "Research center",
[OBJECT_RADAR] = "Radar station",
[OBJECT_INFO] = "Information exchange post",
#if _TEEN
[OBJECT_ENERGY] = "Disintegrator",
#else
[OBJECT_ENERGY] = "Power cell factory",
#endif
[OBJECT_LABO] = "Autolab",
[OBJECT_NUCLEAR] = "Nuclear power station",
[OBJECT_PARA] = "Lightning conductor",
@ -574,13 +522,6 @@ const char * const strings_object[] =
const char * const strings_err[] =
{
[ERR_CMD] = "Unknown command",
#if _NEWLOOK
[ERR_INSTALL] = "CeeBot not installed.",
[ERR_NOCD] = "Please insert the CeeBot CD\nand re-run the game.",
#else
[ERR_INSTALL] = "COLOBOT not installed.",
[ERR_NOCD] = "Please insert the COLOBOT CD\nand re-run the game.",
#endif
[ERR_MANIP_VEH] = "Inappropriate bot",
[ERR_MANIP_FLY] = "Impossible when flying",
[ERR_MANIP_BUSY] = "Already carrying something",

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// singleton.h
/**
* \file common/singleton.h
* \brief CSingleton base class for singletons
*/
#pragma once

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/.
// stringutils.h
/**
* \file common/stringutils.h
* \brief Some useful string operations
*/
#pragma once

View File

@ -1,54 +0,0 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// *
// * 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://www.gnu.org/licenses/.
// struct.h
#pragma once
#include <math/vector.h>
#define D3DFVF_VERTEX2 (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)
struct D3DVERTEX2
{
float x,y,z;
float nx,ny,nz;
float tu, tv;
float tu2, tv2;
D3DVERTEX2() { }
D3DVERTEX2(const Math::Vector& _v, const Math::Vector& _n, float _tu=0.0f, float _tv=0.0f, float _tu2=0.0f, float _tv2=0.0f)
{
x = _v.x;
y = _v.y;
z = _v.z;
nx = _n.x;
ny = _n.y;
nz = _n.z;
tu = _tu;
tv = _tv;
tu2 = _tu2;
tv2 = _tv2;
}
};
struct ColorHSV
{
float h,s,v;
};

View File

@ -7,6 +7,8 @@ include_directories("../../")
include_directories("../../../")
add_executable(image_test ../image.cpp image_test.cpp)
target_link_libraries(image_test -lpng -lSDL -lSDL_image)
add_executable(profile_test ../profile.cpp profile_test.cpp)
add_test(profile_test ./profile_test)

View File

@ -22,6 +22,29 @@ int main(int argc, char *argv[])
printf("Error loading '%s': %s\n", err.c_str());
return 1;
}
Gfx::Color color;
std::string str;
color = image.GetPixel(Math::IntPoint(0, 0));
str = color.ToString();
printf("pixel @ (0,0): %s\n", str.c_str());
color = image.GetPixel(Math::IntPoint(0, 1));
str = color.ToString();
printf("pixel @ (0,1): %s\n", str.c_str());
color = image.GetPixel(Math::IntPoint(1, 0));
str = color.ToString();
printf("pixel @ (1,0): %s\n", str.c_str());
color = image.GetPixel(Math::IntPoint(1, 1));
str = color.ToString();
printf("pixel @ (1,1): %s\n", str.c_str());
image.SetPixel(Math::IntPoint(0, 0), Gfx::Color(0.1f, 0.2f, 0.3f, 0.0f));
image.SetPixel(Math::IntPoint(1, 0), Gfx::Color(0.3f, 0.2f, 0.1f, 1.0f));
image.SetPixel(Math::IntPoint(0, 1), Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f));
image.SetPixel(Math::IntPoint(1, 1), Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f));
if (! image.SavePNG(argv[2]))
{

View File

@ -66,6 +66,7 @@ struct Light
float attenuation2;
//! Angle of spotlight cone (0-90 degrees)
float spotAngle;
//! Intensity of spotlight (0 = uniform; 128 = most intense)
float spotIntensity;

View File

@ -28,67 +28,6 @@
#include "object/object.h"
#include "physics/physics.h"
// TODO temporary stubs for CObject and CPhysics
void CObject::SetTransparency(float)
{
}
CObject* CObject::GetFret()
{
return nullptr;
}
CObject* CObject::GetPower()
{
return nullptr;
}
CObject* CObject::GetTruck()
{
return nullptr;
}
ObjectType CObject::GetType()
{
return OBJECT_NULL;
}
void CObject::SetGunGoalH(float)
{
}
void CObject::GetGlobalSphere(Math::Vector &pos, float &radius)
{
}
float CObject::GetAngleY(int)
{
return 0.0f;
}
Math::Vector CObject::GetPosition(int)
{
return Math::Vector();
}
void CObject::SetViewFromHere(Math::Vector &eye, float &dirH, float &dirV,
Math::Vector &lookat, Math::Vector &upVec,
Gfx::CameraType type)
{
}
CPhysics* CObject::GetPhysics()
{
return nullptr;
}
bool CPhysics::GetLand()
{
return false;
}
//! Changes the level of transparency of an object and objects transported (battery & cargo)
void SetTransparency(CObject* obj, float value)
{
@ -263,12 +202,12 @@ void Gfx::CCamera::Init(Math::Vector eye, Math::Vector lookat, float delay)
}
void Gfx::CCamera::SetObject(CObject* object)
void Gfx::CCamera::SetControllingObject(CObject* object)
{
m_cameraObj = object;
}
CObject* Gfx::CCamera::GetObject()
CObject* Gfx::CCamera::GetControllingObject()
{
return m_cameraObj;
}
@ -1063,11 +1002,9 @@ bool Gfx::CCamera::EventProcess(const Event &event)
EventMouseMove(event);
break;
// TODO: mouse wheel event
/*case EVENT_KEY_DOWN:
if ( event.param == VK_WHEELUP ) EventMouseWheel(+1);
if ( event.param == VK_WHEELDOWN ) EventMouseWheel(-1);
break;*/
case EVENT_MOUSE_WHEEL:
EventMouseWheel(event.mouseWheel.dir);
break;
default:
break;
@ -1081,17 +1018,17 @@ bool Gfx::CCamera::EventMouseMove(const Event &event)
return true;
}
void Gfx::CCamera::EventMouseWheel(int dir)
void Gfx::CCamera::EventMouseWheel(WheelDirection dir)
{
if (m_type == Gfx::CAM_TYPE_BACK)
{
if (dir > 0)
if (dir == WHEEL_UP)
{
m_backDist -= 8.0f;
if (m_backDist < m_backMin)
m_backDist = m_backMin;
}
if (dir < 0)
else if (dir == WHEEL_DOWN)
{
m_backDist += 8.0f;
if (m_backDist > 200.0f)
@ -1102,13 +1039,13 @@ void Gfx::CCamera::EventMouseWheel(int dir)
if ( m_type == Gfx::CAM_TYPE_FIX ||
m_type == Gfx::CAM_TYPE_PLANE )
{
if (dir > 0)
if (dir == WHEEL_UP)
{
m_fixDist -= 8.0f;
if (m_fixDist < 10.0f)
m_fixDist = 10.0f;
}
if (dir < 0)
else if (dir == WHEEL_DOWN)
{
m_fixDist += 8.0f;
if (m_fixDist > 200.0f)
@ -1118,13 +1055,13 @@ void Gfx::CCamera::EventMouseWheel(int dir)
if ( m_type == Gfx::CAM_TYPE_VISIT )
{
if (dir > 0)
if (dir == WHEEL_UP)
{
m_visitDist -= 8.0f;
if (m_visitDist < 20.0f)
m_visitDist = 20.0f;
}
if (dir < 0)
else if (dir == WHEEL_DOWN)
{
m_visitDist += 8.0f;
if (m_visitDist > 200.0f)
@ -1245,19 +1182,19 @@ bool Gfx::CCamera::EventFrameFree(const Event &event)
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed);
// Up/Down
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, event.axeY * event.rTime * factor * m_speed);
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, event.motionInput.y * event.rTime * factor * m_speed);
// Left/Right
if ( event.keyState & KS_CONTROL )
{
if ( event.axeX < 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.axeX * event.rTime * factor * m_speed);
if ( event.axeX > 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.axeX * event.rTime * factor * m_speed);
if ( event.motionInput.x < 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.motionInput.x * event.rTime * factor * m_speed);
if ( event.motionInput.x > 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.motionInput.x * event.rTime * factor * m_speed);
}
else
{
m_directionH -= event.axeX * event.rTime * 0.7f * m_speed;
m_directionH -= event.motionInput.x * event.rTime * 0.7f * m_speed;
}
// PageUp/PageDown
@ -1719,3 +1656,4 @@ Math::Vector Gfx::CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat,
return eye;*/
}

View File

@ -136,8 +136,8 @@ class CCamera {
void Init(Math::Vector eye, Math::Vector lookat, float delay);
//! Sets the object controlling the camera
void SetObject(CObject* object);
CObject* GetObject();
void SetControllingObject(CObject* object);
CObject* GetControllingObject();
//! Change the type of camera
void SetType(Gfx::CameraType type);
@ -208,7 +208,7 @@ protected:
//! Changes the camera according to the mouse moved
bool EventMouseMove(const Event &event);
//! Mouse wheel operation
void EventMouseWheel(int dir);
void EventMouseWheel(WheelDirection dir);
//! Changes the camera according to the time elapsed
bool EventFrame(const Event &event);
//! Moves the point of view

View File

@ -37,6 +37,7 @@
#include "graphics/engine/water.h"
#include "math/geometry.h"
#include "sound/sound.h"
#include "ui/interface.h"
// Initial size of various vectors
@ -87,15 +88,6 @@ Gfx::EngineObjLevel4::EngineObjLevel4(bool used, Gfx::EngineTriangleType type, c
vertices.reserve(LEVEL4_VERTEX_PREALLOCATE_COUNT);
}
// TODO: temporary stub for CInterface
class CInterface
{
public:
void Draw() {}
};
Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
{
m_iMan = iMan;
@ -147,7 +139,7 @@ Gfx::CEngine::CEngine(CInstanceManager *iMan, CApplication *app)
m_backgroundCloudUp = Gfx::Color();
m_backgroundCloudDown = Gfx::Color();
m_backgroundFull = false;
m_backgroundQuarter = false;
m_backgroundScale = Math::Point(1.0f, 1.0f);
m_overFront = true;
m_overColor = Gfx::Color();
m_overMode = ENG_RSTATE_TCOLOR_BLACK;
@ -338,41 +330,23 @@ bool Gfx::CEngine::ProcessEvent(const Event &event)
int index = static_cast<int>(m_mouseType);
m_mouseType = static_cast<Gfx::EngineMouseType>( (index + 1) % Gfx::ENG_MOUSE_COUNT );
}
else if (event.key.key == KEY(F3))
{
bool bq = !m_backgroundQuarter;
SetBackground(bq ? "geneda.png" : "", Gfx::Color(), Gfx::Color(), Gfx::Color(), Gfx::Color(), true, bq);
}
else if (event.key.key == KEY(F4))
{
m_skyMode = !m_skyMode;
if (! m_skyMode)
{
m_backgroundColorDown = Gfx::Color(0.2f, 0.2f, 0.2f);
m_backgroundColorUp = Gfx::Color(0.8f, 0.8f, 0.8f);
}
else
{
m_backgroundColorDown = m_backgroundColorUp = Gfx::Color(0.0f, 0.0f, 0.0f);
}
}
}
else if (event.type == EVENT_FRAME)
{
m_highlightTime += event.rTime;
}
// By default, pass on all events
return true;
}
void Gfx::CEngine::FrameMove(float rTime)
void Gfx::CEngine::FrameUpdate()
{
float rTime = m_app->GetRelTime();
m_lightMan->UpdateProgression(rTime);
m_particle->FrameParticle(rTime);
ComputeDistance();
UpdateGeometry();
m_highlightTime = m_app->GetAbsTime();
if (m_groundMark.draw)
{
if (m_groundMark.phase == Gfx::ENG_GR_MARK_PHASE_INC) // growing?
@ -402,16 +376,6 @@ void Gfx::CEngine::FrameMove(float rTime)
}
}
}
if (m_sound == nullptr)
m_sound = static_cast<CSoundInterface*>( m_iMan->SearchInstance(CLASS_SOUND) );
m_sound->FrameMove(rTime);
}
void Gfx::CEngine::StepSimulation(float rTime)
{
m_app->StepSimulation(rTime);
}
bool Gfx::CEngine::WriteScreenShot(const std::string& fileName, int width, int height)
@ -2166,26 +2130,10 @@ bool Gfx::CEngine::LoadAllTextures()
LoadTexture("effect02.png");
LoadTexture("map.png");
if (m_backgroundQuarter) // image into 4 pieces?
{
if (! m_backgroundName.empty())
{
for (int i = 0; i < 4; i++)
m_backgroundQuarterTexs[i] = LoadTexture(m_backgroundQuarterNames[i]);
}
else
{
for (int i = 0; i < 4; i++)
m_backgroundQuarterTexs[i].SetInvalid();
}
}
if (! m_backgroundName.empty())
m_backgroundTex = LoadTexture(m_backgroundName);
else
{
if (! m_backgroundName.empty())
m_backgroundFullTex = LoadTexture(m_backgroundName);
else
m_backgroundFullTex.SetInvalid();
}
m_backgroundTex.SetInvalid();
if (! m_foregroundName.empty())
m_foregroundTex = LoadTexture(m_foregroundName);
@ -2464,29 +2412,14 @@ float Gfx::CEngine::GetFogStart(int rank)
return m_fogStart[rank];
}
std::string QuarterName(const std::string& name, int quarter)
{
size_t pos = name.find('.');
if (pos == std::string::npos)
return name;
return name.substr(0, pos) + std::string(1, static_cast<char>('a' + quarter)) + name.substr(pos);
}
void Gfx::CEngine::SetBackground(const std::string& name, Gfx::Color up, Gfx::Color down,
Gfx::Color cloudUp, Gfx::Color cloudDown,
bool full, bool quarter)
bool full, Math::Point scale)
{
if (m_backgroundFullTex.Valid())
if (m_backgroundTex.Valid())
{
DeleteTexture(m_backgroundFullTex);
m_backgroundFullTex.SetInvalid();
}
for (int i = 0; i < 4; i++)
{
DeleteTexture(m_backgroundQuarterTexs[i]);
m_backgroundQuarterTexs[i].SetInvalid();
DeleteTexture(m_backgroundTex);
m_backgroundTex.SetInvalid();
}
m_backgroundName = name;
@ -2495,28 +2428,15 @@ void Gfx::CEngine::SetBackground(const std::string& name, Gfx::Color up, Gfx::Co
m_backgroundCloudUp = cloudUp;
m_backgroundCloudDown = cloudDown;
m_backgroundFull = full;
m_backgroundQuarter = quarter;
m_backgroundScale = scale;
if (! m_backgroundName.empty())
{
if (m_backgroundQuarter)
{
for (int i = 0; i < 4; i++)
{
m_backgroundQuarterNames[i] = QuarterName(name, i);
m_backgroundQuarterTexs[i] = LoadTexture(m_backgroundQuarterNames[i]);
}
}
else
{
m_backgroundFullTex = LoadTexture(m_backgroundName);
}
}
m_backgroundTex = LoadTexture(m_backgroundName);
}
void Gfx::CEngine::GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down,
Gfx::Color& cloudUp, Gfx::Color& cloudDown,
bool &full, bool &quarter)
bool &full, Math::Point& scale)
{
name = m_backgroundName;
up = m_backgroundColorUp;
@ -2524,7 +2444,7 @@ void Gfx::CEngine::GetBackground(std::string& name, Gfx::Color& up, Gfx::Color&
cloudUp = m_backgroundCloudUp;
cloudDown = m_backgroundCloudDown;
full = m_backgroundFull;
quarter = m_backgroundQuarter;
scale = m_backgroundScale;
}
void Gfx::CEngine::SetForegroundName(const std::string& name)
@ -2726,16 +2646,6 @@ int Gfx::CEngine::GetEditIndentValue()
return m_editIndentValue;
}
void Gfx::CEngine::SetSpeed(float speed)
{
m_speed = speed;
}
float Gfx::CEngine::GetSpeed()
{
return m_speed;
}
void Gfx::CEngine::SetTracePrecision(float factor)
{
m_tracePrecision = factor;
@ -3144,7 +3054,7 @@ void Gfx::CEngine::DrawInterface()
m_device->SetTransform(Gfx::TRANSFORM_WORLD, m_matWorldInterface);
// Draw the entire interface
CInterface* interface = static_cast<CInterface*>( m_iMan->SearchInstance(CLASS_INTERFACE) );
Ui::CInterface* interface = static_cast<Ui::CInterface*>( m_iMan->SearchInstance(CLASS_INTERFACE) );
if (interface != nullptr)
interface->Draw();
@ -3505,10 +3415,16 @@ void Gfx::CEngine::DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color
AddStatisticTriangle(2);
}
// Status: PART_TESTED
void Gfx::CEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, const Gfx::Texture &tex)
// Status: TESTED, VERIFIED
void Gfx::CEngine::DrawBackgroundImage()
{
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
Math::Point p1, p2;
p1.x = 0.0f;
p1.y = 0.0f;
p2.x = 1.0f;
p2.y = 1.0f;
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal
float u1, u2, v1, v2;
if (m_backgroundFull)
@ -3517,14 +3433,6 @@ void Gfx::CEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, co
v1 = 0.0f;
u2 = 1.0f;
v2 = 1.0f;
if (m_backgroundQuarter)
{
u1 += 0.5f/512.0f;
v1 += 0.5f/384.0f;
u2 -= 0.5f/512.0f;
v2 -= 0.5f/384.0f;
}
}
else
{
@ -3541,7 +3449,10 @@ void Gfx::CEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, co
v2 = v1+h;
}
SetTexture(tex);
u2 *= m_backgroundScale.x;
v2 *= m_backgroundScale.y;
SetTexture(m_backgroundTex);
SetState(Gfx::ENG_RSTATE_OPAQUE_TEXTURE | Gfx::ENG_RSTATE_WRAP);
m_device->SetTransform(Gfx::TRANSFORM_VIEW, m_matViewInterface);
@ -3560,48 +3471,6 @@ void Gfx::CEngine::DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, co
AddStatisticTriangle(2);
}
// Status: TESTED, VERIFIED
void Gfx::CEngine::DrawBackgroundImage()
{
Math::Point p1, p2;
std::string name;
if (m_backgroundQuarter)
{
p1.x = 0.0f;
p1.y = 0.5f;
p2.x = 0.5f;
p2.y = 1.0f;
DrawBackgroundImageQuarter(p1, p2, m_backgroundQuarterTexs[0]);
p1.x = 0.5f;
p1.y = 0.5f;
p2.x = 1.0f;
p2.y = 1.0f;
DrawBackgroundImageQuarter(p1, p2, m_backgroundQuarterTexs[1]);
p1.x = 0.0f;
p1.y = 0.0f;
p2.x = 0.5f;
p2.y = 0.5f;
DrawBackgroundImageQuarter(p1, p2, m_backgroundQuarterTexs[2]);
p1.x = 0.5f;
p1.y = 0.0f;
p2.x = 1.0f;
p2.y = 0.5f;
DrawBackgroundImageQuarter(p1, p2, m_backgroundQuarterTexs[3]);
}
else
{
p1.x = 0.0f;
p1.y = 0.0f;
p2.x = 1.0f;
p2.y = 1.0f;
DrawBackgroundImageQuarter(p1, p2, m_backgroundFullTex);
}
}
void Gfx::CEngine::DrawPlanet()
{
if (! m_planet->PlanetExist()) return;
@ -3854,6 +3723,8 @@ void Gfx::CEngine::DrawMouseSprite(Math::Point pos, Math::Point size, int icon)
Gfx::Vertex(Math::Vector(p2.x, p2.y, 0.0f), normal, Math::Point(u2, v1))
};
m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_TEST, false);
m_device->SetRenderState(Gfx::RENDER_STATE_DEPTH_WRITE, false);
m_device->DrawPrimitive(Gfx::PRIMITIVE_TRIANGLE_STRIP, vertex, 4);
AddStatisticTriangle(2);
}

View File

@ -664,9 +664,7 @@ public:
bool ProcessEvent(const Event& event);
//! Called once per frame, the call is the entry point for animating the scene
void FrameMove(float rTime);
//! Evolved throughout the game
void StepSimulation(float rTime);
void FrameUpdate();
//! Writes a screenshot containing the current frame
@ -993,10 +991,10 @@ public:
//! Management of the background image to use
void SetBackground(const std::string& name, Gfx::Color up = Gfx::Color(), Gfx::Color down = Gfx::Color(),
Gfx::Color cloudUp = Gfx::Color(), Gfx::Color cloudDown = Gfx::Color(),
bool full = false, bool quarter = false);
bool full = false, Math::Point scale = Math::Point(1.0f, 1.0f));
void GetBackground(std::string& name, Gfx::Color& up, Gfx::Color& down,
Gfx::Color& cloudUp, Gfx::Color& cloudDown,
bool& full, bool& quarter);
bool& full, Math::Point& scale);
//@}
//! Specifies the name of foreground texture
@ -1098,11 +1096,6 @@ public:
int GetEditIndentValue();
//@}
//@{
//! Management of game speed
void SetSpeed(float speed);
float GetSpeed();
//@{
//! Management of precision of robot tracks
void SetTracePrecision(float factor);
@ -1161,8 +1154,6 @@ protected:
void DrawBackground();
//! Draws the gradient background
void DrawBackgroundGradient(const Gfx::Color& up, const Gfx::Color& down);
//! Draws a portion of the image background
void DrawBackgroundImageQuarter(Math::Point p1, Math::Point p2, const Gfx::Texture &tex);
//! Draws the image background
void DrawBackgroundImage();
//! Draws all the planets
@ -1297,11 +1288,9 @@ protected:
bool m_firstGroundSpot;
int m_secondTexNum;
bool m_backgroundFull;
bool m_backgroundQuarter;
Math::Point m_backgroundScale;
std::string m_backgroundName;
std::string m_backgroundQuarterNames[4];
Gfx::Texture m_backgroundFullTex;
Gfx::Texture m_backgroundQuarterTexs[4];
Gfx::Texture m_backgroundTex;
Gfx::Color m_backgroundColorUp;
Gfx::Color m_backgroundColorDown;
Gfx::Color m_backgroundCloudUp;

View File

@ -22,7 +22,7 @@
#pragma once
#include "common/misc.h"
#include "common/event.h"
#include "math/vector.h"

View File

@ -200,7 +200,7 @@ void Gfx::CParticle::DrawParticle(int sheet)
// TODO!
}
bool Gfx::CParticle::WriteWheelTrace(char *filename, int width, int height, Math::Vector dl, Math::Vector ur)
bool Gfx::CParticle::WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur)
{
GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n");
// TODO!

View File

@ -306,7 +306,7 @@ public:
void FrameParticle(float rTime);
void DrawParticle(int sheet);
bool WriteWheelTrace(char *filename, int width, int height, Math::Vector dl, Math::Vector ur);
bool WriteWheelTrace(const char *filename, int width, int height, Math::Vector dl, Math::Vector ur);
protected:
void DeleteRank(int rank);

View File

@ -22,7 +22,8 @@
#pragma once
#include "common/misc.h"
#include "common/event.h"
#include "common/global.h"
#include "graphics/engine/engine.h"
#include "object/object.h"

View File

@ -785,18 +785,20 @@ Gfx::CharTexture Gfx::CText::CreateCharTexture(Gfx::UTF8Char ch, Gfx::CachedFont
data.surface = nullptr;
SDL_FreeSurface(textSurface);
SDL_FreeSurface(textureSurface);
if (! tex.Valid())
{
m_error = "Texture create error";
return texture;
}
else
{
texture.id = tex.id;
texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h));
texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h));
}
texture.id = tex.id;
texture.texSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textureSurface->w, textureSurface->h));
texture.charSize = m_engine->WindowToInterfaceSize(Math::IntPoint(textSurface->w, textSurface->h));
SDL_FreeSurface(textSurface);
SDL_FreeSurface(textureSurface);
return texture;
}

View File

@ -129,9 +129,11 @@ bool Gfx::CGLDevice::Create()
glViewport(0, 0, m_config.size.x, m_config.size.y);
int numLights = 0;
glGetIntegerv(GL_MAX_LIGHTS, &numLights);
m_lights = std::vector<Gfx::Light>(GL_MAX_LIGHTS, Gfx::Light());
m_lightsEnabled = std::vector<bool> (GL_MAX_LIGHTS, false);
m_lights = std::vector<Gfx::Light>(numLights, Gfx::Light());
m_lightsEnabled = std::vector<bool> (numLights, false);
int maxTextures = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures);
@ -182,7 +184,6 @@ void Gfx::CGLDevice::BeginScene()
void Gfx::CGLDevice::EndScene()
{
glFlush();
}
void Gfx::CGLDevice::Clear()
@ -434,7 +435,10 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr
else
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
bool convert = false;
GLenum sourceFormat = 0;
if (params.format == Gfx::TEX_IMG_RGB)
{
sourceFormat = GL_RGB;
@ -459,26 +463,26 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr
{
if (data->surface->format->Amask != 0)
{
if ((data->surface->format->Rmask == 0xFF000000) &&
(data->surface->format->Gmask == 0x00FF0000) &&
(data->surface->format->Bmask == 0x0000FF00) &&
(data->surface->format->Amask == 0x000000FF))
if ((data->surface->format->Amask == 0xFF000000) &&
(data->surface->format->Rmask == 0x00FF0000) &&
(data->surface->format->Gmask == 0x0000FF00) &&
(data->surface->format->Bmask == 0x000000FF))
{
sourceFormat = GL_BGRA;
result.alpha = true;
}
else if ((data->surface->format->Bmask == 0xFF000000) &&
(data->surface->format->Gmask == 0x00FF0000) &&
(data->surface->format->Rmask == 0x0000FF00) &&
(data->surface->format->Amask == 0x000000FF))
else if ((data->surface->format->Amask == 0xFF000000) &&
(data->surface->format->Bmask == 0x00FF0000) &&
(data->surface->format->Gmask == 0x0000FF00) &&
(data->surface->format->Rmask == 0x000000FF))
{
sourceFormat = GL_RGBA;
result.alpha = true;
}
else
{
GetLogger()->Error("Auto texture format failed\n");
return Gfx::Texture(); // other format?
sourceFormat = GL_RGBA;
convert = true;
}
}
else
@ -499,16 +503,43 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr
}
else
{
GetLogger()->Error("Auto texture format failed\n");
return Gfx::Texture(); // other format?
sourceFormat = GL_RGBA;
convert = true;
}
}
}
else
assert(false);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h,
0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels);
SDL_Surface* actualSurface = data->surface;
SDL_Surface* convertedSurface = nullptr;
if (convert)
{
SDL_PixelFormat format;
format.BytesPerPixel = 4;
format.BitsPerPixel = 32;
format.alpha = 0;
format.colorkey = 0;
format.Aloss = format.Bloss = format.Gloss = format.Rloss = 0;
format.Amask = 0xFF000000;
format.Ashift = 24;
format.Bmask = 0x00FF0000;
format.Bshift = 16;
format.Gmask = 0x0000FF00;
format.Gshift = 8;
format.Rmask = 0x000000FF;
format.Rshift = 0;
format.palette = nullptr;
convertedSurface = SDL_ConvertSurface(data->surface, &format, SDL_SWSURFACE);
if (convertedSurface != nullptr)
actualSurface = convertedSurface;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, actualSurface->w, actualSurface->h,
0, sourceFormat, GL_UNSIGNED_BYTE, actualSurface->pixels);
SDL_FreeSurface(convertedSurface);
// Restore the previous state of 1st stage

View File

@ -27,5 +27,3 @@
#include "vector.h"
#include "matrix.h"
#include "geometry.h"
#include "conv.h"

View File

@ -51,4 +51,3 @@ const float RAD_TO_DEG = 57.29577951308232286465f;
const float LOG_2 = log(2.0f);
}; // namespace Math

View File

@ -1,39 +0,0 @@
/* math/conv.h
Temporary conversion functions for D3DVECTOR and D3DMATRIX */
#pragma once
#include <d3d.h>
#include "vector.h"
#include "matrix.h"
inline D3DVECTOR VEC_TO_D3DVEC(Math::Vector vec)
{
return D3DVECTOR(vec.x, vec.y, vec.z);
}
inline Math::Vector D3DVEC_TO_VEC(D3DVECTOR vec)
{
return Math::Vector(vec.x, vec.y, vec.z);
}
inline D3DMATRIX MAT_TO_D3DMAT(Math::Matrix mat)
{
D3DMATRIX result;
mat.Transpose();
for (int r = 0; r < 4; ++r)
{
for (int c = 0; c < 16; ++c)
result.m[r][c] = mat.m[4*c+r];
}
return result;
}
inline Math::Matrix D3DMAT_TO_MAT(D3DMATRIX mat)
{
Math::Matrix result(mat.m);
result.Transpose();
return result;
}

View File

@ -76,9 +76,11 @@ inline bool IsInsideTriangle(Math::Point a, Math::Point b, Math::Point c, Math::
}
//! Rotates a point around a center
/** \a center center of rotation
\a angle angle is in radians (positive is counterclockwise (CCW) )
\a p the point */
/**
* \param center center of rotation
* \param angle angle [radians] (positive is CCW)
* \param p the point to be rotated
*/
inline Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
{
Math::Point a;
@ -96,8 +98,10 @@ inline Math::Point RotatePoint(const Math::Point &center, float angle, const Mat
}
//! Rotates a point around the origin (0,0)
/** \a angle angle in radians (positive is counterclockwise (CCW) )
\a p the point */
/**
* \param angle angle [radians] (positive is CCW)
* \param p the point to be rotated
*/
inline Math::Point RotatePoint(float angle, const Math::Point &p)
{
float x = p.x*cosf(angle) - p.y*sinf(angle);
@ -106,9 +110,11 @@ inline Math::Point RotatePoint(float angle, const Math::Point &p)
return Math::Point(x, y);
}
//! Rotates a vector (dist, 0).
/** \a angle angle is in radians (positive is counterclockwise (CCW) )
\a dist distance to origin */
//! Rotates a vector (dist, 0)
/**
* \param angle angle [radians] (positive is CCW)
* \param dist distance to origin
*/
inline Math::Point RotatePoint(float angle, float dist)
{
float x = dist*cosf(angle);
@ -117,7 +123,12 @@ inline Math::Point RotatePoint(float angle, float dist)
return Math::Point(x, y);
}
//! TODO documentation
//! Rotates a point around a center on 2D plane
/**
* \param cx,cy center of rotation
* \param angle angle of rotation [radians] (positive is CCW)
* \param px,py point coordinates to rotate
*/
inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
{
float ax, ay;
@ -132,11 +143,14 @@ inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
py = cy+ay;
}
//! Rotates a point around a center in space.
/** \a center center of rotation
\a angleH,angleV rotation angles in radians (positive is counterclockwise (CCW) ) )
\a p the point
\returns the rotated point */
//! Rotates a point around a center in space
/**
* \a angleH is rotation along Y axis (heading) while \a angleV is rotation along X axis (TODO: ?).
*
* \param center center of rotation
* \param angleH,angleV rotation angles [radians] (positive is CCW)
* \param p the point to be rotated
*/
inline void RotatePoint(const Math::Vector &center, float angleH, float angleV, Math::Vector &p)
{
p.x -= center.x;
@ -151,11 +165,14 @@ inline void RotatePoint(const Math::Vector &center, float angleH, float angleV,
p = center + b;
}
//! Rotates a point around a center in space.
/** \a center center of rotation
\a angleH,angleV rotation angles in radians (positive is counterclockwise (CCW) ) )
\a p the point
\returns the rotated point */
//! Rotates a point around a center in space
/**
* The rotation is performed first along Y axis (\a angleH) and then along X axis (\a angleV).
*
* \param center center of rotation
* \param angleH,angleV rotation angles [radians] (positive is CCW)
* \param p the point to be rotated
*/
inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
{
p.x -= center.x;
@ -189,10 +206,12 @@ inline float RotateAngle(float x, float y)
return -atan + 0.5f*PI;
}
//! Calculates the angle between two points and one center
/** \a center the center point
\a p1,p2 the two points
\returns The angle in radians (positive is counterclockwise (CCW) ) */
//! Calculates the angle between two points and a center
/**
* \param center the center point
* \param p1,p2 the two points
* \returns the angle [radians] (positive is CCW)
*/
inline float RotateAngle(const Math::Point &center, const Math::Point &p1, const Math::Point &p2)
{
if (PointsEqual(p1, center))
@ -215,9 +234,11 @@ inline float RotateAngle(const Math::Point &center, const Math::Point &p1, const
}
//! Loads view matrix from the given vectors
/** \a from origin
\a at view direction
\a worldUp up vector */
/**
* \param from origin
* \param at view direction
* \param worldUp up vector
*/
inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
const Math::Vector &at, const Math::Vector &worldUp)
{
@ -280,10 +301,12 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
}
//! Loads a perspective projection matrix
/** \a fov field of view in radians
\a aspect aspect ratio (width / height)
\a nearPlane distance to near cut plane
\a farPlane distance to far cut plane */
/**
* \param fov field of view in radians
* \param aspect aspect ratio (width / height)
* \param nearPlane distance to near cut plane
* \param farPlane distance to far cut plane
*/
inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f, float aspect = 1.0f,
float nearPlane = 1.0f, float farPlane = 1000.0f)
{
@ -302,9 +325,11 @@ inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f,
}
//! Loads an othogonal projection matrix
/** \a left,right coordinates for left and right vertical clipping planes
\a bottom,top coordinates for bottom and top horizontal clipping planes
\a zNear,zFar distance to nearer and farther depth clipping planes */
/**
* \param left,right coordinates for left and right vertical clipping planes
* \param bottom,top coordinates for bottom and top horizontal clipping planes
* \param zNear,zFar distance to nearer and farther depth clipping planes
*/
inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top,
float zNear = -1.0f, float zFar = 1.0f)
{
@ -320,7 +345,10 @@ inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right
}
//! Loads a translation matrix from given vector
/** \a trans vector of translation*/
/**
* \param mat result matrix
* \param trans vector of translation
*/
inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
{
mat.LoadIdentity();
@ -330,7 +358,10 @@ inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
}
//! Loads a scaling matrix fom given vector
/** \a scale vector with scaling factors for X, Y, Z */
/**
* \param mat result matrix
* \param scale vector with scaling factors for X, Y, Z
*/
inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
{
mat.LoadIdentity();
@ -340,7 +371,10 @@ inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
}
//! Loads a rotation matrix along the X axis
/** \a angle angle in radians */
/**
* \param mat result matrix
* \param angle angle [radians]
*/
inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
{
mat.LoadIdentity();
@ -351,7 +385,10 @@ inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
}
//! Loads a rotation matrix along the Y axis
/** \a angle angle in radians */
/**
* \param mat result matrix
* \param angle angle [radians]
*/
inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
{
mat.LoadIdentity();
@ -362,7 +399,10 @@ inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
}
//! Loads a rotation matrix along the Z axis
/** \a angle angle in radians */
/**
* \param mat result matrix
* \param angle angle [radians]
*/
inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
{
mat.LoadIdentity();
@ -373,8 +413,11 @@ inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
}
//! Loads a rotation matrix along the given axis
/** \a dir axis of rotation
\a angle angle in radians */
/**
* \param mat result matrix
* \param dir axis of rotation
* \param angle angle [radians]
*/
inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
{
float cos = cosf(angle);
@ -397,28 +440,28 @@ inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float
}
//! Calculates the matrix to make three rotations in the order X, Z and Y
inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angle)
inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles)
{
Math::Matrix temp;
LoadRotationXMatrix(temp, angle.x);
LoadRotationXMatrix(temp, angles.x);
LoadRotationZMatrix(mat, angle.z);
LoadRotationZMatrix(mat, angles.z);
mat = Math::MultiplyMatrices(temp, mat);
LoadRotationYMatrix(temp, angle.y);
LoadRotationYMatrix(temp, angles.y);
mat = Math::MultiplyMatrices(temp, mat);
}
//! Calculates the matrix to make three rotations in the order Z, X and Y
inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angle)
inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles)
{
Math::Matrix temp;
LoadRotationZMatrix(temp, angle.z);
LoadRotationZMatrix(temp, angles.z);
LoadRotationXMatrix(mat, angle.x);
LoadRotationXMatrix(mat, angles.x);
mat = Math::MultiplyMatrices(temp, mat);
LoadRotationYMatrix(temp, angle.y);
LoadRotationYMatrix(temp, angles.y);
mat = Math::MultiplyMatrices(temp, mat);
}
@ -430,7 +473,9 @@ inline float DistanceProjected(const Math::Vector &a, const Math::Vector &b)
}
//! Returns the normal vector to a plane
/** \param p1,p2,p3 points defining the plane */
/**
* \param p1,p2,p3 points defining the plane
*/
inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3)
{
Math::Vector u = p3 - p1;
@ -440,16 +485,20 @@ inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2
}
//! Returns a point on the line \a p1 - \a p2, in \a dist distance from \a p1
/** \a p1,p2 line start and end
\a dist scaling factor from \a p1, relative to distance between \a p1 and \a p2 */
/**
* \param p1,p2 line start and end
* \param dist scaling factor from \a p1, relative to distance between \a p1 and \a p2
*/
inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
{
return p1 + (p2 - p1) * dist;
}
//! Returns the distance between given point and a plane
/** \param p the point
\param a,b,c points defining the plane */
/**
* \param p the point
* \param a,b,c points defining the plane
*/
inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b,
const Math::Vector &c, const Math::Vector &p)
{
@ -460,8 +509,10 @@ inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b,
}
//! Checks if two planes defined by three points are the same
/** \a plane1 array of three vectors defining the first plane
\a plane2 array of three vectors defining the second plane */
/**
* \param plane1 array of three vectors defining the first plane
* \param plane2 array of three vectors defining the second plane
*/
inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&plane2)[3])
{
Math::Vector n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]);
@ -479,7 +530,7 @@ inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&pl
return true;
}
//! Calculates the intersection "i" right "of" the plane "abc".
//! Calculates the intersection "i" right "of" the plane "abc" (TODO: ?)
inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c,
const Math::Vector &d, const Math::Vector &e, Math::Vector &i)
{
@ -502,7 +553,7 @@ inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::
}
//! Calculates the intersection of the straight line passing through p (x, z)
/** Line is parallel to the y axis, with the plane abc. Returns p.y. */
/** Line is parallel to the y axis, with the plane abc. Returns p.y. (TODO: ?) */
inline bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, Math::Vector &p)
{
float d = (b.x-a.x)*(c.z-a.z) - (c.x-a.x)*(b.z-a.z);
@ -528,15 +579,18 @@ inline Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float ang
return lookat;
}
//! TODO documentation
//! Transforms the point \a p by matrix \a m
/** Is equal to multiplying the matrix by the vector (of course without perspective divide). */
inline Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p)
{
return MatrixVectorMultiply(m, p);
}
//! Calculates the projection of the point \a p on a straight line \a a to \a b.
/** \a p point to project
\a a,b two ends of the line */
//! Calculates the projection of the point \a p on a straight line \a a to \a b
/**
* \param point to project
* \param a,b two ends of the line
*/
inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p)
{
float k = DotProduct(b - a, p - a);

View File

@ -33,13 +33,14 @@
namespace Math
{
/** \struct Matrix math/matrix.h
\brief 4x4 matrix
Represents an universal 4x4 matrix that can be used in OpenGL and DirectX engines.
Contains the required methods for operating on matrices (inverting, multiplying, etc.).
The internal representation is a 16-value table in column-major order, thus:
/**
* \struct Matrix math/matrix.h
* \brief 4x4 matrix
*
* Represents an universal 4x4 matrix that can be used in OpenGL and DirectX engines.
* Contains the required methods for operating on matrices (inverting, multiplying, etc.).
*
* The internal representation is a 16-value table in column-major order, thus:
\verbatim
m[0 ] m[4 ] m[8 ] m[12]
@ -48,16 +49,16 @@ m[2 ] m[6 ] m[10] m[14]
m[3 ] m[7 ] m[11] m[15]
\endverbatim
This representation is native to OpenGL; DirectX requires transposing the matrix.
The order of multiplication of matrix and vector is also OpenGL-native
(see the function MatrixVectorMultiply).
All methods are made inline to maximize optimization.
Unit tests for the structure and related functions are in module: math/test/matrix_test.cpp.
**/
* This representation is native to OpenGL; DirectX requires transposing the matrix.
*
* The order of multiplication of matrix and vector is also OpenGL-native
* (see the function MatrixVectorMultiply).
*
* All methods are made inline to maximize optimization.
*
* Unit tests for the structure and related functions are in module: math/test/matrix_test.cpp.
*
*/
struct Matrix
{
//! Matrix values in column-major order
@ -78,8 +79,10 @@ struct Matrix
}
//! Creates the matrix from 2D array
/** The array's first index is row, second is column.
\a m array with values */
/**
* The array's first index is row, second is column.
* \param m array with values
*/
inline explicit Matrix(const float (&m)[4][4])
{
for (int c = 0; c < 4; ++c)
@ -91,11 +94,23 @@ struct Matrix
}
}
//! Sets value in given row and col
/**
* \param row row (0 to 3)
* \param col column (0 to 3)
* \param value value
*/
inline void Set(int row, int col, float value)
{
m[(col-1)*4+(row-1)] = value;
}
//! Returns the value in given row and col
/**
* \param row row (0 to 3)
* \param col column (0 to 3)
* \returns value
*/
inline float Get(int row, int col)
{
return m[(col-1)*4+(row-1)];
@ -148,9 +163,11 @@ struct Matrix
}
//! Calculates the cofactor of the matrix
/** \a r row (0 to 3)
\a c column (0 to 3)
\returns the cofactor */
/**
* \param r row (0 to 3)
* \param c column (0 to 3)
* \returns the cofactor
*/
inline float Cofactor(int r, int c) const
{
assert(r >= 0 && r <= 3);
@ -330,8 +347,10 @@ struct Matrix
}
//! Calculates the inverse matrix
/** The determinant of the matrix must not be zero.
\returns the inverted matrix */
/**
* The determinant of the matrix must not be zero.
* \returns the inverted matrix
*/
inline Matrix Inverse() const
{
float d = Det();
@ -352,8 +371,10 @@ struct Matrix
}
//! Calculates the multiplication of this matrix * given matrix
/** \a right right-hand matrix
\returns multiplication result */
/**
* \param right right-hand matrix
* \returns multiplication result
*/
inline Matrix Multiply(const Matrix &right) const
{
float result[16] = { 0.0f };

View File

@ -32,14 +32,14 @@
namespace Math
{
/** \struct Point math/point.h
\brief 2D point
Represents a 2D point (x, y).
Contains the required methods for operating on points.
All methods are made inline to maximize optimization.
/**
* \struct Point
* \brief 2D point
*
* Represents a 2D point (x, y).
* Contains the required methods for operating on points.
*
* All methods are made inline to maximize optimization.
*/
struct Point
{

View File

@ -1,33 +1,23 @@
cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE debug)
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
add_executable(matrix_test matrix_test.cpp)
add_executable(vector_test vector_test.cpp)
add_executable(geometry_test geometry_test.cpp ../old/math3d.cpp ../old/d3dmath.cpp ../../graphics/d3d/d3dutil.cpp)
enable_testing()
add_test(matrix_test ./matrix_test)
add_test(vector_test ./vector_test)
add_test(geometry_test ./geometry_test)
# Change to DirectX SDK directory
include_directories("c:/dxsdk/include")
add_definitions(-DSTRICT -DD3D_OVERLOADS)
# 'make check' will compile the required test programs
# Note that 'make test' will still fail without compiled programs
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS matrix_test vector_test)
# Files to be removed in distclean
set(REMOVE_FILES
CMakeFiles Testing cmake_install.cmake CMakeCache.txt CTestTestfile.cmake Makefile
./matrix_test
./vector_test
./geometry_test
include_directories(
.
../../..
${GTEST_DIR}/include
)
add_custom_target(distclean COMMAND rm -rf ${REMOVE_FILES})
add_executable(matrix_test matrix_test.cpp)
target_link_libraries(matrix_test gtest)
add_executable(vector_test vector_test.cpp)
target_link_libraries(vector_test gtest)
add_executable(geometry_test geometry_test.cpp)
target_link_libraries(geometry_test gtest)
add_test(matrix_test matrix_test)
add_test(vector_test vector_test)
add_test(geometry_test geometry_test)

View File

@ -20,53 +20,41 @@
#include "../func.h"
#include "../geometry.h"
#include "../conv.h"
#include "../../old/math3d.h"
#include "../../old/d3dutil.h"
#include <d3d.h>
#include <cstdio>
#include "gtest/gtest.h"
using namespace std;
const float TEST_TOLERANCE = 1e-5;
// Test for rewritten function RotateAngle()
int TestRotateAngle()
TEST(GeometryTest, RotateAngleTest)
{
if (! Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE))
return __LINE__;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE));
if (! Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE))
return __LINE__;
return 0;
EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE));
}
// Tests for other altered, complex or uncertain functions
/*
TODO: write meaningful tests with proper test values
int TestAngle()
{
const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805);
@ -360,42 +348,12 @@ int TestTransform()
return 0;
}
int main()
*/
int main(int argc, char* argv[])
{
// Functions to test
int (*TESTS[])() =
{
TestRotateAngle,
TestAngle,
TestRotateView,
TestLookatPoint,
TestProjection,
TestLoadViewMatrix,
TestLoadProjectionMatrix,
TestLoadTranslationMatrix,
TestLoadScaleMatrix,
TestLoadRotationXMatrix,
TestLoadRotationYMatrix,
TestLoadRotationZMatrix,
TestLoadRotationMatrix,
TestLoadRotationXZYMatrix,
TestLoadRotationZXYMatrix,
TestTransform
};
const int TESTS_SIZE = sizeof(TESTS) / sizeof(*TESTS);
::testing::InitGoogleTest(&argc, argv);
int result = 0;
for (int i = 0; i < TESTS_SIZE; ++i)
{
result = TESTS[i]();
if (result != 0)
{
fprintf(stderr, "Test function %d failed at line %d\n", i+1, result);
return result;
}
}
fprintf(stderr, "All tests successful\n");
return 0;
return RUN_ALL_TESTS();
}

View File

@ -26,13 +26,13 @@
#include "../func.h"
#include "../matrix.h"
#include <cstdio>
#include "gtest/gtest.h"
using namespace std;
const float TEST_TOLERANCE = 1e-6;
int TestTranspose()
TEST(MatrixTest, TransposeTest)
{
const Math::Matrix mat(
(float[4][4])
@ -56,16 +56,10 @@ int TestTranspose()
Math::Matrix transpose = Math::Transpose(mat);
if (! Math::MatricesEqual(transpose, expectedTranspose, TEST_TOLERANCE))
{
fprintf(stderr, "Transpose mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::MatricesEqual(transpose, expectedTranspose, TEST_TOLERANCE));
}
int TestCofactor()
TEST(MatrixTest, CofactorTest)
{
const Math::Matrix mat1(
(float[4][4])
@ -93,12 +87,7 @@ int TestCofactor()
{
float ret = mat1.Cofactor(r, c);
float exp = expectedCofactors1.m[4*c+r];
if (! Math::IsEqual(ret, exp, TEST_TOLERANCE))
{
fprintf(stderr, "Cofactors 1 mismatch!\n");
fprintf(stderr, "r=%d, c=%d, %f (returned) != %f (expected)\n", r, c, ret, exp);
return __LINE__;
}
EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE));
}
}
@ -129,19 +118,12 @@ int TestCofactor()
{
float ret = mat2.Cofactor(r, c);
float exp = expectedCofactors2.m[4*c+r];
if (! Math::IsEqual(ret, exp, TEST_TOLERANCE))
{
fprintf(stderr, "Cofactors 2 mismatch!\n");
fprintf(stderr, "r=%d, c=%d, %f (returned) != %f (expected)\n", r, c, ret, exp);
return __LINE__;
}
EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE));
}
}
return 0;
}
int TestDet()
TEST(MatrixTest, DetTest)
{
const Math::Matrix mat1(
(float[4][4])
@ -156,12 +138,7 @@ int TestDet()
const float expectedDet1 = 4.07415413729671;
float ret1 = mat1.Det();
if (! Math::IsEqual(ret1, expectedDet1, TEST_TOLERANCE))
{
fprintf(stderr, "Det mismatch!\n");
fprintf(stderr, "%f (returned) != %f (expected)\n", ret1, expectedDet1);
return __LINE__;
}
EXPECT_TRUE(Math::IsEqual(ret1, expectedDet1, TEST_TOLERANCE));
const Math::Matrix mat2(
(float[4][4])
@ -176,17 +153,10 @@ int TestDet()
const float expectedDet2 = -6.35122307880942;
float ret2 = mat2.Det();
if (! Math::IsEqual(ret2, expectedDet2, TEST_TOLERANCE))
{
fprintf(stderr, "Det mismatch!\n");
fprintf(stderr, "%f (returned) != %f (expected)\n", ret2, expectedDet2);
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::IsEqual(ret2, expectedDet2, TEST_TOLERANCE));
}
int TestInverse()
TEST(MatrixTest, InverseTest)
{
const Math::Matrix mat1(
(float[4][4])
@ -210,11 +180,7 @@ int TestInverse()
Math::Matrix inverse1 = mat1.Inverse();
if (! Math::MatricesEqual(inverse1, expectedInverse1, TEST_TOLERANCE))
{
fprintf(stderr, "Inverse 1 mismatch!\n");
return __LINE__;
}
EXPECT_TRUE(Math::MatricesEqual(inverse1, expectedInverse1, TEST_TOLERANCE));
const Math::Matrix mat2(
(float[4][4])
@ -238,16 +204,10 @@ int TestInverse()
Math::Matrix inverse2 = mat2.Inverse();
if (! Math::MatricesEqual(inverse2, expectedInverse2, TEST_TOLERANCE))
{
fprintf(stderr, "Inverse 2 mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::MatricesEqual(inverse2, expectedInverse2, TEST_TOLERANCE));
}
int TestMultiply()
TEST(MatrixTest, MultiplyTest)
{
const Math::Matrix mat1A(
(float[4][4])
@ -280,11 +240,7 @@ int TestMultiply()
);
Math::Matrix multiply1 = Math::MultiplyMatrices(mat1A, mat1B);
if (! Math::MatricesEqual(multiply1, expectedMultiply1, TEST_TOLERANCE ) )
{
fprintf(stderr, "Multiply 1 mismath!\n");
return __LINE__;
}
EXPECT_TRUE(Math::MatricesEqual(multiply1, expectedMultiply1, TEST_TOLERANCE));
const Math::Matrix mat2A(
(float[4][4])
@ -317,16 +273,10 @@ int TestMultiply()
);
Math::Matrix multiply2 = Math::MultiplyMatrices(mat2A, mat2B);
if (! Math::MatricesEqual(multiply2, expectedMultiply2, TEST_TOLERANCE ) )
{
fprintf(stderr, "Multiply 2 mismath!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::MatricesEqual(multiply2, expectedMultiply2, TEST_TOLERANCE));
}
int TestMultiplyVector()
TEST(MatrixTest, MultiplyVectorTest)
{
const Math::Matrix mat1(
(float[4][4])
@ -343,11 +293,7 @@ int TestMultiplyVector()
const Math::Vector expectedMultiply1(0.608932463260470, -1.356893266403749, 3.457156276255142);
Math::Vector multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false);
if (! Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE ) )
{
fprintf(stderr, "Multiply vector 1 mismath!\n");
return __LINE__;
}
EXPECT_TRUE(Math::VectorsEqual(multiply1, expectedMultiply1, TEST_TOLERANCE));
const Math::Matrix mat2(
(float[4][4])
@ -364,39 +310,13 @@ int TestMultiplyVector()
const Math::Vector expectedMultiply2(0.2816820577317669, 0.0334468811767428, 0.1996974284970455);
Math::Vector multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true);
if (! Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE ) )
{
fprintf(stderr, "Multiply vector 2 mismath!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::VectorsEqual(multiply2, expectedMultiply2, TEST_TOLERANCE));
}
int main()
int main(int argc, char* argv[])
{
// Functions to test
int (*TESTS[])() =
{
TestTranspose,
TestCofactor,
TestDet,
TestInverse,
TestMultiply,
TestMultiplyVector
};
const int TESTS_SIZE = sizeof(TESTS) / sizeof(*TESTS);
::testing::InitGoogleTest(&argc, argv);
int result = 0;
for (int i = 0; i < TESTS_SIZE; ++i)
{
result = TESTS[i]();
if (result != 0)
return result;
}
fprintf(stderr, "All tests successful\n");
return 0;
return RUN_ALL_TESTS();
}

View File

@ -26,59 +26,41 @@
#include "../func.h"
#include "../vector.h"
#include <cstdio>
#include "gtest/gtest.h"
using namespace std;
const float TEST_TOLERANCE = 1e-6;
int TestLength()
TEST(VectorTest, LengthTest)
{
Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957);
const float expectedLength = 1.58938001708428;
if (! Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE) )
{
fprintf(stderr, "Length mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE));
}
int TestNormalize()
TEST(VectorTest, NormalizeTest)
{
Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377);
const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797);
vec.Normalize();
if (! Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE))
{
fprintf(stderr, "Normalize mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE));
}
int TestDot()
TEST(VectorTest, DotTest)
{
Math::Vector vecA(0.8202190530968309, 0.0130926060162780, 0.2411914183883510);
Math::Vector vecB(-0.0524083951404069, 1.5564932716738220, -0.8971342631500536);
float expectedDot = -0.238988896477326;
if (! Math::IsEqual(Math::DotProduct(vecA, vecB), expectedDot, TEST_TOLERANCE) )
{
fprintf(stderr, "Dot product mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::IsEqual(Math::DotProduct(vecA, vecB), expectedDot, TEST_TOLERANCE));
}
int TestCross()
TEST(VectorTest, CrossTest)
{
Math::Vector vecA(1.37380499798567, 1.18054518384682, 1.95166361293121);
Math::Vector vecB(0.891657855926886, 0.447591335394532, -0.901604070087823);
@ -86,42 +68,14 @@ int TestCross()
Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581);
Math::Vector expectedReverseCross = -expectedCross;
if (! Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE) )
{
fprintf(stderr, "Cross product mismatch!\n");
return __LINE__;
}
EXPECT_TRUE(Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE));
if (! Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE) )
{
fprintf(stderr, "Reverse cross product mismatch!\n");
return __LINE__;
}
return 0;
EXPECT_TRUE(Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE));
}
int main()
int main(int argc, char* argv[])
{
// Functions to test
int (*TESTS[])() =
{
TestLength,
TestNormalize,
TestDot,
TestCross
};
const int TESTS_SIZE = sizeof(TESTS) / sizeof(*TESTS);
::testing::InitGoogleTest(&argc, argv);
int result = 0;
for (int i = 0; i < TESTS_SIZE; ++i)
{
result = TESTS[i]();
if (result != 0)
return result;
}
fprintf(stderr, "All tests successful\n");
return 0;
return RUN_ALL_TESTS();
}

View File

@ -32,16 +32,17 @@
namespace Math
{
/** \struct Vector math/vector.h
\brief 3D (3x1) vector
Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines.
Contains the required methods for operating on vectors.
All methods are made inline to maximize optimization.
Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
/**
* \struct Vector
* \brief 3D (3x1) vector
*
* Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines.
* Contains the required methods for operating on vectors.
*
* All methods are made inline to maximize optimization.
*
* Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
*
*/
struct Vector
{
@ -103,8 +104,10 @@ struct Vector
}
//! Calculates the cross product with another vector
/** \a right right-hand side vector
\returns the cross product*/
/**
* \param right right-hand side vector
* \returns the cross product
*/
inline Vector CrossMultiply(const Vector &right) const
{
float px = y * right.z - z * right.y;
@ -114,8 +117,10 @@ struct Vector
}
//! Calculates the dot product with another vector
/** \a right right-hand side vector
\returns the dot product */
/**
* \param right right-hand side vector
* \returns the dot product
*/
inline float DotMultiply(const Vector &right) const
{
return x * right.x + y * right.y + z * right.z;
@ -218,7 +223,7 @@ struct Vector
return s.str();
}
}; // struct Point
}; // struct Vector
//! Checks if two vectors are equal within given \a tolerance
inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance = TOLERANCE)
@ -262,4 +267,14 @@ inline float Distance(const Math::Vector &a, const Math::Vector &b)
(a.z-b.z)*(a.z-b.z) );
}
//! Clamps the vector \a vec to range between \a min and \a max
inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
{
Vector clamped;
clamped.x = Min(Max(min.x, vec.x), max.x);
clamped.y = Min(Max(min.y, vec.y), max.y);
clamped.z = Min(Max(min.z, vec.z), max.z);
return clamped;
}
}; // namespace Math

View File

@ -15,8 +15,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/auto.h"
@ -26,7 +24,8 @@
#include "ui/gauge.h"
#include "ui/window.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -37,22 +36,22 @@ CAuto::CAuto(CInstanceManager* iMan, CObject* object)
m_iMan->AddInstance(CLASS_AUTO, this, 100);
m_object = object;
m_event = (CEvent*)m_iMan->SearchInstance(CLASS_EVENT);
m_engine = (CD3DEngine*)m_iMan->SearchInstance(CLASS_ENGINE);
m_particule = (CParticule*)m_iMan->SearchInstance(CLASS_PARTICULE);
m_light = (CLight*)m_iMan->SearchInstance(CLASS_LIGHT);
m_terrain = (CTerrain*)m_iMan->SearchInstance(CLASS_TERRAIN);
m_water = (CWater*)m_iMan->SearchInstance(CLASS_WATER);
m_cloud = (CCloud*)m_iMan->SearchInstance(CLASS_CLOUD);
m_planet = (CPlanet*)m_iMan->SearchInstance(CLASS_PLANET);
m_blitz = (CBlitz*)m_iMan->SearchInstance(CLASS_BLITZ);
m_camera = (CCamera*)m_iMan->SearchInstance(CLASS_CAMERA);
m_interface = (CInterface*)m_iMan->SearchInstance(CLASS_INTERFACE);
m_main = (CRobotMain*)m_iMan->SearchInstance(CLASS_MAIN);
m_displayText = (CDisplayText*)m_iMan->SearchInstance(CLASS_DISPLAYTEXT);
m_sound = (CSound*)m_iMan->SearchInstance(CLASS_SOUND);
m_event = static_cast< CEventQueue* >(m_iMan->SearchInstance(CLASS_EVENT));
m_engine = static_cast< Gfx::CEngine* >(m_iMan->SearchInstance(CLASS_ENGINE));
m_particle = static_cast< Gfx::CParticle* >(m_iMan->SearchInstance(CLASS_PARTICULE));
m_lightMan = static_cast< Gfx::CLightManager* >(m_iMan->SearchInstance(CLASS_LIGHT));
m_terrain = static_cast< Gfx::CTerrain* >(m_iMan->SearchInstance(CLASS_TERRAIN));
m_water = static_cast< Gfx::CWater* >(m_iMan->SearchInstance(CLASS_WATER));
m_cloud = static_cast< Gfx::CCloud* >(m_iMan->SearchInstance(CLASS_CLOUD));
m_planet = static_cast< Gfx::CPlanet* >(m_iMan->SearchInstance(CLASS_PLANET));
m_lightning = static_cast< Gfx::CLightning* >(m_iMan->SearchInstance(CLASS_BLITZ));
m_camera = static_cast< Gfx::CCamera* >(m_iMan->SearchInstance(CLASS_CAMERA));
m_interface = static_cast< Ui::CInterface* >(m_iMan->SearchInstance(CLASS_INTERFACE));
m_main = static_cast< CRobotMain* >(m_iMan->SearchInstance(CLASS_MAIN));
m_displayText = static_cast< Ui::CDisplayText* >(m_iMan->SearchInstance(CLASS_DISPLAYTEXT));
m_sound = static_cast< CSoundInterface* >(m_iMan->SearchInstance(CLASS_SOUND));
m_type = m_object->RetType();
m_type = m_object->GetType();
m_time = 0.0f;
m_lastUpdateTime = 0.0f;
m_bMotor = false;
@ -117,14 +116,14 @@ bool CAuto::SetString(char *string)
bool CAuto::EventProcess(const Event &event)
{
if ( event.event == EVENT_FRAME &&
!m_engine->RetPause() )
if ( event.type == EVENT_FRAME &&
!m_engine->GetPause() )
{
m_time += event.rTime;
UpdateInterface(event.rTime);
}
if ( !m_object->RetSelect() ) // robot not selected?
if ( !m_object->GetSelect() ) // robot not selected?
{
return true;
}
@ -151,13 +150,13 @@ bool CAuto::Abort()
bool CAuto::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
char name[100];
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw != 0 )
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw != nullptr )
{
pw->Flush(); // destroys the window buttons
m_interface->DeleteControl(EVENT_WINDOW0); // destroys the window
@ -171,7 +170,7 @@ bool CAuto::CreateInterface(bool bSelect)
//? dim.y = 70.0f/480.0f;
dim.y = 86.0f/480.0f;
m_interface->CreateWindows(pos, dim, 3, EVENT_WINDOW0);
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
m_object->GetTooltipName(name);
@ -214,7 +213,7 @@ bool CAuto::CreateInterface(bool bSelect)
pos.y = oy+sy*0;
pw->CreateButton(pos, dim, 19, EVENT_OBJECT_HELP);
if ( m_main->RetSceneSoluce() )
if ( m_main->GetSceneSoluce() )
{
pos.x = ox+sx*13.4f;
pos.y = oy+sy*1;
@ -263,62 +262,62 @@ bool CAuto::CreateInterface(bool bSelect)
// Change the state of a button interface.
void CAuto::CheckInterface(CWindow *pw, EventMsg event, bool bState)
void CAuto::CheckInterface(Ui::CWindow *pw, EventType event, bool bState)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
if ( control == nullptr ) return;
control->SetState(STATE_CHECK, bState);
control->SetState(Ui::STATE_CHECK, bState);
}
// Change the state of a button interface.
void CAuto::EnableInterface(CWindow *pw, EventMsg event, bool bState)
void CAuto::EnableInterface(Ui::CWindow *pw, EventType event, bool bState)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
if ( control == nullptr ) return;
control->SetState(STATE_ENABLE, bState);
control->SetState(Ui::STATE_ENABLE, bState);
}
// Change the state of a button interface.
void CAuto::VisibleInterface(CWindow *pw, EventMsg event, bool bState)
void CAuto::VisibleInterface(Ui::CWindow *pw, EventType event, bool bState)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
if ( control == nullptr ) return;
control->SetState(STATE_VISIBLE, bState);
control->SetState(Ui::STATE_VISIBLE, bState);
}
// Change the state of a button interface.
void CAuto::DeadInterface(CWindow *pw, EventMsg event, bool bState)
void CAuto::DeadInterface(Ui::CWindow *pw, EventType event, bool bState)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
if ( control == nullptr ) return;
control->SetState(STATE_DEAD, !bState);
control->SetState(Ui::STATE_DEAD, !bState);
}
// Change the state of a button interface.
void CAuto::UpdateInterface()
{
CWindow* pw;
Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return;
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return;
VisibleInterface(pw, EVENT_OBJECT_GPROGRESS, m_bBusy);
}
@ -328,34 +327,34 @@ void CAuto::UpdateInterface()
void CAuto::UpdateInterface(float rTime)
{
CWindow* pw;
CGauge* pg;
Ui::CWindow* pw;
Ui::CGauge* pg;
if ( m_time < m_lastUpdateTime+0.1f ) return;
m_lastUpdateTime = m_time;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return;
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return;
pg = (CGauge*)pw->SearchControl(EVENT_OBJECT_GSHIELD);
if ( pg != 0 )
pg = static_cast<Ui::CGauge*>(pw->SearchControl(EVENT_OBJECT_GSHIELD));
if ( pg != nullptr )
{
pg->SetLevel(m_object->RetShield());
pg->SetLevel(m_object->GetShield());
}
pg = (CGauge*)pw->SearchControl(EVENT_OBJECT_GPROGRESS);
if ( pg != 0 )
pg = static_cast<Ui::CGauge*>(pw->SearchControl(EVENT_OBJECT_GPROGRESS));
if ( pg != nullptr )
{
pg->SetLevel(m_progressTime);
}
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAuto::RetError()
Error CAuto::GetError()
{
return ERR_OK;
}
@ -363,7 +362,7 @@ Error CAuto::RetError()
// Management of the occupation.
bool CAuto::RetBusy()
bool CAuto::GetBusy()
{
return m_bBusy;
}
@ -387,7 +386,7 @@ void CAuto::EventProgress(float rTime)
// Engine management.
bool CAuto::RetMotor()
bool CAuto::GetMotor()
{
return m_bMotor;
}
@ -422,11 +421,11 @@ bool CAuto::Write(char *line)
return false;
}
// Return all settings to the controller.
// Geturn all settings to the controller.
bool CAuto::Read(char *line)
{
m_type = (ObjectType)OpInt(line, "aType", OBJECT_NULL);
m_type = static_cast<ObjectType>(OpInt(line, "aType", OBJECT_NULL));
m_bBusy = OpInt(line, "aBusy", 0);
m_time = OpFloat(line, "aTime", 0.0f);
m_progressTime = OpFloat(line, "aProgressTime", 0.0f);

View File

@ -19,27 +19,32 @@
#pragma once
#include "common/misc.h"
#include "common/global.h"
#include "object/object.h"
class CInstanceManager;
class CD3DEngine;
class CParticule;
class CLight;
class CTerrain;
class CRobotMain;
class CSoundInterface;
namespace Ui {
class CDisplayText;
class CInterface;
class CWindow;
} /* Ui */
namespace Gfx {
class CEngine;
class CParticle;
class CLightManager;
class CTarrain;
class CWater;
class CCloud;
class CPlanet;
class CBlitz;
class CCamera;
class CInterface;
class CRobotMain;
class CDisplayText;
class CWindow;
class CSound;
class CPlanet;
class CLightning;
} /* Gfx */
class CAuto
@ -61,44 +66,44 @@ public:
virtual bool SetString(char *string);
virtual bool CreateInterface(bool bSelect);
virtual Error RetError();
virtual Error GetError();
virtual bool RetBusy();
virtual bool GetBusy();
virtual void SetBusy(bool bBuse);
virtual void InitProgressTotal(float total);
virtual void EventProgress(float rTime);
virtual bool RetMotor();
virtual bool GetMotor();
virtual void SetMotor(bool bMotor);
virtual bool Write(char *line);
virtual bool Read(char *line);
protected:
void CheckInterface(CWindow *pw, EventMsg event, bool bState);
void EnableInterface(CWindow *pw, EventMsg event, bool bState);
void VisibleInterface(CWindow *pw, EventMsg event, bool bState);
void DeadInterface(CWindow *pw, EventMsg event, bool bState);
void CheckInterface(Ui::CWindow *pw, EventType event, bool bState);
void EnableInterface(Ui::CWindow *pw, EventType event, bool bState);
void VisibleInterface(Ui::CWindow *pw, EventType event, bool bState);
void DeadInterface(Ui::CWindow *pw, EventType event, bool bState);
void UpdateInterface();
void UpdateInterface(float rTime);
protected:
CInstanceManager* m_iMan;
CEvent* m_event;
CD3DEngine* m_engine;
CParticule* m_particule;
CLight* m_light;
CTerrain* m_terrain;
CWater* m_water;
CCloud * m_cloud;
CPlanet * m_planet;
CBlitz* m_blitz;
CCamera* m_camera;
CInterface* m_interface;
CRobotMain* m_main;
CDisplayText* m_displayText;
CObject* m_object;
CSound* m_sound;
CInstanceManager* m_iMan;
CEventQueue* m_event;
Gfx::CEngine* m_engine;
Gfx::CParticle* m_particle;
Gfx::CLightManager* m_lightMan;
Gfx::CTerrain* m_terrain;
Gfx::CWater* m_water;
Gfx::CCloud* m_cloud;
Gfx::CPlanet* m_planet;
Gfx::CLightning* m_lightning;
Gfx::CCamera* m_camera;
Ui::CInterface* m_interface;
Ui::CDisplayText* m_displayText;
CRobotMain* m_main;
CObject* m_object;
CSoundInterface* m_sound;
ObjectType m_type;
bool m_bBusy;

View File

@ -20,10 +20,10 @@
#include "object/auto/autobase.h"
#include "common/iman.h"
#include "old/terrain.h"
#include "old/cloud.h"
#include "old/planet.h"
#include "old/blitz.h"
#include "graphics/engine/terrain.h"
#include "graphics/engine/cloud.h"
#include "graphics/engine/planet.h"
#include "graphics/engine/lightning.h"
#include "math/geometry.h"
#include "object/robotmain.h"
#include "physics/physics.h"
@ -50,8 +50,8 @@ const float BASE_TRANSIT_TIME = 15.0f; // transit duration
CAutoBase::CAutoBase(CInstanceManager* iMan, CObject* object)
: CAuto(iMan, object)
{
m_fogStart = m_engine->RetFogStart();
m_deepView = m_engine->RetDeepView();
m_fogStart = m_engine->GetFogStart();
m_deepView = m_engine->GetDeepView();
Init();
m_phase = ABP_WAIT;
m_soundChannel = -1;
@ -85,10 +85,10 @@ void CAutoBase::Init()
{
m_bOpen = false;
m_time = 0.0f;
m_lastParticule = 0.0f;
m_lastMotorParticule = 0.0f;
m_lastParticle = 0.0f;
m_lastMotorParticle = 0.0f;
m_pos = m_object->RetPosition(0);
m_pos = m_object->GetPosition(0);
m_lastPos = m_pos;
m_phase = ABP_WAIT;
@ -124,10 +124,10 @@ bool CAutoBase::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
begin:
iPos = m_object->RetPosition(0);
iPos = m_object->GetPosition(0);
if ( m_phase == ABP_START )
{
@ -152,17 +152,17 @@ begin:
m_object->SetPosition(18+i, Math::Vector(23.5f, 0.0f, 11.5f));
}
pObj = m_main->RetSelectObject();
pObj = m_main->GetSelectObject();
m_main->SelectObject(pObj);
m_camera->SetObject(pObj);
m_camera->SetControllingObject(pObj);
if ( pObj == 0 )
{
m_camera->SetType(CAMERA_BACK);
m_camera->SetType(Gfx::CAM_TYPE_BACK);
}
else
{
m_camera->SetType(pObj->RetCameraType());
m_camera->SetDist(pObj->RetCameraDist());
m_camera->SetType(pObj->GetCameraType());
m_camera->SetDist(pObj->GetCameraDist());
}
m_main->StartMusic();
@ -193,16 +193,16 @@ begin:
m_main->SetMovieLock(true); // blocks everything until the end of the landing
m_bMotor = true; // lights the jet engine
m_camera->SetType(CAMERA_SCRIPT);
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
pos = m_pos;
pos.x -= 150.0f;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
m_camera->SetScriptEye(pos);
m_posSound = pos;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 300.0f+50.0f;
m_camera->SetScriptLookat(pos);
@ -223,7 +223,7 @@ begin:
if ( m_param == PARAM_PORTICO ) // gate on the porch?
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
m_finalPos = pos;
pos.z += BASE_PORTICO_TIME_MOVE*5.0f; // back
pos.y += 10.0f; // rises (the gate)
@ -246,7 +246,7 @@ begin:
m_speed = 1.0f/BASE_TRANSIT_TIME;
m_object->SetAngleZ(0, -Math::PI/2.0f);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 10000.0f; // in space
m_finalPos = pos;
m_object->SetPosition(0, pos);
@ -254,7 +254,7 @@ begin:
m_main->SetMovieLock(true); // blocks everything until the end of the landing
m_bMotor = true; // lights the jet engine
m_camera->SetType(CAMERA_SCRIPT);
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
pos.x += 1000.0f;
pos.z -= 60.0f;
pos.y += 80.0f;
@ -265,34 +265,34 @@ begin:
BeginTransit();
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 10.0f;
dim.y = dim.x;
pos = Math::Vector(42.0f, -2.0f, 17.0f);
pos = Transform(*mat, pos);
m_partiChannel[0] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[0] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(17.0f, -2.0f, 42.0f);
pos = Transform(*mat, pos);
m_partiChannel[1] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[1] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(42.0f, -2.0f, -17.0f);
pos = Transform(*mat, pos);
m_partiChannel[2] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[2] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(17.0f, -2.0f, -42.0f);
pos = Transform(*mat, pos);
m_partiChannel[3] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[3] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(-42.0f, -2.0f, 17.0f);
pos = Transform(*mat, pos);
m_partiChannel[4] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[4] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(-17.0f, -2.0f, 42.0f);
pos = Transform(*mat, pos);
m_partiChannel[5] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[5] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(-42.0f, -2.0f, -17.0f);
pos = Transform(*mat, pos);
m_partiChannel[6] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[6] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
pos = Math::Vector(-17.0f, -2.0f, -42.0f);
pos = Transform(*mat, pos);
m_partiChannel[7] = m_particule->CreateParticule(pos, speed, dim, PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
m_partiChannel[7] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
if ( m_soundChannel == -1 )
{
@ -303,12 +303,12 @@ begin:
}
}
if ( event.event == EVENT_UPDINTERFACE )
if ( event.type == EVENT_UPDINTERFACE )
{
if ( m_object->RetSelect() ) CreateInterface(true);
if ( m_object->GetSelect() ) CreateInterface(true);
}
if ( event.event == EVENT_OBJECT_BTAKEOFF )
if ( event.type == EVENT_OBJECT_BTAKEOFF )
{
err = CheckCloseDoor();
if ( err != ERR_OK )
@ -328,19 +328,19 @@ begin:
m_main->SetMovieLock(true); // blocks everything until the end
m_main->DeselectAll();
m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
newEvent.type = EVENT_UPDINTERFACE;
m_event->AddEvent(newEvent);
m_camera->SetType(CAMERA_SCRIPT);
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
pos = m_pos;
pos.x -= 110.0f;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
m_camera->SetScriptEye(pos);
m_posSound = pos;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 50.0f;
m_camera->SetScriptLookat(pos);
@ -356,7 +356,7 @@ begin:
return true;
}
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_phase == ABP_WAIT ) return true;
m_progress += event.rTime*m_speed;
@ -382,19 +382,19 @@ begin:
pos = m_pos;
pos.x -= 150.0f;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
m_camera->SetScriptEye(pos);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 50.0f;
m_camera->SetScriptLookat(pos);
m_engine->SetFocus(1.0f+(1.0f-m_progress));
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
// Dust thrown to the ground.
pos = m_pos;
@ -410,19 +410,19 @@ begin:
dim.y = dim.x;
if ( dim.x >= 1.0f )
{
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, 2.0f, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f, 0.0f, 2.0f);
}
// Particles are ejected from the jet engine.
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 6.0f;
h = m_terrain->RetFloorHeight(pos)/300.0f;
h = m_terrain->GetHeightToFloor(pos)/300.0f;
speed.x = (Math::Rand()-0.5f)*(80.0f-50.0f*h);
speed.z = (Math::Rand()-0.5f)*(80.0f-50.0f*h);
speed.y = -(Math::Rand()*(h+1.0f)*40.0f+(h+1.0f)*40.0f);
dim.x = Math::Rand()*2.0f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 2.0f, 10.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 2.0f, 10.0f, 2.0f);
// Black smoke from the jet engine.
if ( m_progress > 0.8f )
@ -436,7 +436,7 @@ begin:
speed.y = 0.0f;
dim.x = Math::Rand()*4.0f+4.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f, 0.0f, 2.0f);
}
}
}
@ -449,7 +449,7 @@ begin:
MoveCargo(); // all cargo moves
// Impact with the ground.
max = (int)(50.0f*m_engine->RetParticuleDensity());
max = static_cast<int>(50.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
angle = Math::Rand()*(Math::PI*2.0f);
@ -461,11 +461,11 @@ begin:
dim.x = Math::Rand()*10.0f+10.0f;
dim.y = dim.x;
time = Math::Rand()*2.0f+1.5f;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, time, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, time, 0.0f, 2.0f);
}
//? m_camera->StartEffect(CE_CRASH, m_pos, 1.0f);
m_camera->StartEffect(CE_EXPLO, m_pos, 2.0f);
m_camera->StartEffect(Gfx::CAM_EFFECT_EXPLO, m_pos, 2.0f);
m_engine->SetFocus(1.0f);
m_sound->Play(SOUND_BOUM, m_posSound, 0.6f, 0.5f);
@ -479,9 +479,9 @@ begin:
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
// Black smoke from the reactor.
pos = m_pos;
@ -493,7 +493,7 @@ begin:
speed.y = 0.0f;
dim.x = Math::Rand()*4.0f+4.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f, 0.0f, 2.0f);
}
}
else
@ -526,7 +526,7 @@ begin:
pos = m_pos;
pos.x += p.x;
pos.z += p.y;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
pos.y += m_progress*40.0f;
m_camera->SetScriptEye(pos);
@ -542,7 +542,7 @@ begin:
}
// Clash the doors with the ground.
max = (int)(20.0f*m_engine->RetParticuleDensity());
max = static_cast<int>(20.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
angle = Math::Rand()*(20.0f*Math::PI/180.0f)-(10.0f*Math::PI/180.0f);
@ -555,7 +555,7 @@ begin:
dim.x = Math::Rand()*8.0f+8.0f;
dim.y = dim.x;
time = Math::Rand()*2.0f+1.5f;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, time, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, time, 0.0f, 2.0f);
}
m_soundChannel = m_sound->Play(SOUND_MANIP, m_posSound, 0.3f, 1.5f, true);
@ -588,7 +588,7 @@ begin:
pos = m_pos;
pos.x += p.x;
pos.z += p.y;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
pos.y += m_progress*40.0f;
m_camera->SetScriptEye(pos);
@ -622,19 +622,19 @@ begin:
{
m_main->SetMovieLock(false); // you can play!
pObj = m_main->RetSelectObject();
pObj = m_main->GetSelectObject();
m_main->SelectObject(pObj);
m_camera->SetObject(pObj);
m_camera->SetControllingObject(pObj);
if ( pObj == 0 )
{
m_camera->SetType(CAMERA_BACK);
m_camera->SetType(Gfx::CAM_TYPE_BACK);
}
else
{
m_camera->SetType(pObj->RetCameraType());
m_camera->SetDist(pObj->RetCameraDist());
m_camera->SetType(pObj->GetCameraType());
m_camera->SetDist(pObj->GetCameraDist());
}
m_sound->Play(SOUND_BOUM, m_object->RetPosition(0));
m_sound->Play(SOUND_BOUM, m_object->GetPosition(0));
m_soundChannel = -1;
m_engine->SetFogStart(m_fogStart);
@ -700,7 +700,7 @@ begin:
m_bMotor = true; // lights the jet engine
// Shock of the closing doors.
max = (int)(20.0f*m_engine->RetParticuleDensity());
max = static_cast<int>(20.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
angle = Math::Rand()*Math::PI*2.0f;
@ -713,9 +713,9 @@ begin:
dim.x = Math::Rand()*3.0f+3.0f;
dim.y = dim.x;
time = Math::Rand()*1.0f+1.0f;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, time);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, time);
}
m_sound->Play(SOUND_BOUM, m_object->RetPosition(0));
m_sound->Play(SOUND_BOUM, m_object->GetPosition(0));
m_soundChannel = -1;
m_bOpen = false;
@ -742,19 +742,19 @@ begin:
vibCir *= m_progress*1.0f;
m_object->SetCirVibration(vibCir);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
// Particles are ejected from the reactor.
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 6.0f;
speed.x = (Math::Rand()-0.5f)*160.0f;
speed.z = (Math::Rand()-0.5f)*160.0f;
speed.y = -(Math::Rand()*10.0f+10.0f);
dim.x = Math::Rand()*2.0f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 2.0f, 10.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 2.0f, 10.0f, 2.0f);
}
m_engine->SetFogStart(m_fogStart+(0.9f-m_fogStart)*m_progress);
@ -785,19 +785,19 @@ begin:
pos = m_pos;
pos.x -= 110.0f+m_progress*250.0f;
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
pos.y += 10.0f;
m_camera->SetScriptEye(pos);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 50.0f;
m_camera->SetScriptLookat(pos);
m_engine->SetFocus(1.0f+m_progress);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
// Dust thrown to the ground.
pos = m_pos;
@ -813,11 +813,11 @@ begin:
dim.y = dim.x;
if ( dim.x >= 1.0f )
{
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, 2.0f, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f, 0.0f, 2.0f);
}
// Particles are ejected from the reactor.
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 6.0f;
speed.x = (Math::Rand()-0.5f)*40.0f;
speed.z = (Math::Rand()-0.5f)*40.0f;
@ -826,23 +826,23 @@ begin:
time = 2.0f+m_progress*12.0f;
dim.x = Math::Rand()*time+time;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 2.0f, 10.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 2.0f, 10.0f, 2.0f);
// Black smoke from the reactor.
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 3.0f;
speed.x = (Math::Rand()-0.5f)*10.0f*(4.0f-m_progress*3.0f);
speed.z = (Math::Rand()-0.5f)*10.0f*(4.0f-m_progress*3.0f);
speed.y = 0.0f;
dim.x = Math::Rand()*20.0f+20.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 10.0f, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 10.0f, 0.0f, 2.0f);
}
}
else
{
m_soundChannel = -1;
m_event->MakeEvent(newEvent, EVENT_WIN);
newEvent.type = EVENT_WIN;
m_event->AddEvent(newEvent);
m_phase = ABP_WAIT;
@ -855,7 +855,7 @@ begin:
{
if ( m_progress < 1.0f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.z -= event.rTime*5.0f;
m_object->SetPosition(0, pos);
MoveCargo(); // all cargo moves
@ -882,7 +882,7 @@ begin:
{
if ( m_progress < 1.0f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y -= event.rTime*(10.0f/BASE_PORTICO_TIME_DOWN);
m_object->SetPosition(0, pos);
MoveCargo(); // all cargo moves
@ -890,7 +890,7 @@ begin:
else
{
// Impact with the ground.
max = (int)(50.0f*m_engine->RetParticuleDensity());
max = static_cast<int>(50.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
angle = Math::Rand()*(Math::PI*2.0f);
@ -902,7 +902,7 @@ begin:
dim.x = Math::Rand()*10.0f+10.0f;
dim.y = dim.x;
time = Math::Rand()*2.0f+1.5f;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, time, 0.0f, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, time, 0.0f, 2.0f);
}
m_phase = ABP_PORTICO_WAIT2;
@ -938,7 +938,7 @@ begin:
{
if ( m_progress < 1.0f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += event.rTime*(2000.0f/BASE_TRANSIT_TIME);
m_object->SetPosition(0, pos);
pos.x += 60.0f;
@ -967,11 +967,11 @@ begin:
if ( m_bMotor )
{
if ( m_lastMotorParticule+m_engine->ParticuleAdapt(0.02f) <= m_time )
if ( m_lastMotorParticle+m_engine->ParticleAdapt(0.02f) <= m_time )
{
m_lastMotorParticule = m_time;
m_lastMotorParticle = m_time;
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
if ( event.rTime == 0.0f )
{
@ -979,7 +979,7 @@ begin:
}
else
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
if ( m_phase == ABP_TRANSIT_MOVE )
{
vSpeed = (pos.x-iPos.x)/event.rTime;
@ -1003,7 +1003,7 @@ begin:
dim.x = 4.0f+Math::Rand()*4.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBASE, 3.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBASE, 3.0f, 0.0f, 0.0f);
if ( m_phase == ABP_TRANSIT_MOVE )
{
@ -1013,7 +1013,7 @@ begin:
pos = Math::Vector(0.0f, 7.0f, 0.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 1.0f, 0.0f, 0.0f);
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 4.0f;
@ -1021,67 +1021,67 @@ begin:
pos = Math::Vector(42.0f, 0.0f, 17.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(17.0f, 0.0f, 42.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(42.0f, 0.0f, -17.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(17.0f, 0.0f, -42.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(-42.0f, 0.0f, 17.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(-17.0f, 0.0f, 42.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(-42.0f, 0.0f, -17.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(-17.0f, 0.0f, -42.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
pos = Transform(*mat, pos);
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 0.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
pos = Math::Vector(42.0f, -2.0f, 17.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[0], pos);
m_particle->SetPosition(m_partiChannel[0], pos);
pos = Math::Vector(17.0f, -2.0f, 42.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[1], pos);
m_particle->SetPosition(m_partiChannel[1], pos);
pos = Math::Vector(42.0f, -2.0f, -17.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[2], pos);
m_particle->SetPosition(m_partiChannel[2], pos);
pos = Math::Vector(17.0f, -2.0f, -42.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[3], pos);
m_particle->SetPosition(m_partiChannel[3], pos);
pos = Math::Vector(-42.0f, -2.0f, 17.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[4], pos);
m_particle->SetPosition(m_partiChannel[4], pos);
pos = Math::Vector(-17.0f, -2.0f, 42.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[5], pos);
m_particle->SetPosition(m_partiChannel[5], pos);
pos = Math::Vector(-42.0f, -2.0f, -17.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[6], pos);
m_particle->SetPosition(m_partiChannel[6], pos);
pos = Math::Vector(-17.0f, -2.0f, -42.0f);
pos = Transform(*mat, pos);
m_particule->SetPosition(m_partiChannel[7], pos);
m_particle->SetPosition(m_partiChannel[7], pos);
}
}
}
if ( m_soundChannel != -1 )
{
pos = m_engine->RetEyePt();
pos = m_engine->GetEyePt();
m_sound->Position(m_soundChannel, pos);
}
@ -1154,17 +1154,17 @@ bool CAutoBase::Abort()
m_main->SetMovieLock(false); // you can play!
pObj = m_main->RetSelectObject();
pObj = m_main->GetSelectObject();
m_main->SelectObject(pObj);
m_camera->SetObject(pObj);
m_camera->SetControllingObject(pObj);
if ( pObj == 0 )
{
m_camera->SetType(CAMERA_BACK);
m_camera->SetType(Gfx::CAM_TYPE_BACK);
}
else
{
m_camera->SetType(pObj->RetCameraType());
m_camera->SetDist(pObj->RetCameraDist());
m_camera->SetType(pObj->GetCameraType());
m_camera->SetDist(pObj->GetCameraDist());
}
m_engine->SetFogStart(m_fogStart);
@ -1175,7 +1175,7 @@ bool CAutoBase::Abort()
m_phase == ABP_TOWAIT ||
m_phase == ABP_TAKEOFF ) // off?
{
m_event->MakeEvent(newEvent, EVENT_WIN);
newEvent.type = EVENT_WIN;
m_event->AddEvent(newEvent);
}
}
@ -1198,9 +1198,9 @@ bool CAutoBase::Abort()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoBase::RetError()
Error CAutoBase::GetError()
{
return ERR_OK;
}
@ -1210,7 +1210,7 @@ Error CAutoBase::RetError()
bool CAutoBase::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
float sleep, delay, magnetic, progress;
@ -1219,8 +1219,8 @@ bool CAutoBase::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return false;
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return false;
dim.x = 33.0f/640.0f;
dim.y = 33.0f/480.0f;
@ -1240,7 +1240,7 @@ bool CAutoBase::CreateInterface(bool bSelect)
pos.y = oy+sy*0.25f;
pw->CreateButton(pos, ddim, 28, EVENT_OBJECT_BTAKEOFF);
if ( m_blitz->GetStatus(sleep, delay, magnetic, progress) )
if ( m_lightning->GetStatus(sleep, delay, magnetic, progress) )
{
pos.x = ox+sx*10.2f;
pos.y = oy+sy*0.5f;
@ -1264,13 +1264,13 @@ bool CAutoBase::CreateInterface(bool bSelect)
void CAutoBase::UpdateInterface()
{
CWindow* pw;
// Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
// pw = static_cast< Ui::CWindow* >( m_interface->SearchControl(EVENT_WINDOW0));
}
@ -1286,15 +1286,15 @@ void CAutoBase::FreezeCargo(bool bFreeze)
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast<CObject*>(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
pObj->SetCargo(false);
if ( pObj == m_object ) continue; // yourself?
if ( pObj->RetTruck() != 0 ) continue; // transport object?
if ( pObj->GetTruck() != 0 ) continue; // transport object?
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::DistanceProjected(m_pos, oPos);
if ( dist < 32.0f )
{
@ -1303,7 +1303,7 @@ void CAutoBase::FreezeCargo(bool bFreeze)
pObj->SetCargo(true);
}
physics = pObj->RetPhysics();
physics = pObj->GetPhysics();
if ( physics != 0 )
{
physics->SetFreeze(bFreeze);
@ -1320,18 +1320,18 @@ void CAutoBase::MoveCargo()
Math::Vector oPos, sPos;
int i;
sPos = m_object->RetPosition(0);
sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast < CObject* > (m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( !pObj->RetCargo() ) continue;
if ( !pObj->GetCargo() ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
oPos.y = sPos.y+30.0f;
oPos.y += pObj->RetCharacter()->height;
oPos.y += pObj->GetCharacter()->height;
oPos.x += sPos.x-m_lastPos.x;
oPos.z += sPos.z-m_lastPos.z;
pObj->SetPosition(0, oPos);
@ -1353,13 +1353,13 @@ Error CAutoBase::CheckCloseDoor()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* > (m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( pObj == m_object ) continue; // yourself?
if ( !pObj->RetActif() ) continue; // inactive?
if ( !pObj->GetActif() ) continue; // inactive?
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_PORTICO ) continue;
j = 0;
@ -1387,22 +1387,20 @@ Error CAutoBase::CheckCloseDoor()
void CAutoBase::BeginTransit()
{
bool bFull, bQuarter;
if ( m_param == PARAM_TRANSIT2 )
{
strcpy(m_bgBack, "back01.tga"); // clouds orange / blue
m_bgBack = "back01.png"; // clouds orange / blue
}
else if ( m_param == PARAM_TRANSIT3 )
{
strcpy(m_bgBack, "back22.tga"); // blueberries clouds
m_bgBack = "back22.png"; // blueberries clouds
}
else
{
#if _DEMO
strcpy(m_bgBack, "back46b.tga"); // paintings
m_bgBack = "back46b.png"; // paintings
#else
strcpy(m_bgBack, "back46.tga"); // paintings
m_bgBack = "back46.png"; // paintings
#endif
}
@ -1410,13 +1408,18 @@ void CAutoBase::BeginTransit()
m_engine->SetDeepView(2000.0f); // we see very far
m_engine->ApplyChange();
m_engine->RetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown, bFull, bQuarter);
m_engine->FreeTexture(m_bgName);
Math::Point scale;
bool full;
m_engine->GetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown, full, scale);
m_engine->DeleteTexture(m_bgName);
m_engine->SetBackground(m_bgBack, 0x00000000, 0x00000000, 0x00000000, 0x00000000);
m_engine->SetBackground(m_bgBack, Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f));
m_engine->LoadTexture(m_bgBack);
m_cloud->SetEnable(false); // cache clouds
m_cloud->SetEnabled(false); // cache clouds
m_planet->SetMode(1);
}
@ -1428,12 +1431,12 @@ void CAutoBase::EndTransit()
m_engine->SetDeepView(m_deepView); // gives initial depth
m_engine->ApplyChange();
m_engine->FreeTexture(m_bgBack);
m_engine->DeleteTexture(m_bgBack);
m_engine->SetBackground(m_bgName, m_bgUp, m_bgDown, m_bgCloudUp, m_bgCloudDown);
m_engine->LoadTexture(m_bgName);
m_cloud->SetEnable(true); // gives the clouds
m_cloud->SetEnabled(true); // gives the clouds
m_planet->SetMode(0);
m_main->StartMusic();

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -73,7 +74,7 @@ public:
void Start(int param);
bool EventProcess(const Event &event);
bool Abort();
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -90,23 +91,23 @@ protected:
bool m_bOpen;
float m_progress;
float m_speed;
float m_lastParticule;
float m_lastMotorParticule;
float m_lastParticle;
float m_lastMotorParticle;
float m_fogStart;
float m_deepView;
Math::Vector m_pos;
Math::Vector m_posSound;
Math::Vector m_finalPos;
Math::Vector m_lastPos;
Math::Vector m_pos;
Math::Vector m_posSound;
Math::Vector m_finalPos;
Math::Vector m_lastPos;
int m_param;
int m_soundChannel;
int m_partiChannel[8];
char m_bgBack[100];
char m_bgName[100];
D3DCOLOR m_bgUp;
D3DCOLOR m_bgDown;
D3DCOLOR m_bgCloudUp;
D3DCOLOR m_bgCloudDown;
std::string m_bgBack;
std::string m_bgName;
Gfx::Color m_bgUp;
Gfx::Color m_bgDown;
Gfx::Color m_bgCloudUp;
Gfx::Color m_bgCloudDown;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoconvert.h"
#include "common/iman.h"
@ -26,7 +25,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -83,7 +83,7 @@ void CAutoConvert::Init()
m_speed = 1.0f/2.0f;
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
CAuto::Init();
}
@ -100,13 +100,13 @@ bool CAutoConvert::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -146,7 +146,7 @@ bool CAutoConvert::EventProcess(const Event &event)
InitProgressTotal(3.0f+10.0f+1.5f);
UpdateInterface();
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 1.0f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.0f);
m_bSoundClose = false;
m_phase = ACP_CLOSE;
@ -163,7 +163,7 @@ bool CAutoConvert::EventProcess(const Event &event)
if ( m_progress >= 0.8f && !m_bSoundClose )
{
m_bSoundClose = true;
m_sound->Play(SOUND_CLOSE, m_object->RetPosition(0), 1.0f, 0.8f);
m_sound->Play(SOUND_CLOSE, m_object->GetPosition(0), 1.0f, 0.8f);
}
angle = -Math::PI*0.35f*(1.0f-Math::Bounce(m_progress, 0.85f, 0.05f));
m_object->SetAngleX(2, angle);
@ -174,7 +174,7 @@ bool CAutoConvert::EventProcess(const Event &event)
m_object->SetAngleX(2, 0.0f);
m_object->SetAngleX(3, 0.0f);
m_soundChannel = m_sound->Play(SOUND_CONVERT, m_object->RetPosition(0), 0.0f, 0.25f, true);
m_soundChannel = m_sound->Play(SOUND_CONVERT, m_object->GetPosition(0), 0.0f, 0.25f, true);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 1.00f, 4.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 4.5f, SOPER_CONTINUE);
@ -202,11 +202,11 @@ bool CAutoConvert::EventProcess(const Event &event)
m_object->SetAngleY(2, angle);
m_object->SetAngleY(3, angle+Math::PI);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
c.x = pos.x;
c.y = pos.z;
p.x = c.x;
@ -218,7 +218,7 @@ bool CAutoConvert::EventProcess(const Event &event)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*2.0f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGAS, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 1.0f, 0.0f, 0.0f);
}
}
else
@ -230,13 +230,13 @@ bool CAutoConvert::EventProcess(const Event &event)
fret = SearchStone(OBJECT_STONE);
if ( fret != 0 )
{
m_bResetDelete = ( fret->RetResetCap() != RESET_NONE );
m_bResetDelete = ( fret->GetResetCap() != RESET_NONE );
fret->DeleteObject(); // destroy the stone
delete fret;
}
CreateMetal(); // Create the metal
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 1.5f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.5f);
m_phase = ACP_OPEN;
m_progress = 0.0f;
@ -253,18 +253,18 @@ bool CAutoConvert::EventProcess(const Event &event)
m_object->SetAngleX(3, angle);
if ( m_progress < 0.9f &&
m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*6.0f;
pos.z += (Math::Rand()-0.5f)*6.0f;
pos.y += Math::Rand()*4.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*4.0f+3.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, 1.0f, 0.0f, 0.0f);
}
}
else
@ -285,11 +285,11 @@ bool CAutoConvert::EventProcess(const Event &event)
return true;
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoConvert::RetError()
Error CAutoConvert::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -330,7 +330,7 @@ bool CAutoConvert::Abort()
bool CAutoConvert::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -338,8 +338,8 @@ bool CAutoConvert::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return false;
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return false;
ox = 3.0f/640.0f;
oy = 3.0f/480.0f;
@ -390,11 +390,11 @@ bool CAutoConvert::Read(char *line)
CAuto::Read(line);
m_phase = (AutoConvertPhase)OpInt(line, "aPhase", ACP_WAIT);
m_phase = static_cast< AutoConvertPhase >(OpInt(line, "aPhase", ACP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}
@ -410,18 +410,18 @@ CObject* CAutoConvert::SearchStone(ObjectType type)
float dist;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
oType = pObj->RetType();
oType = pObj->GetType();
if ( oType != type ) continue;
if ( pObj->RetTruck() != 0 ) continue;
if ( pObj->GetTruck() != 0 ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, cPos);
if ( dist <= 5.0f ) return pObj;
@ -440,14 +440,14 @@ bool CAutoConvert::SearchVehicle()
float oRadius, dist;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
@ -506,8 +506,8 @@ void CAutoConvert::CreateMetal()
float angle;
CObject* fret;
pos = m_object->RetPosition(0);
angle = m_object->RetAngleY(0);
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
fret = new CObject(m_iMan);
if ( !fret->CreateResource(pos, angle, OBJECT_METAL) )

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool Abort();
bool CreateInterface(bool bSelect);
@ -62,7 +63,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
bool m_bResetDelete;
bool m_bSoundClose;
int m_soundChannel;

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,19 +16,18 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoderrick.h"
#include "common/iman.h"
#include "old/terrain.h"
#include "graphics/engine/terrain.h"
#include "math/geometry.h"
#include "script/cmdtoken.h"
#include "ui/interface.h"
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float DERRICK_DELAY = 10.0f; // duration of the extraction
@ -62,7 +62,7 @@ void CAutoDerrick::DeleteObject(bool bAll)
if ( !bAll )
{
fret = SearchFret();
if ( fret != 0 && fret->RetLock() )
if ( fret != 0 && fret->GetLock() )
{
fret->DeleteObject();
delete fret;
@ -86,25 +86,25 @@ void CAutoDerrick::Init()
{
Math::Matrix* mat;
Math::Vector pos;
TerrainRes res;
Gfx::TerrainRes res;
pos = m_object->RetPosition(0);
res = m_terrain->RetResource(pos);
pos = m_object->GetPosition(0);
res = m_terrain->GetResource(pos);
if ( res == TR_STONE ||
res == TR_URANIUM ||
res == TR_KEYa ||
res == TR_KEYb ||
res == TR_KEYc ||
res == TR_KEYd )
if ( res == Gfx::TR_STONE ||
res == Gfx::TR_URANIUM ||
res == Gfx::TR_KEY_A ||
res == Gfx::TR_KEY_B ||
res == Gfx::TR_KEY_C ||
res == Gfx::TR_KEY_D )
{
m_type = OBJECT_FRET;
if ( res == TR_STONE ) m_type = OBJECT_STONE;
if ( res == TR_URANIUM ) m_type = OBJECT_URANIUM;
if ( res == TR_KEYa ) m_type = OBJECT_KEYa;
if ( res == TR_KEYb ) m_type = OBJECT_KEYb;
if ( res == TR_KEYc ) m_type = OBJECT_KEYc;
if ( res == TR_KEYd ) m_type = OBJECT_KEYd;
if ( res == Gfx::TR_STONE ) m_type = OBJECT_STONE;
if ( res == Gfx::TR_URANIUM ) m_type = OBJECT_URANIUM;
if ( res == Gfx::TR_KEY_A ) m_type = OBJECT_KEYa;
if ( res == Gfx::TR_KEY_B ) m_type = OBJECT_KEYb;
if ( res == Gfx::TR_KEY_C ) m_type = OBJECT_KEYc;
if ( res == Gfx::TR_KEY_D ) m_type = OBJECT_KEYd;
m_phase = ADP_EXCAVATE;
m_progress = 0.0f;
@ -119,13 +119,13 @@ void CAutoDerrick::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
m_lastTrack = 0.0f;
pos = Math::Vector(7.0f, 0.0f, 0.0f);
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
pos = Math::Transform(*mat, pos);
m_terrain->MoveOnFloor(pos);
m_terrain->AdjustToFloor(pos);
m_fretPos = pos;
}
@ -141,14 +141,14 @@ bool CAutoDerrick::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_phase == ADP_WAIT ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -176,7 +176,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
{
factor = 1.0f;
}
m_soundChannel = m_sound->Play(SOUND_DERRICK, m_object->RetPosition(0), 1.0f, 0.5f, true);
m_soundChannel = m_sound->Play(SOUND_DERRICK, m_object->GetPosition(0), 1.0f, 0.5f, true);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 4.0f*factor, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.3f, 6.0f*factor, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 1.0f, SOPER_CONTINUE);
@ -184,25 +184,25 @@ bool CAutoDerrick::EventProcess(const Event &event)
}
if ( m_progress >= 6.0f/16.0f && // penetrates into the ground?
m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = Math::Rand()*5.0f;
dim.x = Math::Rand()*3.0f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f);
}
if ( m_progress >= 6.0f/16.0f && // penetrates into the ground?
m_lastTrack+m_engine->ParticuleAdapt(0.5f) <= m_time )
m_lastTrack+m_engine->ParticleAdapt(0.5f) <= m_time )
{
m_lastTrack = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*12.0f;
speed.z = (Math::Rand()-0.5f)*12.0f;
speed.y = Math::Rand()*10.0f+10.0f;
@ -210,7 +210,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
dim.y = dim.x;
pos.y += dim.y;
duration = Math::Rand()*2.0f+2.0f;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK5,
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK5,
duration, Math::Rand()*10.0f+15.0f,
duration*0.2f, 1.0f);
}
@ -222,7 +222,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
pos.y = -m_progress*16.0f;
m_object->SetPosition(1, pos); // down the drill
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle += event.rTime*8.0f;
m_object->SetAngleY(1, angle); // rotates the drill
}
@ -237,25 +237,25 @@ bool CAutoDerrick::EventProcess(const Event &event)
if ( m_phase == ADP_ASCEND )
{
if ( m_progress <= 7.0f/16.0f &&
m_lastParticule+m_engine->ParticuleAdapt(0.1f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = Math::Rand()*5.0f;
dim.x = Math::Rand()*3.0f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH, 2.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f);
}
if ( m_progress <= 4.0f/16.0f &&
m_lastTrack+m_engine->ParticuleAdapt(1.0f) <= m_time )
m_lastTrack+m_engine->ParticleAdapt(1.0f) <= m_time )
{
m_lastTrack = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*12.0f;
speed.z = (Math::Rand()-0.5f)*12.0f;
speed.y = Math::Rand()*10.0f+10.0f;
@ -263,7 +263,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
dim.y = dim.x;
pos.y += dim.y;
duration = Math::Rand()*2.0f+2.0f;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK5,
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK5,
duration, Math::Rand()*10.0f+15.0f,
duration*0.2f, 1.0f);
}
@ -275,7 +275,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
pos.y = -(1.0f-m_progress)*16.0f;
m_object->SetPosition(1, pos); // back the drill
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle -= event.rTime*2.0f;
m_object->SetAngleY(1, angle); // rotates the drill
}
@ -308,7 +308,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
{
if ( SearchFree(m_fretPos) )
{
angle = m_object->RetAngleY(0);
angle = m_object->GetAngleY(0);
CreateFret(m_fretPos, angle, m_type, 16.0f);
}
else
@ -324,31 +324,31 @@ bool CAutoDerrick::EventProcess(const Event &event)
if ( fret != 0 &&
m_progress <= 0.5f &&
m_lastParticule+m_engine->ParticuleAdapt(0.1f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
if ( m_progress < 0.3f )
{
pos = fret->RetPosition(0);
pos = fret->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += (Math::Rand()-0.5f)*5.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 3.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFIRE, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIRE, 1.0f, 0.0f, 0.0f);
}
else
{
pos = fret->RetPosition(0);
pos = fret->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += Math::Rand()*2.5f;
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGLINT, 2.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
}
}
@ -356,7 +356,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
{
if ( fret != 0 )
{
pos = fret->RetPosition(0);
pos = fret->GetPosition(0);
pos.y -= event.rTime*20.0f; // grave
if ( !m_bSoundFall && pos.y < m_fretPos.y )
{
@ -396,7 +396,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
bool CAutoDerrick::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -404,7 +404,7 @@ bool CAutoDerrick::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -455,11 +455,11 @@ bool CAutoDerrick::Read(char *line)
CAuto::Read(line);
m_phase = (AutoDerrickPhase)OpInt(line, "aPhase", ADP_WAIT);
m_phase = static_cast< AutoDerrickPhase >(OpInt(line, "aPhase", ADP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}
@ -476,13 +476,13 @@ CObject* CAutoDerrick::SearchFret()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_DERRICK ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
if ( oPos.x == m_fretPos.x &&
oPos.z == m_fretPos.z ) return pObj;
@ -503,10 +503,10 @@ bool CAutoDerrick::SearchFree(Math::Vector pos)
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_DERRICK ) continue;
j = 0;
@ -537,12 +537,12 @@ void CAutoDerrick::CreateFret(Math::Vector pos, float angle, ObjectType type,
}
fret->SetLock(true); // object not yet usable
if ( m_object->RetResetCap() == RESET_MOVE )
if ( m_object->GetResetCap() == RESET_MOVE )
{
fret->SetResetCap(RESET_DELETE);
}
pos = fret->RetPosition(0);
pos = fret->GetPosition(0);
pos.y += height;
fret->SetPosition(0, pos);
}
@ -562,10 +562,10 @@ bool CAutoDerrick::ExistKey()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type == m_type ) return true;
}
@ -573,11 +573,11 @@ bool CAutoDerrick::ExistKey()
}
// Returns an error due the state of the automaton.
// returns an error due the state of the automaton.
Error CAutoDerrick::RetError()
Error CAutoDerrick::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -62,7 +63,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
float m_lastTrack;
Math::Vector m_fretPos;
int m_soundChannel;

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autodestroyer.h"
#include "common/iman.h"
@ -24,7 +23,8 @@
#include "ui/interface.h"
#include "ui/window.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -61,7 +61,7 @@ void CAutoDestroyer::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
CAuto::Init();
}
@ -72,19 +72,19 @@ void CAutoDestroyer::Init()
bool CAutoDestroyer::EventProcess(const Event &event)
{
CObject* scrap;
CPyro* pyro;
Gfx::CPyro* pyro;
Math::Vector pos, speed;
Math::Point dim;
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -117,7 +117,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
}
else
{
m_sound->Play(SOUND_PSHHH2, m_object->RetPosition(0), 1.0f, 1.0f);
m_sound->Play(SOUND_PSHHH2, m_object->GetPosition(0), 1.0f, 1.0f);
m_phase = ADEP_DOWN;
m_progress = 0.0f;
@ -133,10 +133,10 @@ bool CAutoDestroyer::EventProcess(const Event &event)
if ( m_progress >= 0.3f-0.05f && !m_bExplo )
{
scrap = SearchPlastic();
if ( scrap != 0 )
if ( scrap != nullptr )
{
pyro = new CPyro(m_iMan);
pyro->Create(PT_FRAGT, scrap);
pyro = new Gfx::CPyro(m_iMan);
pyro->Create(Gfx::PT_FRAGT, scrap);
}
m_bExplo = true;
}
@ -150,7 +150,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
else
{
m_object->SetPosition(1, Math::Vector(0.0f, -10.0f, 0.0f));
m_sound->Play(SOUND_REPAIR, m_object->RetPosition(0));
m_sound->Play(SOUND_REPAIR, m_object->GetPosition(0));
m_phase = ADEP_REPAIR;
m_progress = 0.0f;
@ -165,7 +165,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
}
else
{
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 0.8f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 0.8f);
m_phase = ADEP_UP;
m_progress = 0.0f;
@ -199,7 +199,7 @@ bool CAutoDestroyer::EventProcess(const Event &event)
bool CAutoDestroyer::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -207,8 +207,8 @@ bool CAutoDestroyer::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return false;
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return false;
ox = 3.0f/640.0f;
oy = 3.0f/480.0f;
@ -235,23 +235,23 @@ CObject* CAutoDestroyer::SearchPlastic()
float dist;
int i;
sPos = m_object->RetPosition(0);
sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
if ( pObj == 0 ) break;
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == nullptr ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_SCRAP4 &&
type != OBJECT_SCRAP5 ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, sPos);
if ( dist <= 5.0f ) return pObj;
}
return 0;
return nullptr;
}
// Seeks if one vehicle is too close.
@ -264,14 +264,14 @@ bool CAutoDestroyer::SearchVehicle()
float oRadius, dist;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
if ( pObj == 0 ) break;
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == nullptr ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
@ -316,11 +316,11 @@ bool CAutoDestroyer::SearchVehicle()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoDestroyer::RetError()
Error CAutoDestroyer::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -362,11 +362,11 @@ bool CAutoDestroyer::Read(char *line)
CAuto::Read(line);
m_phase = (AutoDestroyerPhase)OpInt(line, "aPhase", ADEP_WAIT);
m_phase = static_cast< AutoDestroyerPhase >(OpInt(line, "aPhase", ADEP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -43,7 +44,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -59,7 +60,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
bool m_bExplo;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,15 +16,14 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoegg.h"
#include "math/geometry.h"
#include "common/iman.h"
#include "script/cmdtoken.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -61,8 +61,8 @@ void CAutoEgg::DeleteObject(bool bAll)
if ( alien != 0 )
{
// Probably the intended action
// Original code: ( alien->RetZoom(0) == 1.0f )
if ( alien->RetZoomY(0) == 1.0f )
// Original code: ( alien->GetZoom(0) == 1.0f )
if ( alien->GetZoomY(0) == 1.0f )
{
alien->SetLock(false);
alien->SetActivity(true); // the insect is active
@ -98,7 +98,7 @@ void CAutoEgg::Init()
m_speed = 1.0f/5.0f;
m_time = 0.0f;
m_type = alien->RetType();
m_type = alien->GetType();
if ( m_type == OBJECT_ANT ||
m_type == OBJECT_SPIDER ||
@ -164,9 +164,9 @@ bool CAutoEgg::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_phase == AEP_NULL ) return true;
if ( m_phase == AEP_DELAY )
@ -175,7 +175,7 @@ bool CAutoEgg::EventProcess(const Event &event)
if ( m_progress < 1.0f ) return true;
alien = new CObject(m_iMan);
if ( !alien->CreateInsect(m_object->RetPosition(0), m_object->RetAngleY(0), m_type) )
if ( !alien->CreateInsect(m_object->GetPosition(0), m_object->GetAngleY(0), m_type) )
{
delete alien;
m_phase = AEP_DELAY;
@ -213,7 +213,7 @@ bool CAutoEgg::EventProcess(const Event &event)
Error CAutoEgg::IsEnded()
{
CObject* alien;
CPyro* pyro;
Gfx::CPyro* pyro;
if ( m_phase == AEP_DELAY )
{
@ -236,8 +236,8 @@ Error CAutoEgg::IsEnded()
{
if ( m_progress < 1.0f ) return ERR_CONTINUE;
pyro = new CPyro(m_iMan);
pyro->Create(PT_EGG, m_object); // exploding egg
pyro = new Gfx::CPyro(m_iMan);
pyro->Create(Gfx::PT_EGG, m_object); // exploding egg
alien->SetZoom(0, 1.0f); // this is a big boy now
@ -258,9 +258,9 @@ Error CAutoEgg::IsEnded()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoEgg::RetError()
Error CAutoEgg::GetError()
{
return ERR_OK;
}
@ -277,23 +277,23 @@ CObject* CAutoEgg::SearchAlien()
float dist, min;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
min = 100000.0f;
pBest = 0;
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( pObj->RetTruck() != 0 ) continue;
if ( pObj->GetTruck() != 0 ) continue;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_ANT &&
type != OBJECT_BEE &&
type != OBJECT_SPIDER &&
type != OBJECT_WORM ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::DistanceProjected(oPos, cPos);
if ( dist < 8.0f && dist < min )
{
@ -347,7 +347,7 @@ bool CAutoEgg::Read(char *line)
CAuto::Read(line);
m_phase = (AutoEggPhase)OpInt(line, "aPhase", AEP_NULL);
m_phase = static_cast< AutoEggPhase >(OpInt(line, "aPhase", AEP_NULL));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_type = OpTypeObject(line, "aParamType", OBJECT_NULL);

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -45,7 +46,7 @@ public:
void Start(int param);
bool EventProcess(const Event &event);
Error IsEnded();
Error RetError();
Error GetError();
bool SetType(ObjectType type);
bool SetValue(int rank, float value);

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,12 +16,10 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoenergy.h"
#include "common/iman.h"
#include "old/terrain.h"
#include "graphics/engine/terrain.h"
#include "math/geometry.h"
#include "script/cmdtoken.h"
#include "ui/interface.h"
@ -28,6 +27,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float ENERGY_POWER = 0.4f; // Necessary energy for a battery
@ -60,7 +61,7 @@ void CAutoEnergy::DeleteObject(bool bAll)
if ( m_partiSphere != -1 )
{
m_particule->DeleteParticule(m_partiSphere);
m_particle->DeleteParticle(m_partiSphere);
m_partiSphere = -1;
}
@ -92,7 +93,7 @@ void CAutoEnergy::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastUpdateTime = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
m_phase = AENP_WAIT; // waiting ...
m_progress = 0.0f;
@ -109,35 +110,35 @@ bool CAutoEnergy::EventProcess(const Event &event)
CObject* fret;
Math::Vector pos, ppos, speed;
Math::Point dim, c, p;
TerrainRes res;
Gfx::TerrainRes res;
float big;
bool bGO;
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
m_timeVirus = 0.1f+Math::Rand()*0.3f;
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
pos = m_object->RetPosition(0);
m_lastParticle = m_time;
pos = m_object->GetPosition(0);
pos.y += 10.0f;
speed.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = -7.0f;
dim.x = Math::Rand()*0.5f+0.5f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFIREZ, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIREZ, 1.0f, 0.0f, 0.0f);
}
}
return true;
@ -146,10 +147,10 @@ bool CAutoEnergy::EventProcess(const Event &event)
UpdateInterface(event.rTime);
EventProgress(event.rTime);
big = m_object->RetEnergy();
big = m_object->GetEnergy();
res = m_terrain->RetResource(m_object->RetPosition(0));
if ( res == TR_POWER )
res = m_terrain->GetResource(m_object->GetPosition(0));
if ( res == Gfx::TR_POWER )
{
big += event.rTime*0.01f; // recharges the big pile
}
@ -162,7 +163,7 @@ bool CAutoEnergy::EventProcess(const Event &event)
fret = SearchMetal(); // transform metal?
if ( fret != 0 )
{
if ( fret->RetType() == OBJECT_METAL )
if ( fret->GetType() == OBJECT_METAL )
{
if ( big > ENERGY_POWER ) bGO = true;
}
@ -174,7 +175,7 @@ bool CAutoEnergy::EventProcess(const Event &event)
if ( bGO )
{
if ( fret->RetType() == OBJECT_METAL )
if ( fret->GetType() == OBJECT_METAL )
{
fret->SetLock(true); // usable metal
CreatePower(); // creates the battery
@ -184,12 +185,12 @@ bool CAutoEnergy::EventProcess(const Event &event)
InitProgressTotal(ENERGY_DELAY);
CAuto::UpdateInterface();
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 4.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 3.0f;
dim.y = dim.x;
m_partiSphere = m_particule->CreateParticule(pos, speed, dim, PARTISPHERE1, ENERGY_DELAY, 0.0f, 0.0f);
m_partiSphere = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISPHERE1, ENERGY_DELAY, 0.0f, 0.0f);
m_phase = AENP_CREATE;
m_progress = 0.0f;
@ -217,17 +218,17 @@ bool CAutoEnergy::EventProcess(const Event &event)
{
if ( m_progress < 1.0f && big > 0.01f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
pos = m_object->RetPosition(0);
m_lastParticle = m_time;
pos = m_object->GetPosition(0);
pos.y += 10.0f;
speed.x = (Math::Rand()-0.5f)*1.0f;
speed.z = (Math::Rand()-0.5f)*1.0f;
speed.y = -7.0f;
dim.x = Math::Rand()*0.5f+0.5f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFIREZ, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIREZ, 1.0f, 0.0f, 0.0f);
}
}
else
@ -245,7 +246,7 @@ bool CAutoEnergy::EventProcess(const Event &event)
fret = SearchMetal();
if ( fret != 0 )
{
if ( fret->RetType() == OBJECT_METAL )
if ( fret->GetType() == OBJECT_METAL )
{
big -= event.rTime/ENERGY_DELAY*ENERGY_POWER;
}
@ -262,11 +263,11 @@ bool CAutoEnergy::EventProcess(const Event &event)
fret->SetZoom(0, m_progress);
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
c.x = pos.x;
c.y = pos.z;
p.x = c.x;
@ -278,27 +279,27 @@ bool CAutoEnergy::EventProcess(const Event &event)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*2.0f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGLINT, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 1.0f, 0.0f, 0.0f);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 3.0f;
speed.x = (Math::Rand()-0.5f)*30.0f;
speed.z = (Math::Rand()-0.5f)*30.0f;
speed.y = Math::Rand()*20.0f+10.0f;
dim.x = Math::Rand()*0.4f+0.4f;
dim.y = dim.x;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK2, 2.0f, 50.0f, 1.2f, 1.2f);
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK2, 2.0f, 50.0f, 1.2f, 1.2f);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 10.0f;
speed.x = (Math::Rand()-0.5f)*1.5f;
speed.z = (Math::Rand()-0.5f)*1.5f;
speed.y = -6.0f;
dim.x = Math::Rand()*1.0f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFIREZ, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIREZ, 1.0f, 0.0f, 0.0f);
m_sound->Play(SOUND_ENERGY, m_object->RetPosition(0),
m_sound->Play(SOUND_ENERGY, m_object->GetPosition(0),
1.0f, 1.0f+Math::Rand()*1.5f);
}
}
@ -337,11 +338,11 @@ bool CAutoEnergy::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 17.0f;
pos.x += (Math::Rand()-0.5f)*3.0f;
pos.z += (Math::Rand()-0.5f)*3.0f;
@ -350,7 +351,7 @@ bool CAutoEnergy::EventProcess(const Event &event)
speed.y = 6.0f+Math::Rand()*6.0f;
dim.x = Math::Rand()*1.5f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f);
}
}
else
@ -376,10 +377,10 @@ CObject* CAutoEnergy::SearchMetal()
CObject* pObj;
ObjectType type;
pObj = m_object->RetPower();
pObj = m_object->GetPower();
if ( pObj == 0 ) return 0;
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_METAL ||
type == OBJECT_SCRAP1 ||
type == OBJECT_SCRAP2 ||
@ -398,14 +399,14 @@ bool CAutoEnergy::SearchVehicle()
float oRadius, dist;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
@ -457,8 +458,8 @@ void CAutoEnergy::CreatePower()
Math::Vector pos;
float angle;
pos = m_object->RetPosition(0);
angle = m_object->RetAngleY(0);
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
power = new CObject(m_iMan);
if ( !power->CreateResource(pos, angle, OBJECT_POWER) )
@ -469,7 +470,7 @@ void CAutoEnergy::CreatePower()
}
power->SetLock(true); // battery not yet usable
pos = power->RetPosition(0);
pos = power->GetPosition(0);
pos.y += 3.0f;
power->SetPosition(0, pos);
}
@ -483,19 +484,19 @@ CObject* CAutoEnergy::SearchPower()
ObjectType type;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( !pObj->RetLock() ) continue;
if ( !pObj->GetLock() ) continue;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_POWER ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
if ( oPos.x == cPos.x &&
oPos.z == cPos.z )
{
@ -507,15 +508,15 @@ CObject* CAutoEnergy::SearchPower()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoEnergy::RetError()
Error CAutoEnergy::GetError()
{
CObject* pObj;
ObjectType type;
TerrainRes res;
Gfx::TerrainRes res;
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -523,14 +524,14 @@ Error CAutoEnergy::RetError()
if ( m_phase != AENP_WAIT &&
m_phase != AENP_BLITZ ) return ERR_OK;
res = m_terrain->RetResource(m_object->RetPosition(0));
if ( res != TR_POWER ) return ERR_ENERGY_NULL;
res = m_terrain->GetResource(m_object->GetPosition(0));
if ( res != Gfx::TR_POWER ) return ERR_ENERGY_NULL;
if ( m_object->RetEnergy() < ENERGY_POWER ) return ERR_ENERGY_LOW;
if ( m_object->GetEnergy() < ENERGY_POWER ) return ERR_ENERGY_LOW;
pObj = m_object->RetPower();
pObj = m_object->GetPower();
if ( pObj == 0 ) return ERR_ENERGY_EMPTY;
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_POWER ) return ERR_OK;
if ( type != OBJECT_METAL &&
type != OBJECT_SCRAP1 &&
@ -545,7 +546,7 @@ Error CAutoEnergy::RetError()
bool CAutoEnergy::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -553,7 +554,7 @@ bool CAutoEnergy::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -581,23 +582,23 @@ bool CAutoEnergy::CreateInterface(bool bSelect)
void CAutoEnergy::UpdateInterface(float rTime)
{
CWindow* pw;
CGauge* pg;
Ui::CWindow* pw;
Ui::CGauge* pg;
CAuto::UpdateInterface(rTime);
if ( m_time < m_lastUpdateTime+0.1f ) return;
m_lastUpdateTime = m_time;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
pg = (CGauge*)pw->SearchControl(EVENT_OBJECT_GENERGY);
pg = static_cast< Ui::CGauge* >(pw->SearchControl(EVENT_OBJECT_GENERGY));
if ( pg != 0 )
{
pg->SetLevel(m_object->RetEnergy());
pg->SetLevel(m_object->GetEnergy());
}
}
@ -636,12 +637,12 @@ bool CAutoEnergy::Read(char *line)
CAuto::Read(line);
m_phase = (AutoEnergyPhase)OpInt(line, "aPhase", AENP_WAIT);
m_phase = static_cast< AutoEnergyPhase >(OpInt(line, "aPhase", AENP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastUpdateTime = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -65,7 +66,7 @@ protected:
float m_speed;
float m_timeVirus;
float m_lastUpdateTime;
float m_lastParticule;
float m_lastParticle;
int m_partiSphere;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autofactory.h"
#include "common/global.h"
@ -29,7 +28,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
@ -95,9 +95,9 @@ void CAutoFactory::Init()
m_speed = 1.0f/2.0f;
m_time = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
m_fretPos = m_object->RetPosition(0);
m_fretPos = m_object->GetPosition(0);
CAuto::Init();
}
@ -119,37 +119,37 @@ bool CAutoFactory::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
if ( m_object->RetSelect() ) // factory selected?
if ( m_object->GetSelect() ) // factory selected?
{
if ( event.event == EVENT_UPDINTERFACE )
if ( event.type == EVENT_UPDINTERFACE )
{
CreateInterface(true);
}
type = OBJECT_NULL;
if ( event.event == EVENT_OBJECT_FACTORYwa ) type = OBJECT_MOBILEwa;
if ( event.event == EVENT_OBJECT_FACTORYta ) type = OBJECT_MOBILEta;
if ( event.event == EVENT_OBJECT_FACTORYfa ) type = OBJECT_MOBILEfa;
if ( event.event == EVENT_OBJECT_FACTORYia ) type = OBJECT_MOBILEia;
if ( event.event == EVENT_OBJECT_FACTORYws ) type = OBJECT_MOBILEws;
if ( event.event == EVENT_OBJECT_FACTORYts ) type = OBJECT_MOBILEts;
if ( event.event == EVENT_OBJECT_FACTORYfs ) type = OBJECT_MOBILEfs;
if ( event.event == EVENT_OBJECT_FACTORYis ) type = OBJECT_MOBILEis;
if ( event.event == EVENT_OBJECT_FACTORYwc ) type = OBJECT_MOBILEwc;
if ( event.event == EVENT_OBJECT_FACTORYtc ) type = OBJECT_MOBILEtc;
if ( event.event == EVENT_OBJECT_FACTORYfc ) type = OBJECT_MOBILEfc;
if ( event.event == EVENT_OBJECT_FACTORYic ) type = OBJECT_MOBILEic;
if ( event.event == EVENT_OBJECT_FACTORYwi ) type = OBJECT_MOBILEwi;
if ( event.event == EVENT_OBJECT_FACTORYti ) type = OBJECT_MOBILEti;
if ( event.event == EVENT_OBJECT_FACTORYfi ) type = OBJECT_MOBILEfi;
if ( event.event == EVENT_OBJECT_FACTORYii ) type = OBJECT_MOBILEii;
if ( event.event == EVENT_OBJECT_FACTORYrt ) type = OBJECT_MOBILErt;
if ( event.event == EVENT_OBJECT_FACTORYrc ) type = OBJECT_MOBILErc;
if ( event.event == EVENT_OBJECT_FACTORYrr ) type = OBJECT_MOBILErr;
if ( event.event == EVENT_OBJECT_FACTORYrs ) type = OBJECT_MOBILErs;
if ( event.event == EVENT_OBJECT_FACTORYsa ) type = OBJECT_MOBILEsa;
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;
if ( type != OBJECT_NULL )
{
@ -186,7 +186,7 @@ bool CAutoFactory::EventProcess(const Event &event)
}
}
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
EventProgress(event.rTime);
@ -249,7 +249,7 @@ bool CAutoFactory::EventProcess(const Event &event)
m_object->SetAngleZ(10+i, 0.0f);
}
m_channelSound = m_sound->Play(SOUND_FACTORY, m_object->RetPosition(0), 0.0f, 1.0f, true);
m_channelSound = m_sound->Play(SOUND_FACTORY, 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, 11.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
@ -300,7 +300,7 @@ bool CAutoFactory::EventProcess(const Event &event)
{
prog = 1.0f-m_progress;
}
angle = powf(prog*10.0f, 2.0f)+m_object->RetAngleY(0);
angle = powf(prog*10.0f, 2.0f)+m_object->GetAngleY(0);
vehicle = SearchVehicle();
if ( vehicle != 0 )
@ -315,9 +315,9 @@ bool CAutoFactory::EventProcess(const Event &event)
fret->SetZoom(0, 1.0f-m_progress);
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
#if 0
pos = m_fretPos;
@ -329,9 +329,9 @@ bool CAutoFactory::EventProcess(const Event &event)
speed.y = Math::Rand()*12.0f;
dim.x = Math::Rand()*12.0f+10.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
#else
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
pos = Math::Vector(-12.0f, 20.0f, -4.0f); // position of chimney
pos = Math::Transform(*mat, pos);
pos.y += 2.0f;
@ -342,7 +342,7 @@ bool CAutoFactory::EventProcess(const Event &event)
speed.y = 6.0f+Math::Rand()*6.0f;
dim.x = Math::Rand()*1.5f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f);
#endif
}
}
@ -361,15 +361,15 @@ bool CAutoFactory::EventProcess(const Event &event)
vehicle = SearchVehicle();
if ( vehicle != 0 )
{
physics = vehicle->RetPhysics();
physics = vehicle->GetPhysics();
if ( physics != 0 )
{
physics->SetFreeze(false); // can move
}
vehicle->SetLock(false); // vehicle useable
//? vehicle->RetPhysics()->RetBrain()->StartTaskAdvance(16.0f);
vehicle->SetAngleY(0, m_object->RetAngleY(0)+Math::PI);
//? vehicle->GetPhysics()->GetBrain()->StartTaskAdvance(16.0f);
vehicle->SetAngleY(0, m_object->GetAngleY(0)+Math::PI);
vehicle->SetZoom(0, 1.0f);
}
@ -392,9 +392,9 @@ bool CAutoFactory::EventProcess(const Event &event)
m_object->SetAngleZ(10+i, -angle);
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.1f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_fretPos;
pos.x += (Math::Rand()-0.5f)*10.0f;
@ -403,7 +403,7 @@ bool CAutoFactory::EventProcess(const Event &event)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGLINT, 2.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
}
}
else
@ -435,9 +435,9 @@ bool CAutoFactory::EventProcess(const Event &event)
m_object->SetZoomZ(10+i, zoom);
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.1f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_fretPos;
pos.x += (Math::Rand()-0.5f)*10.0f;
@ -446,7 +446,7 @@ bool CAutoFactory::EventProcess(const Event &event)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIGLINT, 2.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
}
}
else
@ -503,12 +503,12 @@ bool CAutoFactory::Read(char *line)
CAuto::Read(line);
m_phase = (AutoFactoryPhase)OpInt(line, "aPhase", AFP_WAIT);
m_phase = static_cast< AutoFactoryPhase >(OpInt(line, "aPhase", AFP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_fretPos = m_object->RetPosition(0);
m_lastParticle = 0.0f;
m_fretPos = m_object->GetPosition(0);
return true;
}
@ -526,14 +526,14 @@ CObject* CAutoFactory::SearchFret()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_METAL ) continue;
if ( pObj->RetTruck() != 0 ) continue;
if ( pObj->GetTruck() != 0 ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, m_fretPos);
if ( dist < 8.0f ) return pObj;
@ -552,14 +552,14 @@ bool CAutoFactory::NearestVehicle()
float oRadius, dist;
int i;
cPos = m_object->RetPosition(0);
cPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
@ -616,9 +616,9 @@ bool CAutoFactory::CreateVehicle()
char* name;
int i;
angle = m_object->RetAngleY(0);
angle = m_object->GetAngleY(0);
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
if ( m_type == OBJECT_MOBILErt ||
m_type == OBJECT_MOBILErc ||
m_type == OBJECT_MOBILErr ||
@ -643,7 +643,7 @@ bool CAutoFactory::CreateVehicle()
vehicle->SetLock(true); // not usable
vehicle->SetRange(30.0f);
physics = vehicle->RetPhysics();
physics = vehicle->GetPhysics();
if ( physics != 0 )
{
physics->SetFreeze(true); // it doesn't move
@ -651,7 +651,7 @@ bool CAutoFactory::CreateVehicle()
for ( i=0 ; i<10 ; i++ )
{
name = m_main->RetNewScriptName(m_type, i);
name = m_main->GetNewScriptName(m_type, i);
if ( name == 0 ) break;
vehicle->ReadProgram(i, name);
}
@ -671,16 +671,16 @@ CObject* CAutoFactory::SearchVehicle()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( !pObj->RetLock() ) continue;
if ( !pObj->GetLock() ) continue;
type = pObj->RetType();
type = pObj->GetType();
if ( type != m_type ) continue;
if ( pObj->RetTruck() != 0 ) continue;
if ( pObj->GetTruck() != 0 ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, m_fretPos);
if ( dist < 8.0f ) return pObj;
@ -694,7 +694,7 @@ CObject* CAutoFactory::SearchVehicle()
bool CAutoFactory::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
@ -702,8 +702,8 @@ bool CAutoFactory::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return false;
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return false;
dim.x = 33.0f/640.0f;
dim.y = 33.0f/480.0f;
@ -786,13 +786,13 @@ bool CAutoFactory::CreateInterface(bool bSelect)
void CAutoFactory::UpdateInterface()
{
CWindow* pw;
Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
UpdateButton(pw, EVENT_OBJECT_FACTORYwa, m_bBusy);
UpdateButton(pw, EVENT_OBJECT_FACTORYta, m_bBusy);
@ -819,7 +819,7 @@ void CAutoFactory::UpdateInterface()
// Updates the status of one interface button.
void CAutoFactory::UpdateButton(CWindow *pw, EventMsg event, bool bBusy)
void CAutoFactory::UpdateButton(Ui::CWindow *pw, EventType event, bool bBusy)
{
bool bEnable = true;
@ -933,7 +933,7 @@ void CAutoFactory::SoundManip(float time, float amplitude, float frequency)
{
int i;
i = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.0f, 0.3f*frequency, true);
i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.3f*frequency, true);
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, 0.1f, SOPER_CONTINUE);
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);

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -54,7 +55,7 @@ public:
protected:
void UpdateInterface();
void UpdateButton(CWindow *pw, EventMsg event, bool bBusy);
void UpdateButton(Ui::CWindow *pw, EventType event, bool bBusy);
CObject* SearchFret();
bool NearestVehicle();
@ -67,7 +68,7 @@ protected:
AutoFactoryPhase m_phase;
float m_progress;
float m_speed;
float m_lastParticule;
float m_lastParticle;
Math::Vector m_fretPos;
int m_channelSound;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,12 +16,12 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoflag.h"
#include "math/geometry.h"
#include "old/terrain.h"
#include "graphics/engine/terrain.h"
#include <stdio.h>
@ -68,7 +69,7 @@ void CAutoFlag::Init()
m_param = 0;
m_progress = 0.0f;
wind = m_terrain->RetWind();
wind = m_terrain->GetWind();
angle = Math::RotateAngle(wind.x, -wind.z);
m_object->SetAngleY(0, angle); // directs the flag in the wind
@ -98,7 +99,7 @@ bool CAutoFlag::EventProcess(const Event &event)
CAuto::EventProcess(event);
#if ADJUST_ANGLE
if ( event.event == EVENT_KEYDOWN )
if ( event.type == EVENT_KEYDOWN )
{
if ( event.param == 'E' ) g_flag1 += 0.1f;
if ( event.param == 'D' ) g_flag1 -= 0.1f;
@ -109,8 +110,8 @@ bool CAutoFlag::EventProcess(const Event &event)
}
#endif
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_param == 1 ) // shakes?
{
@ -152,9 +153,9 @@ bool CAutoFlag::EventProcess(const Event &event)
}
// Returns an error due the state of the automation
// Geturns an error due the state of the automation
Error CAutoFlag::RetError()
Error CAutoFlag::GetError()
{
return ERR_OK;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -34,7 +35,7 @@ public:
void Init();
void Start(int param);
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
protected:

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,14 +16,12 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autohuston.h"
#include "ui/interface.h"
#include "ui/window.h"
#include <stdio.h>
// Object's constructor.
@ -38,11 +37,11 @@ CAutoHuston::CAutoHuston(CInstanceManager* iMan, CObject* object)
m_lens[i].parti = -1;
}
pos = m_object->RetPosition(0);
m_lens[0].type = PARTISELR;
m_lens[1].type = PARTISELR;
m_lens[2].type = PARTISELR;
m_lens[3].type = PARTISELR;
pos = m_object->GetPosition(0);
m_lens[0].type = Gfx::PARTISELR;
m_lens[1].type = Gfx::PARTISELR;
m_lens[2].type = Gfx::PARTISELR;
m_lens[3].type = Gfx::PARTISELR;
m_lens[0].pos = pos+Math::Vector(0.0f+13.0f, 34.0f, 30.0f );
m_lens[1].pos = pos+Math::Vector(0.0f-13.0f, 34.0f, 30.0f );
m_lens[2].pos = pos+Math::Vector(0.0f , 34.0f, 30.0f+13.0f);
@ -62,46 +61,46 @@ CAutoHuston::CAutoHuston(CInstanceManager* iMan, CObject* object)
// Part under the radar.
i = 4;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, 40.1f);
m_lens[i].dim = 1.8f;
m_lens[i].total = 0.4f;
m_lens[i].off = 0.2f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f;
i ++;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f;
i ++;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 1.0f;
m_lens[i].off = 0.5f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, 14.0f);
m_lens[i].dim = 1.2f;
m_lens[i].total = 0.8f;
m_lens[i].off = 0.2f;
i ++;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(4.0f, 6.0f, 8.6f);
m_lens[i].dim = 1.0f;
m_lens[i].total = 0.9f;
@ -109,53 +108,53 @@ CAutoHuston::CAutoHuston(CInstanceManager* iMan, CObject* object)
i ++;
// Part with three windows.
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 9.9f, -19.9f);
m_lens[i].dim = 1.0f;
m_lens[i].total = 0.6f;
m_lens[i].off = 0.3f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 7.2f, 34.8f-60.0f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.7f;
m_lens[i].off = 0.3f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 34.3f-60.0f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f;
i ++;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.4f-60.0f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.6f;
m_lens[i].off = 0.4f;
i ++;
m_lens[i].type = PARTISELR;
m_lens[i].type = Gfx::PARTISELR;
m_lens[i].pos = pos+Math::Vector(-7.0f, 6.5f, 33.0f-60.0f);
m_lens[i].dim = 0.4f;
m_lens[i].total = 0.8f;
m_lens[i].off = 0.2f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-6.5f, 13.5f, -37.0f);
m_lens[i].dim = 1.0f;
m_lens[i].total = 0.0f;
m_lens[i].off = 0.0f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 12.2f, -39.8f);
m_lens[i].dim = 1.8f;
m_lens[i].total = 1.5f;
m_lens[i].off = 0.5f;
i ++;
m_lens[i].type = PARTISELY;
m_lens[i].type = Gfx::PARTISELY;
m_lens[i].pos = pos+Math::Vector(-7.0f, 8.5f, -47.0f);
m_lens[i].dim = 0.6f;
m_lens[i].total = 0.7f;
@ -211,14 +210,14 @@ bool CAutoHuston::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
angle = -m_time*1.0f;
m_object->SetAngleY(1, angle); // rotates the radar
angle = sinf(m_time*4.0f)*0.3f;
m_object->SetAngleX(2, angle);
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
@ -231,7 +230,7 @@ bool CAutoHuston::EventProcess(const Event &event)
{
if ( m_lens[i].parti != -1 )
{
m_particule->DeleteParticule(m_lens[i].parti);
m_particle->DeleteParticle(m_lens[i].parti);
m_lens[i].parti = -1;
}
}
@ -241,7 +240,7 @@ bool CAutoHuston::EventProcess(const Event &event)
{
dim.x = m_lens[i].dim;
dim.y = dim.x;
m_lens[i].parti = m_particule->CreateParticule(m_lens[i].pos, speed, dim, m_lens[i].type, 1.0f, 0.0f, 0.0f);
m_lens[i].parti = m_particle->CreateParticle(m_lens[i].pos, speed, dim, m_lens[i].type, 1.0f, 0.0f, 0.0f);
}
}
}
@ -261,7 +260,7 @@ bool CAutoHuston::Abort()
bool CAutoHuston::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -269,8 +268,8 @@ bool CAutoHuston::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return false;
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return false;
ox = 3.0f/640.0f;
oy = 3.0f/480.0f;
@ -287,9 +286,9 @@ bool CAutoHuston::CreateInterface(bool bSelect)
}
// Returns an error due to state of the automation.
// Geturns an error due to state of the automation.
Error CAutoHuston::RetError()
Error CAutoHuston::GetError()
{
return ERR_OK;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -20,18 +21,18 @@
#include "object/auto/auto.h"
#include "old/particule.h"
#include "graphics/engine/particle.h"
struct HustonLens
{
int parti;
ParticuleType type;
int parti;
Gfx::ParticleType type;
Math::Vector pos;
float dim;
float total;
float off;
float dim;
float total;
float off;
};
@ -50,7 +51,7 @@ public:
void Start(int param);
bool EventProcess(const Event &event);
bool Abort();
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoinfo.h"
#include "script/cmdtoken.h"
@ -24,7 +23,8 @@
#include "ui/list.h"
#include "ui/window.h"
#include <stdio.h>
#include <string.h>
@ -90,8 +90,8 @@ void CAutoInfo::Start(int param)
m_speed = 1.0f/2.0f;
}
m_lastParticule = 0;
m_goal = m_object->RetPosition(0);
m_lastParticle = 0;
m_goal = m_object->GetPosition(0);
if ( m_phase == AIP_EMETTE )
{
@ -100,7 +100,7 @@ void CAutoInfo::Start(int param)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 30.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISPHERE4, 1.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISPHERE4, 1.5f, 0.0f, 0.0f);
m_sound->Play(SOUND_LABO, pos, 1.0f, 2.0f);
}
@ -111,7 +111,7 @@ void CAutoInfo::Start(int param)
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 50.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISPHERE6, 1.5f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISPHERE6, 1.5f, 0.0f, 0.0f);
m_sound->Play(SOUND_LABO, pos, 1.0f, 2.0f);
}
@ -133,18 +133,18 @@ bool CAutoInfo::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
m_timeVirus = 0.1f+Math::Rand()*0.3f;
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle += Math::Rand()*0.3f;
m_object->SetAngleY(1, angle);
@ -170,7 +170,7 @@ bool CAutoInfo::EventProcess(const Event &event)
}
else
{
if ( m_object->RetInfoUpdate() )
if ( m_object->GetInfoUpdate() )
{
UpdateList(); // updates the list
}
@ -184,9 +184,9 @@ bool CAutoInfo::EventProcess(const Event &event)
if ( m_phase == AIP_EMETTE ) // instruction "receive" ?
{
if ( m_progress < 0.5f &&
m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
for ( i=0 ; i<4 ; i++ )
{
@ -199,7 +199,7 @@ bool CAutoInfo::EventProcess(const Event &event)
dim.x = 0.6f;
dim.y = dim.x;
duration = Math::Rand()*0.5f+0.5f;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK6,
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK6,
duration, 0.0f,
duration*0.9f, 0.7f);
}
@ -230,9 +230,9 @@ bool CAutoInfo::EventProcess(const Event &event)
if ( m_phase == AIP_RECEIVE ) // instruction "send" ?
{
if ( m_progress < 0.5f &&
m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
for ( i=0 ; i<4 ; i++ )
{
@ -247,7 +247,7 @@ bool CAutoInfo::EventProcess(const Event &event)
dim.x = 0.6f;
dim.y = dim.x;
duration = Math::Rand()*0.5f+0.5f;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK6,
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK6,
duration, 0.0f,
duration*0.9f, 0.7f);
}
@ -278,9 +278,9 @@ bool CAutoInfo::EventProcess(const Event &event)
if ( m_phase == AIP_ERROR )
{
if ( m_progress < 0.5f &&
m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_goal;
speed.x = (Math::Rand()-0.5f)*5.0f;
@ -289,7 +289,7 @@ bool CAutoInfo::EventProcess(const Event &event)
dim.x = 5.0f+Math::Rand()*5.0f;
dim.y = dim.x;
duration = Math::Rand()*0.5f+0.5f;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE1, 4.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE1, 4.0f);
}
if ( m_progress < 1.0f )
@ -327,7 +327,7 @@ bool CAutoInfo::EventProcess(const Event &event)
}
}
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle += rTime*0.5f;
m_object->SetAngleY(1, angle);
@ -339,11 +339,11 @@ bool CAutoInfo::EventProcess(const Event &event)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoInfo::RetError()
Error CAutoInfo::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -356,8 +356,8 @@ Error CAutoInfo::RetError()
bool CAutoInfo::CreateInterface(bool bSelect)
{
CWindow* pw;
CList* pl;
Ui::CWindow* pw;
Ui::CList* pl;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -365,7 +365,7 @@ bool CAutoInfo::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -403,31 +403,31 @@ void CAutoInfo::UpdateInterface(float rTime)
void CAutoInfo::UpdateList()
{
CWindow* pw;
CList* pl;
Ui::CWindow* pw;
Ui::CList* pl;
Info info;
int total, i;
char text[100];
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
if ( pw == 0 ) return;
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == nullptr ) return;
pl = (CList*)pw->SearchControl(EVENT_OBJECT_GINFO);
if ( pl == 0 ) return;
pl = static_cast< Ui::CList* >(pw->SearchControl(EVENT_OBJECT_GINFO));
if ( pl == nullptr ) return;
pl->Flush();
total = m_object->RetInfoTotal();
total = m_object->GetInfoTotal();
if ( total == 0 )
{
pl->ClearState(STATE_ENABLE);
pl->ClearState(Ui::STATE_ENABLE);
}
else
{
pl->SetState(STATE_ENABLE);
pl->SetState(Ui::STATE_ENABLE);
for ( i=0 ; i<total ; i++ )
{
info = m_object->RetInfo(i);
info = m_object->GetInfo(i);
sprintf(text, "%s = %.2f", info.name, info.value);
pl->SetName(i, text);
}
@ -440,28 +440,28 @@ void CAutoInfo::UpdateList()
void CAutoInfo::UpdateListVirus()
{
CWindow* pw;
CList* pl;
Ui::CWindow* pw;
Ui::CList* pl;
int i, j, max;
char text[100];
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
pl = (CList*)pw->SearchControl(EVENT_OBJECT_GINFO);
pl = static_cast< Ui::CList* >(pw->SearchControl(EVENT_OBJECT_GINFO));
if ( pl == 0 ) return;
pl->SetState(STATE_ENABLE);
pl->SetState(Ui::STATE_ENABLE);
pl->Flush();
for ( i=0 ; i<4 ; i++ )
{
max = (int)(2.0f+Math::Rand()*10.0f);
max = static_cast< int >(2.0f+Math::Rand()*10.0f);
for ( j=0 ; j<max ; j++ )
{
do
{
text[j] = ' '+(int)(Math::Rand()*94.0f);
text[j] = ' '+static_cast< int >(Math::Rand()*94.0f);
}
while ( text[j] == '\\' );
}
@ -505,11 +505,11 @@ bool CAutoInfo::Read(char *line)
CAuto::Read(line);
m_phase = (AutoInfoPhase)OpInt(line, "aPhase", AIP_WAIT);
m_phase = static_cast< AutoInfoPhase > (OpInt(line, "aPhase", AIP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
void Start(int param);
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -61,7 +62,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
Math::Vector m_goal;
bool m_bLastVirus;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,11 +16,9 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autojostle.h"
#include <stdio.h>
// Object's constructor.
@ -71,7 +70,7 @@ void CAutoJostle::Start(int param, float force)
m_time = 0.0f;
m_error = ERR_CONTINUE;
type = m_object->RetType();
type = m_object->GetType();
if ( type >= OBJECT_PLANT5 &&
type <= OBJECT_PLANT7 ) // clover?
{
@ -89,8 +88,8 @@ bool CAutoJostle::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_progress < 1.0f )
{

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012 Polish Portal of Colobot (PPC)
// *
// * 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
@ -42,7 +43,7 @@ protected:
float m_force;
float m_progress;
float m_speed;
float m_lastParticule;
float m_lastParticle;
Error m_error;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,13 +16,12 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autokid.h"
#include "old/particule.h"
#include "old/water.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/water.h"
#include <stdio.h>
// Object's constructor.
@ -62,18 +62,18 @@ void CAutoKid::Init()
m_speed = 1.0f/1.0f;
m_progress = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
if ( m_type == OBJECT_TEEN36 ) // trunk ?
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f));
m_progress = Math::Mod(pos.x/10.0f, 1.0f);
}
if ( m_type == OBJECT_TEEN37 ) // boat?
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
m_speed = 1.0f/(1.0f+(Math::Mod(pos.x/10.0f-0.5f, 1.0f)*0.2f))*2.5f;
m_progress = Math::Mod(pos.x/10.0f, 1.0f);
}
@ -82,7 +82,7 @@ void CAutoKid::Init()
{
if ( m_soundChannel == -1 )
{
//? m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 1.0f, 0.5f, true);
//? m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 1.0f, 0.5f, true);
m_bSilent = false;
}
}
@ -100,7 +100,7 @@ bool CAutoKid::EventProcess(const Event &event)
if ( m_soundChannel != -1 )
{
if ( m_engine->RetPause() )
if ( m_engine->GetPause() )
{
if ( !m_bSilent )
{
@ -118,8 +118,8 @@ bool CAutoKid::EventProcess(const Event &event)
}
}
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
@ -135,12 +135,12 @@ bool CAutoKid::EventProcess(const Event &event)
vib.z = sinf(m_progress*0.5f)*0.05f;
m_object->SetCirVibration(vib);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.15f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.15f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos.y = m_water->RetLevel()+1.0f;
pos = m_object->GetPosition(0);
pos.y = m_water->GetLevel()+1.0f;
pos.x += (Math::Rand()-0.5f)*50.0f;
pos.z += (Math::Rand()-0.5f)*50.0f;
speed.y = 0.0f;
@ -148,7 +148,7 @@ bool CAutoKid::EventProcess(const Event &event)
speed.z = 0.0f;
dim.x = 50.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFLIC, 3.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f);
}
}
@ -164,12 +164,12 @@ bool CAutoKid::EventProcess(const Event &event)
vib.z = sinf(m_progress*0.5f)*0.15f;
m_object->SetCirVibration(vib);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.15f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.15f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos.y = m_water->RetLevel()+1.0f;
pos = m_object->GetPosition(0);
pos.y = m_water->GetLevel()+1.0f;
pos.x += (Math::Rand()-0.5f)*20.0f;
pos.z += (Math::Rand()-0.5f)*20.0f;
speed.y = 0.0f;
@ -177,7 +177,7 @@ bool CAutoKid::EventProcess(const Event &event)
speed.z = 0.0f;
dim.x = 20.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIFLIC, 3.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFLIC, 3.0f, 0.0f, 0.0f);
}
}
@ -191,9 +191,9 @@ bool CAutoKid::EventProcess(const Event &event)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoKid::RetError()
Error CAutoKid::GetError()
{
return ERR_OK;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -33,14 +34,14 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
protected:
protected:
float m_speed;
float m_progress;
float m_lastParticule;
float m_lastParticle;
int m_soundChannel;
bool m_bSilent;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autolabo.h"
#include "common/global.h"
@ -28,6 +27,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float LABO_DELAY = 20.0f; // duration of the analysis
@ -69,14 +70,14 @@ void CAutoLabo::DeleteObject(bool bAll)
{
if ( m_partiRank[i] != -1 )
{
m_particule->DeleteParticule(m_partiRank[i]);
m_particle->DeleteParticle(m_partiRank[i]);
m_partiRank[i] = -1;
}
}
if ( m_partiSphere != -1 )
{
m_particule->DeleteParticule(m_partiSphere);
m_particle->DeleteParticle(m_partiSphere);
m_partiSphere = -1;
}
@ -97,7 +98,7 @@ void CAutoLabo::Init()
{
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
m_phase = ALAP_WAIT; // waiting ...
m_progress = 0.0f;
@ -119,23 +120,23 @@ bool CAutoLabo::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.event == EVENT_UPDINTERFACE )
if ( event.type == EVENT_UPDINTERFACE )
{
if ( m_object->RetSelect() ) CreateInterface(true);
if ( m_object->GetSelect() ) CreateInterface(true);
}
if ( m_object->RetSelect() && // center selected?
(event.event == EVENT_OBJECT_RiPAW ||
event.event == EVENT_OBJECT_RiGUN) )
if ( m_object->GetSelect() && // center selected?
(event.type == EVENT_OBJECT_RiPAW ||
event.type == EVENT_OBJECT_RiGUN) )
{
if ( m_phase != ALAP_WAIT )
{
return false;
}
m_research = event.event;
m_research = event.type;
if ( TestResearch(m_research) )
{
@ -143,13 +144,13 @@ bool CAutoLabo::EventProcess(const Event &event)
return false;
}
power = m_object->RetPower();
power = m_object->GetPower();
if ( power == 0 )
{
m_displayText->DisplayError(ERR_LABO_NULL, m_object);
return false;
}
if ( power->RetType() != OBJECT_BULLET )
if ( power->GetType() != OBJECT_BULLET )
{
m_displayText->DisplayError(ERR_LABO_BAD, m_object);
return false;
@ -168,12 +169,12 @@ bool CAutoLabo::EventProcess(const Event &event)
return true;
}
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -247,31 +248,32 @@ bool CAutoLabo::EventProcess(const Event &event)
{
m_object->SetAngleZ(1, 0.0f);
goal = m_object->RetPosition(0);
goal = m_object->GetPosition(0);
goal.y += 3.0f;
pos = goal;
pos.x -= 4.0f;
pos.y += 4.0f;
for ( i=0 ; i<3 ; i++ )
{
m_partiRank[i] = m_particule->CreateRay(pos, goal,
PARTIRAY2,
m_partiRank[i] = m_particle->CreateRay(pos, goal,
Gfx::PARTIRAY2,
Math::Point(2.9f, 2.9f),
LABO_DELAY);
}
m_soundChannel = m_sound->Play(SOUND_LABO, m_object->RetPosition(0), 0.0f, 0.25f, true);
m_soundChannel = m_sound->Play(SOUND_LABO, m_object->GetPosition(0), 0.0f, 0.25f, true);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.60f, 2.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 2.00f, 8.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.60f, 8.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.25f, 2.0f, SOPER_STOP);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 4.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 4.0f;
dim.y = dim.x;
m_partiSphere = m_particule->CreateParticule(pos, speed, dim, PARTISPHERE2, LABO_DELAY, 0.0f, 0.0f);
m_partiSphere = m_particle->CreateParticle(pos, speed,
dim, Gfx::PARTISPHERE2, LABO_DELAY, 0.0f, 0.0f);
m_phase = ALAP_ANALYSE;
m_progress = 0.0f;
@ -283,13 +285,13 @@ bool CAutoLabo::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
power = m_object->RetPower();
power = m_object->GetPower();
if ( power != 0 )
{
power->SetZoom(0, 1.0f-m_progress);
}
angle = m_object->RetAngleY(2);
angle = m_object->GetAngleY(2);
if ( m_progress < 0.5f )
{
angle -= event.rTime*m_progress*20.0f;
@ -300,27 +302,27 @@ bool CAutoLabo::EventProcess(const Event &event)
}
m_object->SetAngleY(2, angle); // rotates the analyzer
angle += m_object->RetAngleY(0);
angle += m_object->GetAngleY(0);
for ( i=0 ; i<3 ; i++ )
{
rot = Math::RotatePoint(-angle, -4.0f);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += rot.x;
pos.z += rot.y;
pos.y += 3.0f+4.0f;;
m_particule->SetPosition(m_partiRank[i], pos); // adjusts ray
m_particle->SetPosition(m_partiRank[i], pos); // adjusts ray
angle += Math::PI*2.0f/3.0f;
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
if ( m_progress > 0.25f &&
m_progress < 0.80f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 3.0f;
pos.x += (Math::Rand()-0.5f)*2.0f;
pos.z += (Math::Rand()-0.5f)*2.0f;
@ -329,7 +331,7 @@ bool CAutoLabo::EventProcess(const Event &event)
speed.z = (Math::Rand()-0.5f)*10.0f;
dim.x = Math::Rand()*0.4f*m_progress+1.0f;
dim.y = dim.x;
m_particule->CreateTrack(pos, speed, dim, PARTITRACK2,
m_particle->CreateTrack(pos, speed, dim, Gfx::PARTITRACK2,
2.0f+2.0f*m_progress, 10.0f, 1.5f, 1.4f);
}
}
@ -338,7 +340,7 @@ bool CAutoLabo::EventProcess(const Event &event)
{
SetResearch(m_research); // research done
power = m_object->RetPower();
power = m_object->GetPower();
if ( power != 0 )
{
m_object->SetPower(0);
@ -421,21 +423,21 @@ bool CAutoLabo::EventProcess(const Event &event)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoLabo::RetError()
Error CAutoLabo::GetError()
{
CObject* pObj;
ObjectType type;
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
pObj = m_object->RetPower();
pObj = m_object->GetPower();
if ( pObj == 0 ) return ERR_LABO_NULL;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_BULLET ) return ERR_LABO_BAD;
return ERR_OK;
@ -446,7 +448,7 @@ Error CAutoLabo::RetError()
bool CAutoLabo::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
@ -454,7 +456,7 @@ bool CAutoLabo::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
dim.x = 33.0f/640.0f;
@ -487,13 +489,13 @@ bool CAutoLabo::CreateInterface(bool bSelect)
void CAutoLabo::UpdateInterface()
{
CWindow* pw;
Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
DeadInterface(pw, EVENT_OBJECT_RiPAW, g_researchEnable&RESEARCH_iPAW);
@ -508,20 +510,20 @@ void CAutoLabo::UpdateInterface()
// Indicates the research conducted for a button.
void CAutoLabo::OkayButton(CWindow *pw, EventMsg event)
void CAutoLabo::OkayButton(Ui::CWindow *pw, EventType event)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
control->SetState(STATE_OKAY, TestResearch(event));
control->SetState(Ui::STATE_OKAY, TestResearch(event));
}
// Test whether a search has already been done.
bool CAutoLabo::TestResearch(EventMsg 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);
@ -531,16 +533,17 @@ bool CAutoLabo::TestResearch(EventMsg event)
// Indicates a search as made.
void CAutoLabo::SetResearch(EventMsg event)
void CAutoLabo::SetResearch(EventType event)
{
Event newEvent;
if ( event == EVENT_OBJECT_RiPAW ) g_researchDone |= RESEARCH_iPAW;
if ( event == EVENT_OBJECT_RiGUN ) g_researchDone |= RESEARCH_iGUN;
m_main->WriteFreeParam();
m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
Event newEvent(EVENT_UPDINTERFACE);
// m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
m_event->AddEvent(newEvent);
UpdateInterface();
}
@ -551,7 +554,7 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency)
{
int i;
i = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.0f, 0.3f*frequency, true);
i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.3f*frequency, true);
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, 0.1f, SOPER_CONTINUE);
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);
@ -597,12 +600,12 @@ bool CAutoLabo::Read(char *line)
CAuto::Read(line);
m_phase = (AutoLaboPhase)OpInt(line, "aPhase", ALAP_WAIT);
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 = (EventMsg)OpInt(line, "aResearch", 0);
m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -47,7 +48,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -56,9 +57,9 @@ public:
protected:
void UpdateInterface();
void OkayButton(CWindow *pw, EventMsg event);
bool TestResearch(EventMsg event);
void SetResearch(EventMsg event);
void OkayButton(Ui::CWindow *pw, EventType event);
bool TestResearch(EventType event);
void SetResearch(EventType event);
void SoundManip(float time, float amplitude, float frequency);
protected:
@ -66,8 +67,8 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
EventMsg m_research;
float m_lastParticle;
EventType m_research;
int m_partiRank[3];
int m_partiSphere;
int m_soundChannel;

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,14 +16,14 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/automush.h"
#include "common/iman.h"
#include "script/cmdtoken.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -57,7 +58,7 @@ void CAutoMush::Init()
m_speed = 1.0f/4.0f;
m_time = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
}
@ -72,8 +73,8 @@ bool CAutoMush::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
@ -122,7 +123,7 @@ bool CAutoMush::EventProcess(const Event &event)
}
else
{
m_sound->Play(SOUND_MUSHROOM, m_object->RetPosition(0));
m_sound->Play(SOUND_MUSHROOM, m_object->GetPosition(0));
m_phase = AMP_FIRE;
m_progress = 0.0f;
@ -137,21 +138,21 @@ bool CAutoMush::EventProcess(const Event &event)
factor = 1.0f-m_progress;
size = 1.0f+(1.0f-m_progress)*0.3f;
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
for ( i=0 ; i<10 ; i++ )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 5.0f;
speed.x = (Math::Rand()-0.5f)*200.0f;
speed.z = (Math::Rand()-0.5f)*200.0f;
speed.y = -(20.0f+Math::Rand()*20.0f);
dim.x = 1.0f;
dim.y = dim.x;
channel = m_particule->CreateParticule(pos, speed, dim, PARTIGUN2, 2.0f, 100.0f, 0.0f);
m_particule->SetObjectFather(channel, m_object);
channel = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGUN2, 2.0f, 100.0f, 0.0f);
m_particle->SetObjectFather(channel, m_object);
}
}
}
@ -167,18 +168,18 @@ bool CAutoMush::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 5.0f;
speed.x = (Math::Rand()-0.5f)*4.0f;
speed.z = (Math::Rand()-0.5f)*4.0f;
speed.y = -(0.5f+Math::Rand()*0.5f);
dim.x = Math::Rand()*2.5f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTISMOKE3, 4.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f, 0.0f, 0.0f);
}
}
else
@ -226,16 +227,16 @@ bool CAutoMush::SearchTarget()
float dist;
int i;
iPos = m_object->RetPosition(0);
iPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( pObj->RetLock() ) continue;
if ( pObj->GetLock() ) continue;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
type != OBJECT_MOBILEwa &&
@ -279,7 +280,7 @@ bool CAutoMush::SearchTarget()
type != OBJECT_PARA &&
type != OBJECT_HUMAN ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, iPos);
if ( dist < 50.0f ) return true;
}
@ -288,9 +289,9 @@ bool CAutoMush::SearchTarget()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoMush::RetError()
Error CAutoMush::GetError()
{
return ERR_OK;
}
@ -332,11 +333,11 @@ bool CAutoMush::Read(char *line)
CAuto::Read(line);
m_phase = (AutoMushPhase)OpInt(line, "aPhase", AMP_WAIT);
m_phase = static_cast< AutoMushPhase >(OpInt(line, "aPhase", AMP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool Write(char *line);
bool Read(char *line);
@ -56,6 +57,6 @@ protected:
AutoMushPhase m_phase;
float m_progress;
float m_speed;
float m_lastParticule;
float m_lastParticle;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,15 +16,14 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autonest.h"
#include "common/iman.h"
#include "old/terrain.h"
#include "graphics/engine/terrain.h"
#include "script/cmdtoken.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -72,10 +72,10 @@ void CAutoNest::Init()
m_speed = 1.0f/4.0f;
m_time = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
pos = m_object->RetPosition(0);
m_terrain->MoveOnFloor(pos);
pos = m_object->GetPosition(0);
m_terrain->AdjustToFloor(pos);
m_fretPos = pos;
}
@ -88,8 +88,8 @@ bool CAutoNest::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
@ -154,10 +154,10 @@ bool CAutoNest::SearchFree(Math::Vector pos)
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type == OBJECT_NEST ) continue;
j = 0;
@ -199,15 +199,15 @@ CObject* CAutoNest::SearchFret()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( !pObj->RetLock() ) continue;
if ( !pObj->GetLock() ) continue;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_BULLET ) continue;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
if ( oPos.x == m_fretPos.x &&
oPos.z == m_fretPos.z )
{
@ -219,9 +219,9 @@ CObject* CAutoNest::SearchFret()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoNest::RetError()
Error CAutoNest::GetError()
{
return ERR_OK;
}
@ -263,11 +263,11 @@ bool CAutoNest::Read(char *line)
CAuto::Read(line);
m_phase = (AutoNestPhase)OpInt(line, "aPhase", ANP_WAIT);
m_phase = static_cast< AutoNestPhase >(OpInt(line, "aPhase", ANP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -41,7 +42,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool Write(char *line);
bool Read(char *line);
@ -55,7 +56,7 @@ protected:
AutoNestPhase m_phase;
float m_progress;
float m_speed;
float m_lastParticule;
Math::Vector m_fretPos;
float m_lastParticle;
Math::Vector m_fretPos;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autonuclear.h"
#include "common/iman.h"
@ -26,6 +25,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float NUCLEAR_DELAY = 30.0f; // duration of the generation
@ -84,9 +85,9 @@ void CAutoNuclear::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
m_pos = Math::Transform(*mat, Math::Vector(22.0f, 4.0f, 0.0f));
m_phase = ANUP_WAIT; // waiting ...
@ -110,13 +111,13 @@ bool CAutoNuclear::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -146,7 +147,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
InitProgressTotal(1.5f+NUCLEAR_DELAY+1.5f);
UpdateInterface();
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 1.4f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.4f);
m_phase = ANUP_CLOSE;
m_progress = 0.0f;
@ -166,8 +167,8 @@ bool CAutoNuclear::EventProcess(const Event &event)
{
m_object->SetAngleZ(1, 0.0f);
mat = m_object->RetWorldMatrix(0);
max = (int)(10.0f*m_engine->RetParticuleDensity());
mat = m_object->GetWorldMatrix(0);
max = static_cast< int >(10.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
pos.x = 27.0f;
@ -179,12 +180,12 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = 0.0f;
dim.x = Math::Rand()*1.0f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH);
}
m_sound->Play(SOUND_CLOSE, m_object->RetPosition(0), 1.0f, 1.0f);
m_sound->Play(SOUND_CLOSE, m_object->GetPosition(0), 1.0f, 1.0f);
m_channelSound = m_sound->Play(SOUND_NUCLEAR, m_object->RetPosition(0), 1.0f, 0.1f, true);
m_channelSound = m_sound->Play(SOUND_NUCLEAR, m_object->GetPosition(0), 1.0f, 0.1f, true);
m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, NUCLEAR_DELAY-1.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP);
@ -198,11 +199,11 @@ bool CAutoNuclear::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.10f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.10f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 30.0f;
pos.x += (Math::Rand()-0.5f)*6.0f;
pos.z += (Math::Rand()-0.5f)*6.0f;
@ -211,7 +212,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = 0.0f;
dim.x = Math::Rand()*8.0f+8.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH);
pos = m_pos;
speed.x = (Math::Rand()-0.5f)*20.0f;
@ -219,7 +220,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = (Math::Rand()-0.5f)*20.0f;
dim.x = 2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLITZ, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 0.0f, 0.0f);
}
}
else
@ -234,7 +235,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
CreatePower(); // creates the atomic cell
max = (int)(20.0f*m_engine->RetParticuleDensity());
max = static_cast< int >(20.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ )
{
pos = m_pos;
@ -246,10 +247,10 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = 0.0f;
dim.x = Math::Rand()*2.0f+2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLUE, Math::Rand()*5.0f+5.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, Math::Rand()*5.0f+5.0f, 0.0f, 0.0f);
}
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 1.4f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 1.4f);
m_phase = ANUP_OPEN;
m_progress = 0.0f;
@ -287,7 +288,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
bool CAutoNuclear::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -295,7 +296,7 @@ bool CAutoNuclear::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -319,9 +320,9 @@ CObject* CAutoNuclear::SearchUranium()
{
CObject* pObj;
pObj = m_object->RetPower();
pObj = m_object->GetPower();
if ( pObj == 0 ) return 0;
if ( pObj->RetType() == OBJECT_URANIUM ) return pObj;
if ( pObj->GetType() == OBJECT_URANIUM ) return pObj;
return 0;
}
@ -337,10 +338,10 @@ bool CAutoNuclear::SearchVehicle()
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
@ -392,8 +393,8 @@ void CAutoNuclear::CreatePower()
Math::Vector pos;
float angle;
pos = m_object->RetPosition(0);
angle = m_object->RetAngleY(0);
pos = m_object->GetPosition(0);
angle = m_object->GetAngleY(0);
power = new CObject(m_iMan);
if ( !power->CreateResource(pos, angle, OBJECT_ATOMIC) )
@ -409,28 +410,28 @@ void CAutoNuclear::CreatePower()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoNuclear::RetError()
Error CAutoNuclear::GetError()
{
CObject* pObj;
ObjectType type;
//? TerrainRes res;
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
//? res = m_terrain->RetResource(m_object->RetPosition(0));
//? res = m_terrain->GetResource(m_object->GetPosition(0));
//? if ( res != TR_POWER ) return ERR_NUCLEAR_NULL;
//? if ( m_object->RetEnergy() < ENERGY_POWER ) return ERR_NUCLEAR_LOW;
//? if ( m_object->GetEnergy() < ENERGY_POWER ) return ERR_NUCLEAR_LOW;
pObj = m_object->RetPower();
pObj = m_object->GetPower();
if ( pObj == 0 ) return ERR_NUCLEAR_EMPTY;
if ( pObj->RetLock() ) return ERR_OK;
type = pObj->RetType();
if ( pObj->GetLock() ) return ERR_OK;
type = pObj->GetType();
if ( type == OBJECT_ATOMIC ) return ERR_OK;
if ( type != OBJECT_URANIUM ) return ERR_NUCLEAR_BAD;
@ -472,11 +473,11 @@ bool CAutoNuclear::Read(char *line)
CAuto::Read(line);
m_phase = (AutoNuclearPhase)OpInt(line, "aPhase", ANUP_WAIT);
m_phase = static_cast< AutoNuclearPhase >(OpInt(line, "aPhase", ANUP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -61,7 +62,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
Math::Vector m_pos;
int m_channelSound;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autopara.h"
@ -26,6 +25,8 @@
#include "ui/interface.h"
#include "ui/window.h"
#include <stdio.h>
#include <string.h>
@ -68,9 +69,9 @@ void CAutoPara::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
m_pos = Math::Transform(*mat, Math::Vector(22.0f, 4.0f, 0.0f));
m_phase = APAP_WAIT; // waiting ...
@ -83,9 +84,9 @@ void CAutoPara::Init()
// Reception of lightning.
void CAutoPara::StartBlitz()
void CAutoPara::StartLightning()
{
m_phase = APAP_BLITZ;
m_phase = APAP_LIGHTNING;
m_progress = 0.0f;
m_speed = 1.0f/2.0f;
}
@ -101,13 +102,13 @@ bool CAutoPara::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -118,17 +119,17 @@ bool CAutoPara::EventProcess(const Event &event)
EventProgress(event.rTime);
if ( m_phase == APAP_BLITZ )
if ( m_phase == APAP_LIGHTNING )
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
for ( i=0 ; i<10 ; i++ )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*m_progress*40.0f;
pos.z += (Math::Rand()-0.5f)*m_progress*40.0f;
pos.y += 50.0f-m_progress*50.0f;
@ -137,7 +138,7 @@ bool CAutoPara::EventProcess(const Event &event)
speed.y = 5.0f+Math::Rand()*5.0f;
dim.x = 2.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLITZ, 1.0f, 20.0f, 0.5f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 20.0f, 0.5f);
}
}
}
@ -153,20 +154,20 @@ bool CAutoPara::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
for ( i=0 ; i<2 ; i++ )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.y += 16.0f;
speed.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = -Math::Rand()*30.0f;
dim.x = 1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLITZ, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, 1.0f, 0.0f, 0.0f);
}
}
@ -188,7 +189,7 @@ bool CAutoPara::EventProcess(const Event &event)
bool CAutoPara::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -196,7 +197,7 @@ bool CAutoPara::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -220,11 +221,11 @@ bool CAutoPara::CreateInterface(bool bSelect)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoPara::RetError()
Error CAutoPara::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -242,38 +243,38 @@ void CAutoPara::ChargeObject(float rTime)
float dist, energy;
int i;
sPos = m_object->RetPosition(0);
sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, sPos);
if ( dist > 20.0f ) continue;
if ( pObj->RetTruck() == 0 && pObj->RetType() == OBJECT_POWER )
if ( pObj->GetTruck() == 0 && pObj->GetType() == OBJECT_POWER )
{
energy = pObj->RetEnergy();
energy = pObj->GetEnergy();
energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f;
pObj->SetEnergy(energy);
}
power = pObj->RetPower();
if ( power != 0 && power->RetType() == OBJECT_POWER )
power = pObj->GetPower();
if ( power != 0 && power->GetType() == OBJECT_POWER )
{
energy = power->RetEnergy();
energy = power->GetEnergy();
energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f;
power->SetEnergy(energy);
}
power = pObj->RetFret();
if ( power != 0 && power->RetType() == OBJECT_POWER )
power = pObj->GetFret();
if ( power != 0 && power->GetType() == OBJECT_POWER )
{
energy = power->RetEnergy();
energy = power->GetEnergy();
energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f;
power->SetEnergy(energy);
@ -315,11 +316,11 @@ bool CAutoPara::Read(char *line)
CAuto::Read(line);
m_phase = (AutoParaPhase)OpInt(line, "aPhase", APAP_WAIT);
m_phase = static_cast< AutoParaPhase >(OpInt(line, "aPhase", APAP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -26,7 +27,7 @@
enum AutoParaPhase
{
APAP_WAIT = 1,
APAP_BLITZ = 2,
APAP_LIGHTNING = 2,
APAP_CHARGE = 3,
};
@ -42,8 +43,8 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
void StartBlitz();
Error GetError();
void StartLightning();
bool CreateInterface(bool bSelect);
@ -58,7 +59,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
Math::Vector m_pos;
int m_channelSound;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,14 +16,13 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoportico.h"
#include "object/robotmain.h"
#include <stdio.h>
#include <string.h>
const int PARAM_DEPOSE = 2; // run=2 -> deposits the spaceship
@ -90,7 +90,7 @@ void CAutoPortico::DeleteObject(bool bAll)
void CAutoPortico::Init()
{
m_time = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
m_posTrack = 0.0f;
m_phase = APOP_WAIT;
@ -108,7 +108,7 @@ void CAutoPortico::Start(int param)
{
Math::Vector pos;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
m_finalPos = pos;
pos.z += PORTICO_TIME_MOVE*5.0f; // back to start
m_object->SetPosition(0, pos);
@ -140,15 +140,15 @@ bool CAutoPortico::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
if ( m_phase == APOP_START )
{
if ( m_param == PARAM_DEPOSE ) // deposits the ship?
{
m_startPos = m_object->RetPosition(0);
m_startPos = m_object->GetPosition(0);
m_soundChannel = m_sound->Play(SOUND_MOTORr, m_object->RetPosition(0), 0.0f, 0.3f, true);
m_soundChannel = m_sound->Play(SOUND_MOTORr, m_object->GetPosition(0), 0.0f, 0.3f, true);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.6f, 0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.6f, PORTICO_TIME_MOVE-0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.3f, 0.5f, SOPER_STOP);
@ -159,7 +159,7 @@ bool CAutoPortico::EventProcess(const Event &event)
m_main->SetMovieLock(true); // blocks everything until the end of the landing
m_camera->SetType(CAMERA_SCRIPT);
m_camera->SetType(Gfx::CAM_TYPE_SCRIPT);
pos = m_startPos;
pos.x += -100.0f;
@ -167,7 +167,7 @@ bool CAutoPortico::EventProcess(const Event &event)
pos.z += -200.0f;
m_camera->SetScriptEye(pos);
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += 0.0f;
pos.y += 10.0f;
pos.z += -40.0f;
@ -187,7 +187,7 @@ bool CAutoPortico::EventProcess(const Event &event)
angle = sinf(m_time*4.0f)*0.3f;
m_object->SetAngleX(11, angle);
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_phase == APOP_WAIT ) return true;
m_progress += event.rTime*m_speed;
@ -197,7 +197,7 @@ bool CAutoPortico::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.z -= event.rTime*5.0f; // advance
m_object->SetPosition(0, pos);
@ -216,7 +216,7 @@ bool CAutoPortico::EventProcess(const Event &event)
{
if ( m_progress >= 1.0f )
{
m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.0f, 0.3f, true);
m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.3f, true);
m_sound->AddEnvelope(m_soundChannel, 0.3f, 0.5f, 1.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.3f, 0.6f, PORTICO_TIME_DOWN-1.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.3f, 1.0f, SOPER_STOP);
@ -253,12 +253,12 @@ bool CAutoPortico::EventProcess(const Event &event)
{
if ( m_progress >= 1.0f )
{
m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->RetPosition(0), 0.0f, 0.5f, true);
m_soundChannel = m_sound->Play(SOUND_MANIP, m_object->GetPosition(0), 0.0f, 0.5f, true);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 1.0f, 0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 1.0f, PORTICO_TIME_OPEN/2.0f-0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.5f, 0.5f, SOPER_STOP);
m_soundChannel = m_sound->Play(SOUND_MOTORr, m_object->RetPosition(0), 0.0f, 0.3f, true);
m_soundChannel = m_sound->Play(SOUND_MOTORr, m_object->GetPosition(0), 0.0f, 0.3f, true);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.6f, 0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.5f, 0.6f, PORTICO_TIME_OPEN-0.5f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.3f, 0.5f, SOPER_STOP);
@ -273,7 +273,7 @@ bool CAutoPortico::EventProcess(const Event &event)
{
if ( m_progress < 1.0f )
{
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.z += event.rTime*5.3f; // back
m_object->SetPosition(0, pos);
@ -308,8 +308,8 @@ bool CAutoPortico::EventProcess(const Event &event)
pObj = m_main->SearchHuman();
m_main->SelectObject(pObj);
m_camera->SetObject(pObj);
m_camera->SetType(CAMERA_BACK);
m_camera->SetControllingObject(pObj);
m_camera->SetType(Gfx::CAM_TYPE_BACK);
m_phase = APOP_WAIT;
m_progress = 0.0f;
@ -319,8 +319,8 @@ bool CAutoPortico::EventProcess(const Event &event)
if ( m_soundChannel != -1 )
{
//? m_sound->Position(m_soundChannel, m_object->RetPosition(0));
pos = m_engine->RetEyePt();
//? m_sound->Position(m_soundChannel, m_object->GetPosition(0));
pos = m_engine->GetEyePt();
m_sound->Position(m_soundChannel, pos);
}
@ -338,7 +338,7 @@ bool CAutoPortico::EventProcess(const Event &event)
m_camera->SetScriptEye(pos);
}
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += 0.0f;
pos.y += 10.0f;
pos.z += -40.0f;
@ -367,8 +367,8 @@ bool CAutoPortico::Abort()
pObj = m_main->SearchHuman();
m_main->SelectObject(pObj);
m_camera->SetObject(pObj);
m_camera->SetType(CAMERA_BACK);
m_camera->SetControllingObject(pObj);
m_camera->SetType(Gfx::CAM_TYPE_BACK);
if ( m_soundChannel != -1 )
{
@ -385,9 +385,9 @@ bool CAutoPortico::Abort()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoPortico::RetError()
Error CAutoPortico::GetError()
{
return ERR_OK;
}
@ -397,11 +397,11 @@ Error CAutoPortico::RetError()
void CAutoPortico::UpdateTrackMapping(float left, float right)
{
D3DMATERIAL7 mat;
Gfx::Material mat;
float limit[2];
int rank;
ZeroMemory( &mat, sizeof(D3DMATERIAL7) );
memset( &mat, 0, sizeof(Gfx::Material));
mat.diffuse.r = 1.0f;
mat.diffuse.g = 1.0f;
mat.diffuse.b = 1.0f; // blank
@ -409,17 +409,17 @@ void CAutoPortico::UpdateTrackMapping(float left, float right)
mat.ambient.g = 0.5f;
mat.ambient.b = 0.5f;
rank = m_object->RetObjectRank(0);
rank = m_object->GetObjectRank(0);
limit[0] = 0.0f;
limit[1] = 1000000.0f;
m_engine->TrackTextureMapping(rank, mat, D3DSTATEPART1, "lemt.tga", "",
limit[0], limit[1], D3DMAPPINGX,
m_engine->TrackTextureMapping(rank, mat, Gfx::ENG_RSTATE_PART1, "lemt.png", "",
limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X,
right, 8.0f, 8.0f, 192.0f, 256.0f);
m_engine->TrackTextureMapping(rank, mat, D3DSTATEPART2, "lemt.tga", "",
limit[0], limit[1], D3DMAPPINGX,
m_engine->TrackTextureMapping(rank, mat, Gfx::ENG_RSTATE_PART2, "lemt.png", "",
limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X,
left, 8.0f, 8.0f, 192.0f, 256.0f);
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -48,7 +49,7 @@ public:
void Start(int param);
bool EventProcess(const Event &event);
bool Abort();
Error RetError();
Error GetError();
protected:
void UpdateTrackMapping(float left, float right);
@ -59,7 +60,7 @@ protected:
float m_speed;
float m_cameraProgress;
float m_cameraSpeed;
float m_lastParticule;
float m_lastParticle;
Math::Vector m_finalPos;
Math::Vector m_startPos;
float m_posTrack;

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoradar.h"
#include "common/iman.h"
@ -25,6 +24,8 @@
#include "ui/window.h"
#include "ui/gauge.h"
#include <stdio.h>
// Object's constructor.
@ -74,31 +75,31 @@ bool CAutoRadar::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
if ( m_phase == ARAP_WAIT ) return true;
m_progress += event.rTime*m_speed;
m_aTime += event.rTime;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
m_timeVirus = 0.1f+Math::Rand()*0.3f;
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle += (Math::Rand()-0.2f)*0.5f;
m_object->SetAngleY(1, angle);
angle = m_object->RetAngleY(2);
angle = m_object->GetAngleY(2);
angle += (Math::Rand()-0.8f)*1.0f;
m_object->SetAngleY(2, angle);
m_object->SetAngleX(3, (Math::Rand()-0.5f)*0.3f);
m_totalDetect = (int)(Math::Rand()*10.0f);
m_totalDetect = static_cast< int >(Math::Rand()*10.0f);
UpdateInterface();
}
return true;
@ -109,7 +110,7 @@ bool CAutoRadar::EventProcess(const Event &event)
if ( m_progress < 1.0f )
{
speed = Math::Min(10.0f, m_progress*50.0f);
angle = m_object->RetAngleY(1);
angle = m_object->GetAngleY(1);
angle += event.rTime*speed;
m_object->SetAngleY(1, angle);
}
@ -123,11 +124,11 @@ bool CAutoRadar::EventProcess(const Event &event)
}
else
{
pos = m_object->RetPosition(0);
m_start = m_object->RetAngleY(1);
pos = m_object->GetPosition(0);
m_start = m_object->GetAngleY(1);
m_angle = m_start-Math::NormAngle(m_start)+Math::PI*2.0f;
m_angle += Math::RotateAngle(pos.x-ePos.x, ePos.z-pos.z);
m_angle += Math::PI-m_object->RetAngleY(0);
m_angle += Math::PI-m_object->GetAngleY(0);
m_phase = ARAP_SHOW;
m_progress = 0.0f;
@ -145,7 +146,7 @@ bool CAutoRadar::EventProcess(const Event &event)
}
else
{
m_sound->Play(SOUND_RADAR, m_object->RetPosition(0));
m_sound->Play(SOUND_RADAR, m_object->GetPosition(0));
m_phase = ARAP_SINUS;
m_progress = 0.0f;
@ -182,11 +183,11 @@ bool CAutoRadar::EventProcess(const Event &event)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoRadar::RetError()
Error CAutoRadar::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -199,7 +200,7 @@ Error CAutoRadar::RetError()
bool CAutoRadar::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
@ -207,7 +208,7 @@ bool CAutoRadar::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -235,21 +236,21 @@ bool CAutoRadar::CreateInterface(bool bSelect)
void CAutoRadar::UpdateInterface()
{
CWindow* pw;
CGauge* pg;
Ui::CWindow* pw;
Ui::CGauge* pg;
float level;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
pg = (CGauge*)pw->SearchControl(EVENT_OBJECT_GRADAR);
pg = static_cast< Ui::CGauge* >(pw->SearchControl(EVENT_OBJECT_GRADAR));
if ( pg != 0 )
{
level = (float)m_totalDetect*(1.0f/8.0f);
level = static_cast< float >(m_totalDetect*(1.0f/8.0f));
if ( level > 1.0f ) level = 1.0f;
pg->SetLevel(level);
}
@ -267,18 +268,18 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos)
float distance, min;
int i;
iPos = m_object->RetPosition(0);
iPos = m_object->GetPosition(0);
min = 1000000.0f;
m_totalDetect = 0;
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
if ( !pObj->RetActif() ) continue;
if ( !pObj->GetActif() ) continue;
oType = pObj->RetType();
oType = pObj->GetType();
if ( oType != OBJECT_ANT &&
oType != OBJECT_SPIDER &&
oType != OBJECT_BEE &&
@ -287,7 +288,7 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos)
m_totalDetect ++;
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
distance = Math::Distance(oPos, iPos);
if ( distance < min )
{
@ -299,7 +300,7 @@ bool CAutoRadar::SearchEnemy(Math::Vector &pos)
UpdateInterface();
if ( pBest == 0 ) return false;
pos = pBest->RetPosition(0);
pos = pBest->GetPosition(0);
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
bool CreateInterface(bool bSelect);
Error RetError();
Error GetError();
protected:
void UpdateInterface();
@ -56,7 +57,7 @@ protected:
float m_speed;
float m_aTime;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
float m_angle;
float m_start;
int m_totalDetect;

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autorepair.h"
#include "common/iman.h"
@ -25,6 +24,9 @@
#include "ui/interface.h"
#include "ui/window.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
@ -60,7 +62,7 @@ void CAutoRepair::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
CAuto::Init();
}
@ -77,13 +79,13 @@ bool CAutoRepair::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( event.event != EVENT_FRAME ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -104,7 +106,7 @@ bool CAutoRepair::EventProcess(const Event &event)
}
else
{
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 0.8f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 0.8f);
m_phase = ARP_DOWN;
m_progress = 0.0f;
@ -123,7 +125,7 @@ bool CAutoRepair::EventProcess(const Event &event)
else
{
m_object->SetAngleZ(1, 0.0f);
m_sound->Play(SOUND_REPAIR, m_object->RetPosition(0));
m_sound->Play(SOUND_REPAIR, m_object->GetPosition(0));
m_phase = ARP_REPAIR;
m_progress = 0.0f;
@ -135,21 +137,21 @@ bool CAutoRepair::EventProcess(const Event &event)
{
vehicule = SearchVehicle();
if ( m_progress < 1.0f ||
(vehicule != 0 && vehicule->RetShield() < 1.0f) )
(vehicule != 0 && vehicule->GetShield() < 1.0f) )
{
if ( vehicule != 0 )
{
shield = vehicule->RetShield();
shield = vehicule->GetShield();
shield += event.rTime*0.2f;
if ( shield > 1.0f ) shield = 1.0f;
vehicule->SetShield(shield);
}
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += 1.0f;
@ -158,12 +160,12 @@ bool CAutoRepair::EventProcess(const Event &event)
speed.y = Math::Rand()*15.0f;
dim.x = Math::Rand()*6.0f+4.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, 1.0f, 0.0f, 0.0f);
}
}
else
{
m_sound->Play(SOUND_OPEN, m_object->RetPosition(0), 1.0f, 0.8f);
m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 0.8f);
m_phase = ARP_UP;
m_progress = 0.0f;
@ -196,7 +198,7 @@ bool CAutoRepair::EventProcess(const Event &event)
bool CAutoRepair::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, ddim;
float ox, oy, sx, sy;
@ -204,7 +206,7 @@ bool CAutoRepair::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
ox = 3.0f/640.0f;
@ -233,14 +235,14 @@ CObject* CAutoRepair::SearchVehicle()
float dist;
int i;
sPos = m_object->RetPosition(0);
sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ )
{
pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
pObj = static_cast< CObject* >(m_iMan->SearchInstance(CLASS_OBJECT, i));
if ( pObj == 0 ) break;
type = pObj->RetType();
type = pObj->GetType();
if ( type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta &&
type != OBJECT_MOBILEwa &&
@ -269,10 +271,10 @@ CObject* CAutoRepair::SearchVehicle()
type != OBJECT_MOBILEit &&
type != OBJECT_MOBILEdr ) continue;
physics = pObj->RetPhysics();
if ( physics != 0 && !physics->RetLand() ) continue; // in flight?
physics = pObj->GetPhysics();
if ( physics != 0 && !physics->GetLand() ) continue; // in flight?
oPos = pObj->RetPosition(0);
oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, sPos);
if ( dist <= 5.0f ) return pObj;
}
@ -281,11 +283,11 @@ CObject* CAutoRepair::SearchVehicle()
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoRepair::RetError()
Error CAutoRepair::GetError()
{
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
@ -327,11 +329,11 @@ bool CAutoRepair::Read(char *line)
CAuto::Read(line);
m_phase = (AutoRepairPhase)OpInt(line, "aPhase", ARP_WAIT);
m_phase = static_cast< AutoRepairPhase >(OpInt(line, "aPhase", ARP_WAIT));
m_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -44,7 +45,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -59,7 +60,7 @@ protected:
float m_progress;
float m_speed;
float m_timeVirus;
float m_lastParticule;
float m_lastParticle;
};

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -15,8 +16,6 @@
// * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoresearch.h"
#include "common/global.h"
@ -28,6 +27,8 @@
#include "ui/window.h"
#include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float SEARCH_TIME = 30.0f; // duration of a research
@ -84,7 +85,7 @@ void CAutoResearch::Init()
m_time = 0.0f;
m_timeVirus = 0.0f;
m_lastUpdateTime = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
}
@ -100,29 +101,29 @@ bool CAutoResearch::EventProcess(const Event &event)
CAuto::EventProcess(event);
if ( m_engine->RetPause() ) return true;
if ( m_engine->GetPause() ) return true;
if ( event.event == EVENT_UPDINTERFACE )
if ( event.type == EVENT_UPDINTERFACE )
{
if ( m_object->RetSelect() ) CreateInterface(true);
if ( m_object->GetSelect() ) CreateInterface(true);
}
if ( m_object->RetSelect() && // center selected?
(event.event == EVENT_OBJECT_RTANK ||
event.event == EVENT_OBJECT_RFLY ||
event.event == EVENT_OBJECT_RTHUMP ||
event.event == EVENT_OBJECT_RCANON ||
event.event == EVENT_OBJECT_RTOWER ||
event.event == EVENT_OBJECT_RPHAZER ||
event.event == EVENT_OBJECT_RSHIELD ||
event.event == EVENT_OBJECT_RATOMIC ) )
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_phase != ALP_WAIT )
{
return false;
}
m_research = event.event;
m_research = event.type;
if ( TestResearch(m_research) )
{
@ -130,33 +131,33 @@ bool CAutoResearch::EventProcess(const Event &event)
return false;
}
power = m_object->RetPower();
power = m_object->GetPower();
if ( power == 0 )
{
m_displayText->DisplayError(ERR_RESEARCH_POWER, m_object);
return false;
}
if ( power->RetCapacity() > 1.0f )
if ( power->GetCapacity() > 1.0f )
{
m_displayText->DisplayError(ERR_RESEARCH_TYPE, m_object);
return false;
}
if ( power->RetEnergy() < 1.0f )
if ( power->GetEnergy() < 1.0f )
{
m_displayText->DisplayError(ERR_RESEARCH_ENERGY, m_object);
return false;
}
time = SEARCH_TIME;
if ( event.event == EVENT_OBJECT_RTANK ) time *= 0.3f;
if ( event.event == EVENT_OBJECT_RFLY ) time *= 0.3f;
if ( event.event == EVENT_OBJECT_RATOMIC ) time *= 2.0f;
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->RetPosition(0), 0.0f, 1.0f, true);
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);
@ -167,12 +168,12 @@ bool CAutoResearch::EventProcess(const Event &event)
return true;
}
if ( event.event != EVENT_FRAME ) return true;
if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed;
m_timeVirus -= event.rTime;
if ( m_object->RetVirusMode() ) // contaminated by a virus?
if ( m_object->GetVirusMode() ) // contaminated by a virus?
{
if ( m_timeVirus <= 0.0f )
{
@ -201,7 +202,7 @@ bool CAutoResearch::EventProcess(const Event &event)
FireStopUpdate(m_progress, true); // flashes
if ( m_progress < 1.0f )
{
power = m_object->RetPower();
power = m_object->GetPower();
if ( power == 0 ) // more battery?
{
SetBusy(false);
@ -214,11 +215,11 @@ bool CAutoResearch::EventProcess(const Event &event)
}
power->SetEnergy(1.0f-m_progress);
if ( m_lastParticule+m_engine->ParticuleAdapt(0.05f) <= m_time )
if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
{
m_lastParticule = m_time;
m_lastParticle = m_time;
pos = m_object->RetPosition(0);
pos = m_object->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*6.0f;
pos.z += (Math::Rand()-0.5f)*6.0f;
pos.y += 11.0f;
@ -227,7 +228,7 @@ bool CAutoResearch::EventProcess(const Event &event)
speed.y = Math::Rand()*20.0f;
dim.x = Math::Rand()*1.0f+1.0f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIVAPOR);
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIVAPOR);
}
}
else
@ -262,9 +263,9 @@ bool CAutoResearch::EventProcess(const Event &event)
}
// Returns an error due the state of the automation.
// Geturns an error due the state of the automation.
Error CAutoResearch::RetError()
Error CAutoResearch::GetError()
{
CObject* power;
@ -273,21 +274,21 @@ Error CAutoResearch::RetError()
return ERR_OK;
}
if ( m_object->RetVirusMode() )
if ( m_object->GetVirusMode() )
{
return ERR_BAT_VIRUS;
}
power = m_object->RetPower();
power = m_object->GetPower();
if ( power == 0 )
{
return ERR_RESEARCH_POWER;
}
if ( power != 0 && power->RetCapacity() > 1.0f )
if ( power != 0 && power->GetCapacity() > 1.0f )
{
return ERR_RESEARCH_TYPE;
}
if ( power != 0 && power->RetEnergy() < 1.0f )
if ( power != 0 && power->GetEnergy() < 1.0f )
{
return ERR_RESEARCH_ENERGY;
}
@ -300,7 +301,7 @@ Error CAutoResearch::RetError()
bool CAutoResearch::CreateInterface(bool bSelect)
{
CWindow* pw;
Ui::CWindow* pw;
Math::Point pos, dim, ddim;
float ox, oy, sx, sy;
@ -308,7 +309,7 @@ bool CAutoResearch::CreateInterface(bool bSelect)
if ( !bSelect ) return true;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return false;
dim.x = 33.0f/640.0f;
@ -371,13 +372,13 @@ bool CAutoResearch::CreateInterface(bool bSelect)
void CAutoResearch::UpdateInterface()
{
CWindow* pw;
Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
DeadInterface(pw, EVENT_OBJECT_RTANK, g_researchEnable&RESEARCH_TANK);
@ -413,8 +414,8 @@ void CAutoResearch::UpdateInterface()
void CAutoResearch::UpdateInterface(float rTime)
{
CWindow* pw;
CGauge* pg;
Ui::CWindow* pw;
Ui::CGauge* pg;
CObject* power;
float energy;
@ -423,19 +424,19 @@ void CAutoResearch::UpdateInterface(float rTime)
if ( m_time < m_lastUpdateTime+0.1f ) return;
m_lastUpdateTime = m_time;
if ( !m_object->RetSelect() ) return;
if ( !m_object->GetSelect() ) return;
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0);
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return;
pg = (CGauge*)pw->SearchControl(EVENT_OBJECT_GENERGY);
pg = static_cast< Ui::CGauge* >(pw->SearchControl(EVENT_OBJECT_GENERGY));
if ( pg != 0 )
{
energy = 0.0f;
power = m_object->RetPower();
power = m_object->GetPower();
if ( power != 0 )
{
energy = power->RetEnergy();
energy = power->GetEnergy();
}
pg->SetLevel(energy);
}
@ -443,20 +444,20 @@ void CAutoResearch::UpdateInterface(float rTime)
// Research shows already performed button.
void CAutoResearch::OkayButton(CWindow *pw, EventMsg event)
void CAutoResearch::OkayButton(Ui::CWindow *pw, EventType event)
{
CControl* control;
Ui::CControl* control;
control = pw->SearchControl(event);
if ( control == 0 ) return;
control->SetState(STATE_OKAY, TestResearch(event));
control->SetState(Ui::STATE_OKAY, TestResearch(event));
}
// Test whether a search has already been done.
bool CAutoResearch::TestResearch(EventMsg 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 );
@ -472,9 +473,8 @@ bool CAutoResearch::TestResearch(EventMsg event)
// Indicates a search as made.
void CAutoResearch::SetResearch(EventMsg event)
void CAutoResearch::SetResearch(EventType event)
{
Event newEvent;
if ( event == EVENT_OBJECT_RTANK ) g_researchDone |= RESEARCH_TANK;
if ( event == EVENT_OBJECT_RFLY ) g_researchDone |= RESEARCH_FLY;
@ -487,7 +487,7 @@ void CAutoResearch::SetResearch(EventMsg event)
m_main->WriteFreeParam();
m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
Event newEvent(EVENT_UPDINTERFACE);
m_event->AddEvent(newEvent);
UpdateInterface();
}
@ -518,14 +518,14 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
{
if ( m_partiStop[i] != -1 )
{
m_particule->DeleteParticule(m_partiStop[i]);
m_particle->DeleteParticle(m_partiStop[i]);
m_partiStop[i] = -1;
}
}
return;
}
mat = m_object->RetWorldMatrix(0);
mat = m_object->GetWorldMatrix(0);
speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 2.0f;
@ -537,7 +537,7 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
{
if ( m_partiStop[i] != -1 )
{
m_particule->DeleteParticule(m_partiStop[i]);
m_particle->DeleteParticle(m_partiStop[i]);
m_partiStop[i] = -1;
}
}
@ -549,8 +549,8 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
pos.y = 11.5f;
pos.z = listpos[i*2+1];
pos = Math::Transform(*mat, pos);
m_partiStop[i] = m_particule->CreateParticule(pos, speed,
dim, PARTISELY,
m_partiStop[i] = m_particle->CreateParticle(pos, speed,
dim, Gfx::PARTISELY,
1.0f, 0.0f, 0.0f);
}
}
@ -594,13 +594,13 @@ bool CAutoResearch::Read(char *line)
CAuto::Read(line);
m_phase = (AutoResearchPhase)OpInt(line, "aPhase", ALP_WAIT);
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 = (EventMsg)OpInt(line, "aResearch", 0);
m_research = static_cast< EventType >(OpInt(line, "aResearch", 0));
m_lastUpdateTime = 0.0f;
m_lastParticule = 0.0f;
m_lastParticle = 0.0f;
return true;
}

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
// *
// * 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
@ -41,7 +42,7 @@ public:
void Init();
bool EventProcess(const Event &event);
Error RetError();
Error GetError();
bool CreateInterface(bool bSelect);
@ -51,9 +52,9 @@ public:
protected:
void UpdateInterface();
void UpdateInterface(float rTime);
void OkayButton(CWindow *pw, EventMsg event);
bool TestResearch(EventMsg event);
void SetResearch(EventMsg event);
void OkayButton(Ui::CWindow *pw, EventType event);
bool TestResearch(EventType event);
void SetResearch(EventType event);
void FireStopUpdate(float progress, bool bLightOn);
protected:
@ -62,8 +63,8 @@ protected:
float m_speed;
float m_timeVirus;
float m_lastUpdateTime;
float m_lastParticule;
EventMsg m_research;
float m_lastParticle;
EventType m_research;
int m_partiStop[6];
int m_channelSound;
};

Some files were not shown because too many files have changed in this diff Show More