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) { bool ConvertToStore(const SI_CHAR * a_pszString) {
size_t uLen = SizeToStore(a_pszString); size_t uLen = SizeToStore(a_pszString);
if (uLen == (size_t)(-1)) { if (uLen == static_cast<size_t>(-1)) {
return false; return false;
} }
while (uLen > m_scratch.size()) { while (uLen > m_scratch.size()) {
@ -1360,7 +1360,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadFile(
} }
fseek(a_fpFile, 0, SEEK_SET); fseek(a_fpFile, 0, SEEK_SET);
size_t uRead = fread(pData, sizeof(char), lSize, a_fpFile); size_t uRead = fread(pData, sizeof(char), lSize, a_fpFile);
if (uRead != (size_t) lSize) { if (uRead != static_cast<size_t>(lSize)) {
delete[] pData; delete[] pData;
return SI_FILE; return SI_FILE;
} }
@ -1394,7 +1394,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
// determine the length of the converted data // determine the length of the converted data
size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen); size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen);
if (uLen == (size_t)(-1)) { if (uLen == static_cast<size_t>(-1)) {
return SI_FAIL; 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 // move this line down to the location that it should be if necessary
if (pDataLine < pCurrLine) { 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)); memmove(pDataLine, pCurrLine, nLen * sizeof(SI_CHAR));
pDataLine[nLen] = '\0'; pDataLine[nLen] = '\0';
} }
@ -1816,10 +1816,10 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::CopyString(
{ {
size_t uLen = 0; size_t uLen = 0;
if (sizeof(SI_CHAR) == sizeof(char)) { 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)) { 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 { else {
for ( ; a_pString[uLen]; ++uLen) /*loop*/ ; 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 // if multi-key isn't permitted then the section size is
// the number of keys that we have. // the number of keys that we have.
if (!m_bAllowMultiKey || section.empty()) { if (!m_bAllowMultiKey || section.empty()) {
return (int) section.size(); return static_cast<int> (section.size());
} }
// otherwise we need to count them // otherwise we need to count them
@ -2626,7 +2626,7 @@ struct SI_GenericCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const { bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
long cmp; long cmp;
for ( ;*pLeft && *pRight; ++pLeft, ++pRight) { for ( ;*pLeft && *pRight; ++pLeft, ++pRight) {
cmp = (long) *pLeft - (long) *pRight; cmp = static_cast<long> (*pLeft) - static_cast<long> (*pRight);
if (cmp != 0) { if (cmp != 0) {
return cmp < 0; return cmp < 0;
} }
@ -2649,7 +2649,7 @@ struct SI_GenericNoCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const { bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
long cmp; long cmp;
for ( ;*pLeft && *pRight; ++pLeft, ++pRight) { 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) { if (cmp != 0) {
return cmp < 0; return cmp < 0;
} }
@ -2741,7 +2741,7 @@ public:
const SI_CHAR * a_pInputData) const SI_CHAR * a_pInputData)
{ {
// ASCII/MBCS/UTF-8 needs no conversion // 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. /** Convert the input string to the storage format of this data.
@ -2763,7 +2763,7 @@ public:
size_t a_uOutputDataSize) size_t a_uOutputDataSize)
{ {
// calc input string length (SI_CHAR type and size independent) // 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) { if (uInputLen > a_uOutputDataSize) {
return false; return false;
} }
@ -3195,12 +3195,12 @@ template<class SI_CHAR>
struct SI_NoCase { struct SI_NoCase {
bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const { bool operator()(const SI_CHAR * pLeft, const SI_CHAR * pRight) const {
if (sizeof(SI_CHAR) == sizeof(char)) { if (sizeof(SI_CHAR) == sizeof(char)) {
return _mbsicmp((const unsigned char *)pLeft, return _mbsicmp(reinterpret_cast<const unsigned char *>(pLeft),
(const unsigned char *)pRight) < 0; reinterpret_cast<const unsigned char *>(pRight)) < 0;
} }
if (sizeof(SI_CHAR) == sizeof(wchar_t)) { if (sizeof(SI_CHAR) == sizeof(wchar_t)) {
return _wcsicmp((const wchar_t *)pLeft, return _wcsicmp(reinterpret_cast<const wchar_t *>(pLeft),
(const wchar_t *)pRight) < 0; reinterpret_cast<const wchar_t *>(pRight)) < 0;
} }
return SI_GenericNoCase<SI_CHAR>()(pLeft, pRight); return SI_GenericNoCase<SI_CHAR>()(pLeft, pRight);
} }
@ -3251,9 +3251,9 @@ public:
int retval = MultiByteToWideChar( int retval = MultiByteToWideChar(
m_uCodePage, 0, m_uCodePage, 0,
a_pInputData, (int) a_uInputDataLen, a_pInputData, static_cast<int> (a_uInputDataLen),
0, 0); 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. /** Convert the input string from the storage format to SI_CHAR.
@ -3277,8 +3277,8 @@ public:
{ {
int nSize = MultiByteToWideChar( int nSize = MultiByteToWideChar(
m_uCodePage, 0, m_uCodePage, 0,
a_pInputData, (int) a_uInputDataLen, a_pInputData, static_cast<int> (a_uInputDataLen),
(wchar_t *) a_pOutputData, (int) a_uOutputDataSize); static_cast<wchar_t *> (a_pOutputData), static_cast<int> (a_uOutputDataSize));
return (nSize > 0); return (nSize > 0);
} }
@ -3297,9 +3297,9 @@ public:
{ {
int retval = WideCharToMultiByte( int retval = WideCharToMultiByte(
m_uCodePage, 0, m_uCodePage, 0,
(const wchar_t *) a_pInputData, -1, static_cast<const wchar_t *> (a_pInputData), -1,
0, 0, 0, 0); 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. /** Convert the input string to the storage format of this data.
@ -3322,8 +3322,8 @@ public:
{ {
int retval = WideCharToMultiByte( int retval = WideCharToMultiByte(
m_uCodePage, 0, m_uCodePage, 0,
(const wchar_t *) a_pInputData, -1, static_cast<const wchar_t *> (a_pInputData), -1,
a_pOutputData, (int) a_uOutputDataSize, 0, 0); a_pOutputData, static_cast<int> (a_uOutputDataSize), 0, 0);
return retval > 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 // set the array size
void CBotStringArray::SetSize(int nNewSize) void CBotStringArray::SetSize(int nNewSize)
@ -618,15 +606,14 @@ void CBotStringArray::SetSize(int nNewSize)
// shrink to nothing // shrink to nothing
DestructElements(m_pData, m_nSize); DestructElements(m_pData, m_nSize);
// delete[] static_cast<unsigned char *>(m_pData); delete[] reinterpret_cast<unsigned char *>(m_pData);
delete[] (unsigned char *)m_pData;
m_pData = NULL; m_pData = NULL;
m_nSize = m_nMaxSize = 0; m_nSize = m_nMaxSize = 0;
} }
else if (m_pData == NULL) else if (m_pData == NULL)
{ {
// create one with exact size // 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); ConstructElements(m_pData, nNewSize);
@ -663,7 +650,7 @@ void CBotStringArray::SetSize(int nNewSize)
else else
nNewMax = nNewSize; // no slush 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 // copy new data from old
memcpy(pNewData, m_pData, m_nSize * sizeof(CBotString)); 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) // 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_pData = pNewData;
m_nSize = nNewSize; m_nSize = nNewSize;
m_nMaxSize = nNewMax; m_nMaxSize = nNewMax;

View File

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

View File

@ -23,16 +23,24 @@
#include "common/logger.h" #include "common/logger.h"
#include "common/iman.h" #include "common/iman.h"
#include "common/image.h" #include "common/image.h"
#include "common/key.h"
#include "graphics/opengl/gldevice.h" #include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <SDL/SDL_image.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 //! Interval of timer called to update joystick state
@ -62,8 +70,8 @@ struct ApplicationPrivate
ApplicationPrivate() ApplicationPrivate()
{ {
memset(&currentEvent, 0, sizeof(SDL_Event)); memset(&currentEvent, 0, sizeof(SDL_Event));
surface = NULL; surface = nullptr;
joystick = NULL; joystick = nullptr;
joystickTimer = 0; joystickTimer = 0;
} }
}; };
@ -76,14 +84,10 @@ CApplication::CApplication()
m_iMan = new CInstanceManager(); m_iMan = new CInstanceManager();
m_eventQueue = new CEventQueue(m_iMan); m_eventQueue = new CEventQueue(m_iMan);
m_engine = NULL; m_engine = nullptr;
m_device = NULL; m_device = nullptr;
m_robotMain = NULL; m_robotMain = nullptr;
m_sound = NULL; m_sound = nullptr;
m_keyState = 0;
m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f);
m_axeJoy = Math::Vector(0.0f, 0.0f, 0.0f);
m_exitCode = 0; m_exitCode = 0;
m_active = false; m_active = false;
@ -91,29 +95,57 @@ CApplication::CApplication()
m_windowTitle = "COLOBOT"; 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_joystickEnabled = false;
m_kmodState = 0;
m_mouseButtonsState = 0;
m_trackedKeys = 0;
m_dataPath = "./data"; m_dataPath = "./data";
ResetKey(); m_language = LANG_ENGLISH;
} }
CApplication::~CApplication() CApplication::~CApplication()
{ {
delete m_private; delete m_private;
m_private = NULL; m_private = nullptr;
delete m_eventQueue; delete m_eventQueue;
m_eventQueue = NULL; m_eventQueue = nullptr;
delete m_iMan; 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 waitDataDir = false;
bool waitLogLevel = false; bool waitLogLevel = false;
bool waitLanguage = false;
for (int i = 1; i < argc; ++i) for (int i = 1; i < argc; ++i)
{ {
@ -123,6 +155,7 @@ bool CApplication::ParseArguments(int argc, char *argv[])
{ {
waitDataDir = false; waitDataDir = false;
m_dataPath = arg; m_dataPath = arg;
GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str());
continue; continue;
} }
@ -142,7 +175,23 @@ bool CApplication::ParseArguments(int argc, char *argv[])
else if (arg == "none") else if (arg == "none")
GetLogger()->SetLogLevel(LOG_NONE); GetLogger()->SetLogLevel(LOG_NONE);
else 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; continue;
} }
@ -158,34 +207,95 @@ bool CApplication::ParseArguments(int argc, char *argv[])
{ {
waitDataDir = true; 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 else
{ {
m_exitCode = 1; m_exitCode = 1;
return false; return PARSE_ARGS_FAIL;
} }
} }
// Args not given? // Args not given?
if (waitDataDir || waitLogLevel) if (waitDataDir || waitLogLevel || waitLanguage)
return false; return PARSE_ARGS_FAIL;
return true; return PARSE_ARGS_OK;
} }
bool CApplication::Create() bool CApplication::Create()
{ {
GetLogger()->Info("Creating CApplication\n"); 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 // Temporarily -- only in windowed mode
m_deviceConfig.fullScreen = false; m_deviceConfig.fullScreen = false;
/* // Create the sound instance. // Create the sound instance.
m_sound = new CSound(m_iMan); m_sound = new CSoundInterface();
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan); */
std::string standardInfoMessage = std::string standardInfoMessage =
@ -218,7 +328,7 @@ bool CApplication::Create()
if (! CreateVideoSurface()) if (! CreateVideoSurface())
return false; // dialog is in function 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") + m_errorMessage = std::string("SDL error while setting video mode:\n") +
std::string(SDL_GetError()); std::string(SDL_GetError());
@ -261,6 +371,11 @@ bool CApplication::Create()
return false; return false;
} }
// Create the robot application.
m_robotMain = new CRobotMain(m_iMan, this);
m_robotMain->ChangePhase(PHASE_WELCOME1);
GetLogger()->Info("CApplication created successfully\n"); GetLogger()->Info("CApplication created successfully\n");
return true; return true;
@ -269,7 +384,7 @@ bool CApplication::Create()
bool CApplication::CreateVideoSurface() bool CApplication::CreateVideoSurface()
{ {
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL) if (videoInfo == nullptr)
{ {
m_errorMessage = std::string("SDL error while getting video info:\n ") + m_errorMessage = std::string("SDL error while getting video info:\n ") +
std::string(SDL_GetError()); std::string(SDL_GetError());
@ -321,44 +436,46 @@ bool CApplication::CreateVideoSurface()
void CApplication::Destroy() void CApplication::Destroy()
{ {
/*if (m_robotMain != NULL) m_joystickEnabled = false;
if (m_robotMain != nullptr)
{ {
delete m_robotMain; delete m_robotMain;
m_robotMain = NULL; m_robotMain = nullptr;
} }
if (m_sound != NULL) if (m_sound != nullptr)
{ {
delete m_sound; delete m_sound;
m_sound = NULL; m_sound = nullptr;
}*/ }
if (m_engine != NULL) if (m_engine != nullptr)
{ {
m_engine->Destroy(); m_engine->Destroy();
delete m_engine; delete m_engine;
m_engine = NULL; m_engine = nullptr;
} }
if (m_device != NULL) if (m_device != nullptr)
{ {
m_device->Destroy(); m_device->Destroy();
delete m_device; delete m_device;
m_device = NULL; m_device = nullptr;
} }
if (m_private->joystick != NULL) if (m_private->joystick != nullptr)
{ {
SDL_JoystickClose(m_private->joystick); 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); SDL_FreeSurface(m_private->surface);
m_private->surface = NULL; m_private->surface = nullptr;
} }
IMG_Quit(); IMG_Quit();
@ -383,7 +500,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
return false; return false;
} }
if (m_private->surface == NULL) if (m_private->surface == nullptr)
{ {
if (! restore) if (! restore)
{ {
@ -426,7 +543,7 @@ bool CApplication::OpenJoystick()
return false; return false;
m_private->joystick = SDL_JoystickOpen(m_joystick.index); m_private->joystick = SDL_JoystickOpen(m_joystick.index);
if (m_private->joystick == NULL) if (m_private->joystick == nullptr)
return false; return false;
m_joystick.axisCount = SDL_JoystickNumAxes(m_private->joystick); m_joystick.axisCount = SDL_JoystickNumAxes(m_private->joystick);
@ -437,7 +554,7 @@ bool CApplication::OpenJoystick()
m_joyButtonState = std::vector<bool>(m_joystick.buttonCount, false); m_joyButtonState = std::vector<bool>(m_joystick.buttonCount, false);
// Create a timer for polling joystick state // 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; return true;
} }
@ -447,7 +564,7 @@ void CApplication::CloseJoystick()
// Timer will remove itself automatically // Timer will remove itself automatically
SDL_JoystickClose(m_private->joystick); SDL_JoystickClose(m_private->joystick);
m_private->joystick = NULL; m_private->joystick = nullptr;
} }
bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick) bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
@ -455,7 +572,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
if ( (newJoystick.index < 0) || (newJoystick.index >= SDL_NumJoysticks()) ) if ( (newJoystick.index < 0) || (newJoystick.index >= SDL_NumJoysticks()) )
return false; return false;
if (m_private->joystick != NULL) if (m_private->joystick != nullptr)
CloseJoystick(); CloseJoystick();
return OpenJoystick(); return OpenJoystick();
@ -464,7 +581,7 @@ bool CApplication::ChangeJoystick(const JoystickDevice &newJoystick)
Uint32 JoystickTimerCallback(Uint32 interval, void *) Uint32 JoystickTimerCallback(Uint32 interval, void *)
{ {
CApplication *app = CApplication::GetInstancePointer(); CApplication *app = CApplication::GetInstancePointer();
if ((app == NULL) || (! app->GetJoystickEnabled())) if ((app == nullptr) || (! app->GetJoystickEnabled()))
return 0; // don't run the timer again return 0; // don't run the timer again
app->UpdateJoystick(); app->UpdateJoystick();
@ -540,6 +657,10 @@ int CApplication::Run()
{ {
m_active = true; m_active = true;
GetCurrentTimeStamp(m_baseTimeStamp);
GetCurrentTimeStamp(m_lastTimeStamp);
GetCurrentTimeStamp(m_curTimeStamp);
while (true) while (true)
{ {
// To be sure no old event remains // To be sure no old event remains
@ -577,12 +698,24 @@ int CApplication::Run()
{ {
bool passOn = ProcessEvent(event); bool passOn = ProcessEvent(event);
if (m_engine != NULL && passOn) if (m_engine != nullptr && passOn)
passOn = m_engine->ProcessEvent(event); passOn = m_engine->ProcessEvent(event);
if (passOn) if (passOn)
m_eventQueue->AddEvent(event); 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); passOn = ProcessEvent(event);
if (passOn && m_engine != NULL) if (passOn && m_engine != nullptr)
passOn = m_engine->ProcessEvent(event); passOn = m_engine->ProcessEvent(event);
} }
/*if (passOn && m_robotMain != NULL) if (passOn && m_robotMain != nullptr)
m_robotMain->ProcessEvent(event); */ m_robotMain->EventProcess(event);
} }
/* Update mouse position explicitly right before rendering /* 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) // Update game and render a frame during idle time (no messages are waiting)
Render(); Render();
// Update simulation state
StepSimulation();
} }
} }
@ -664,6 +800,7 @@ Event CApplication::ParseEvent()
else else
event.type = EVENT_KEY_UP; event.type = EVENT_KEY_UP;
event.key.virt = false;
event.key.key = m_private->currentEvent.key.keysym.sym; event.key.key = m_private->currentEvent.key.keysym.sym;
event.key.mod = m_private->currentEvent.key.keysym.mod; event.key.mod = m_private->currentEvent.key.keysym.mod;
event.key.state = TranslatePressState(m_private->currentEvent.key.state); event.key.state = TranslatePressState(m_private->currentEvent.key.state);
@ -671,6 +808,22 @@ Event CApplication::ParseEvent()
} }
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) || else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) ) (m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
{
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
{ {
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
event.type = EVENT_MOUSE_BUTTON_DOWN; event.type = EVENT_MOUSE_BUTTON_DOWN;
@ -682,6 +835,7 @@ Event CApplication::ParseEvent()
event.mouseButton.pos = m_engine->WindowToInterfaceCoords( event.mouseButton.pos = m_engine->WindowToInterfaceCoords(
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
} }
}
else if (m_private->currentEvent.type == SDL_MOUSEMOTION) else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
{ {
event.type = EVENT_MOUSE_MOVE; event.type = EVENT_MOUSE_MOVE;
@ -725,18 +879,93 @@ Event CApplication::ParseEvent()
return event; 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 * Processes incoming events. It is the first function called after an event is captured.
or \c false if not. */ * Event is modified, updating its tracked keys state and mouse position to current values.
bool CApplication::ProcessEvent(const Event &event) * 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(); CLogger *l = GetLogger();
event.trackedKeys = m_trackedKeys;
if (GetSystemMouseVisibile())
event.mousePos = m_systemMousePos;
else
event.mousePos = m_engine->GetMousePos();
if (event.type == EVENT_ACTIVE) if (event.type == EVENT_ACTIVE)
{ {
m_active = event.active.gain;
if (m_debugMode) 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 // 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_DOWN:
case EVENT_KEY_UP: case EVENT_KEY_UP:
l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "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(" key = %4x\n", event.key.key);
l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED"); l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
l->Info(" mod = %4x\n", event.key.mod); 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(" 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); l->Info(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y);
break; 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: case EVENT_JOY_AXIS:
l->Info("EVENT_JOY_AXIS:\n"); l->Info("EVENT_JOY_AXIS:\n");
l->Info(" axis = %d\n", event.joyAxis.axis); l->Info(" axis = %d\n", event.joyAxis.axis);
@ -789,6 +1024,48 @@ bool CApplication::ProcessEvent(const Event &event)
return true; 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 */ /** Renders the frame and swaps buffers as necessary */
void CApplication::Render() void CApplication::Render()
{ {
@ -798,9 +1075,101 @@ void CApplication::Render()
SDL_GL_SwapBuffers(); 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() Gfx::GLDeviceConfig CApplication::GetVideoConfig()
@ -814,7 +1183,7 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint
resolutions.clear(); resolutions.clear();
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (videoInfo == NULL) if (videoInfo == nullptr)
return VIDEO_QUERY_ERROR; return VIDEO_QUERY_ERROR;
Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE; Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
@ -861,25 +1230,31 @@ bool CApplication::GetDebugMode()
return m_debugMode; 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 (m_mouseButtonsState & (1<<index)) != 0;
return 0; }
void CApplication::ResetKeyStates()
{
m_trackedKeys = 0;
m_kmodState = 0;
m_robotMain->ResetKeyStates();
} }
void CApplication::SetGrabInput(bool grab) void CApplication::SetGrabInput(bool grab)
@ -964,3 +1339,13 @@ std::string CApplication::GetDataFilePath(const std::string& dirName, const std:
{ {
return m_dataPath + "/" + dirName + "/" + fileName; 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 #pragma once
#include "common/global.h"
#include "common/misc.h"
#include "common/singleton.h" #include "common/singleton.h"
#include "graphics/core/device.h" #include "graphics/core/device.h"
#include "graphics/engine/engine.h" #include "graphics/engine/engine.h"
@ -36,11 +35,12 @@
class CInstanceManager; class CInstanceManager;
class CEvent; class CEvent;
class CRobotMain; class CRobotMain;
class CSound; class CSoundInterface;
/** /**
\struct JoystickDevice * \struct JoystickDevice
\brief Information about a joystick device */ * \brief Information about a joystick device
*/
struct JoystickDevice struct JoystickDevice
{ {
//! Device index (-1 = invalid device) //! Device index (-1 = invalid device)
@ -57,8 +57,9 @@ struct JoystickDevice
}; };
/** /**
\enum VideoQueryResult * \enum VideoQueryResult
\brief Result of querying for available video resolutions */ * \brief Result of querying for available video resolutions
*/
enum VideoQueryResult enum VideoQueryResult
{ {
VIDEO_QUERY_ERROR, 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; struct ApplicationPrivate;
/** /**
@ -82,7 +112,7 @@ struct ApplicationPrivate;
* \section Creation Creation of other main objects * \section Creation Creation of other main objects
* *
* The class creates the only instance of CInstanceManager, CEventQueue, CEngine, * The class creates the only instance of CInstanceManager, CEventQueue, CEngine,
* CRobotMain and CSound classes. * CRobotMain and CSoundInterface classes.
* *
* \section Window Window management * \section Window Window management
* *
@ -123,7 +153,7 @@ public:
public: public:
//! Parses commandline arguments //! Parses commandline arguments
bool ParseArguments(int argc, char *argv[]); ParseArgsStatus ParseArguments(int argc, char *argv[]);
//! Initializes the application //! Initializes the application
bool Create(); bool Create();
//! Main event loop //! Main event loop
@ -147,8 +177,37 @@ public:
//! Change the video mode to given mode //! Change the video mode to given mode
bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig); 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 //! 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 //! Returns a list of available joystick devices
std::vector<JoystickDevice> GetJoystickList(); std::vector<JoystickDevice> GetJoystickList();
@ -159,10 +218,11 @@ public:
//! Change the current joystick device //! Change the current joystick device
bool ChangeJoystick(const JoystickDevice &newJoystick); bool ChangeJoystick(const JoystickDevice &newJoystick);
//! Enables/disables joystick //! Management of joystick enable state
//@{
void SetJoystickEnabled(bool enable); void SetJoystickEnabled(bool enable);
//! Returns whether joystick is enabled
bool GetJoystickEnabled(); bool GetJoystickEnabled();
//@}
//! Polls the state of joystick axes and buttons //! Polls the state of joystick axes and buttons
void UpdateJoystick(); void UpdateJoystick();
@ -170,42 +230,63 @@ public:
//! Updates the mouse position explicitly //! Updates the mouse position explicitly
void UpdateMouse(); void UpdateMouse();
void FlushPressKey(); //! Returns the current key modifiers
void ResetKey(); int GetKmods();
void SetKey(int keyRank, int option, int key); //! Returns whether the given kmod is active
int GetKey(int keyRank, int option); 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); void SetGrabInput(bool grab);
//! Returns the grab mode
bool GetGrabInput(); bool GetGrabInput();
//@}
//! Sets the visiblity of system mouse cursor //! Management of the visiblity of system mouse cursor
//@{
void SetSystemMouseVisible(bool visible); void SetSystemMouseVisible(bool visible);
//! Returns the visiblity of system mouse cursor
bool GetSystemMouseVisibile(); 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); void SetSystemMousePos(Math::Point pos);
//! Returns the position of system mouse cursor (in interface coords)
Math::Point GetSystemMousePos(); 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); void SetDebugMode(bool mode);
//! Returns whether debug mode is enabled
bool GetDebugMode(); bool GetDebugMode();
//@}
//! Returns the full path to a file in data directory //! Returns the full path to a file in data directory
std::string GetDataFilePath(const std::string &dirName, const std::string &fileName); std::string GetDataFilePath(const std::string &dirName, const std::string &fileName);
//! Management of language
//@{
Language GetLanguage();
void SetLanguage(Language language);
//@}
protected: protected:
//! Creates the window's SDL_Surface //! Creates the window's SDL_Surface
bool CreateVideoSurface(); bool CreateVideoSurface();
//! Processes the captured SDL event to Event struct //! Processes the captured SDL event to Event struct
Event ParseEvent(); 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 //! Handles some incoming events
bool ProcessEvent(const Event &event); bool ProcessEvent(Event &event);
//! Renders the image in window //! Renders the image in window
void Render(); void Render();
@ -226,7 +307,7 @@ protected:
//! Graphics device //! Graphics device
Gfx::CDevice* m_device; Gfx::CDevice* m_device;
//! Sound subsystem //! Sound subsystem
CSound* m_sound; CSoundInterface* m_sound;
//! Main class of the proper game engine //! Main class of the proper game engine
CRobotMain* m_robotMain; CRobotMain* m_robotMain;
@ -248,13 +329,36 @@ protected:
//! Text set as window title //! Text set as window title
std::string m_windowTitle; std::string m_windowTitle;
int m_keyState; //! Animation time stamps, etc.
Math::Vector m_axeKey; //@{
Math::Vector m_axeJoy; SystemTimeStamp* m_baseTimeStamp;
Math::Point m_systemMousePos; SystemTimeStamp* m_lastTimeStamp;
long m_mouseWheel; 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 //! Info about current joystick device
JoystickDevice m_joystick; JoystickDevice m_joystick;
@ -267,5 +371,8 @@ protected:
//! Path to directory with data files //! Path to directory with data files
std::string m_dataPath; 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 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"); SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
return app.GetExitCode(); return app.GetExitCode();
} }
else if (status == PARSE_ARGS_HELP)
{
return app.GetExitCode();
}
int code = 0; int code = 0;

View File

@ -48,18 +48,18 @@ struct SystemTimeStamp
// Convert a wide Unicode string to an UTF8 string // Convert a wide Unicode string to an UTF8 string
std::string UTF8_Encode_Windows(const std::wstring &wstr) 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); 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; return strTo;
} }
// Convert an UTF8 string to a wide Unicode String // Convert an UTF8 string to a wide Unicode String
std::wstring UTF8_Decode_Windows(const std::string &str) 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); 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; return wstrTo;
} }

View File

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

View File

@ -19,6 +19,16 @@
#include "common/event.h" #include "common/event.h"
#include "common/iman.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) CEventQueue::CEventQueue(CInstanceManager* iMan)

View File

@ -14,23 +14,26 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once
#include <common/key.h> #include "common/key.h"
#include <common/event_ids.h> #include "common/event_ids.h"
#include <math/point.h> #include "math/point.h"
#include "math/vector.h"
#include <string.h>
class CInstanceManager; class CInstanceManager;
/** \enum PressState /**
\brief State of key/mouse button */ * \enum PressState
* \brief State of key/mouse button
*/
enum PressState enum PressState
{ {
STATE_PRESSED, 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 struct KeyEventData
{ {
//! STATE_PRESSED or STATE_RELEASED */ //! STATE_PRESSED or STATE_RELEASED */
PressState state; 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; unsigned int key;
//! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h) //! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h)
unsigned int mod; unsigned int mod;
//! Unicode character //! Unicode character
unsigned int unicode; unsigned int unicode;
KeyEventData()
: state(STATE_PRESSED), key(0), mod(0), unicode(0) {}
}; };
/** \struct MouseMotionEventData /** \struct MouseMotionEventData
@ -60,16 +64,15 @@ struct KeyEventData
struct MouseMoveEventData struct MouseMoveEventData
{ {
//! Current button state //! Current button state
unsigned char state; PressState state;
//! Position of mouse in normalized coordinates (0..1) //! Position of mouse in normalized coordinates (0..1)
Math::Point pos; 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 struct MouseButtonEventData
{ {
//! The mouse button index //! The mouse button index
@ -78,39 +81,58 @@ struct MouseButtonEventData
PressState state; PressState state;
//! Position of mouse in normalized coordinates (0..1) //! Position of mouse in normalized coordinates (0..1)
Math::Point pos; 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 struct JoyAxisEventData
{ {
//! The joystick axis index //! The joystick axis index
unsigned char axis; unsigned char axis;
//! The axis value (range: -32768 to 32767) //! The axis value (range: -32768 to 32767)
int value; 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 struct JoyButtonEventData
{ {
//! The joystick button index //! The joystick button index
unsigned char button; unsigned char button;
//! STATE_PRESSED or STATE_RELEASED //! STATE_PRESSED or STATE_RELEASED
PressState state; 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 enum ActiveEventFlags
{ {
//! Application window focus //! 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 struct ActiveEventData
{ {
//! Flags (bitmask of enum values ActiveEventFlags) //! Flags (bitmask of enum values ActiveEventFlags)
unsigned char flags; unsigned char flags;
//! True if the focus was gained; false otherwise //! True if the focus was gained; false otherwise
bool gain; bool gain;
ActiveEventData()
: flags(0), gain(false) {}
}; };
/** /**
\struct Event * \struct Event
\brief Event sent by system, interface or game * \brief Event sent by system, interface or game
*
Event is described by its type (EventType) and the union * Event is described by its type (EventType) and the union
\a data contains additional data about the event. * \a data contains additional data about the event.
Different members of the union are filled with different event types. * Different members of the union are filled with different event types.
With some events, nothing is filled (it's zeroed out). * With some events, nothing is filled (it's zeroed out).
The union contains roughly the same information as SDL_Event struct * The union contains roughly the same information as SDL_Event struct
but packaged to independent structs and fields. * but packaged to independent structs and fields.
**/ **/
struct Event struct Event
{ {
@ -163,6 +184,8 @@ struct Event
MouseButtonEventData mouseButton; MouseButtonEventData mouseButton;
//! Additional data for EVENT_MOUSE_MOVE //! Additional data for EVENT_MOUSE_MOVE
MouseMoveEventData mouseMove; MouseMoveEventData mouseMove;
//! Additional data for EVENT_MOUSE_WHEEL
MouseWheelEventData mouseWheel;
//! Additional data for EVENT_JOY //! Additional data for EVENT_JOY
JoyAxisEventData joyAxis; JoyAxisEventData joyAxis;
//! Additional data for EVENT_JOY_AXIS //! Additional data for EVENT_JOY_AXIS
@ -171,70 +194,49 @@ struct Event
ActiveEventData active; 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 long param; // parameter
Math::Point pos; // mouse position (0 .. 1)
float axeX; // control the X axis (-1 .. 1) // TODO: remove in longer term (use CApplication's new time functions instead)
float axeY; // control of the Y axis (-1 .. 1)
float axeZ; // control the Z axis (-1 .. 1)
short keyState; // state of the keyboard (KS_ *)
float rTime; // relative time float rTime; // relative time
Event(EventType aType = EVENT_NULL) Event(EventType aType = EVENT_NULL)
{ {
type = aType; type = aType;
systemEvent = false; systemEvent = false;
trackedKeys = 0;
param = 0; param = 0;
axeX = axeY = axeZ = 0.0f;
keyState = 0;
rTime = 0.0f; rTime = 0.0f;
} }
}; };
/** //! Returns an unique event type (above the standard IDs)
\enum KeyRank EventType GetUniqueEventType();
\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,
};
/** /**
\class CEventQueue * \class CEventQueue
\brief Global event queue * \brief Global event queue
*
Provides an interface to a global FIFO queue with events (both system- and user-generated). * 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. * The queue has a fixed maximum size but it should not be a problem.
*/ */
class CEventQueue class CEventQueue
{ {
@ -261,5 +263,3 @@ protected:
int m_tail; int m_tail;
int m_total; int m_total;
}; };

View File

@ -14,6 +14,9 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * along with this program. If not, see http://www.gnu.org/licenses/.
// TODO: move to event.h after restext rewrite
#pragma once #pragma once
/** /**
@ -38,6 +41,8 @@ enum EventType
EVENT_MOUSE_BUTTON_DOWN = 3, EVENT_MOUSE_BUTTON_DOWN = 3,
//! Event sent after releasing a mouse button //! Event sent after releasing a mouse button
EVENT_MOUSE_BUTTON_UP = 4, 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 sent after moving the mouse
EVENT_MOUSE_MOVE = 7, EVENT_MOUSE_MOVE = 7,
//! Event sent after pressing a key //! Event sent after pressing a key
@ -48,9 +53,6 @@ enum EventType
//! Event sent when application window loses/gains focus //! Event sent when application window loses/gains focus
EVENT_ACTIVE = 10, EVENT_ACTIVE = 10,
//? EVENT_CHAR = 10,
//? EVENT_FOCUS = 11,
//! Event sent after moving joystick axes //! Event sent after moving joystick axes
EVENT_JOY_AXIS = 12, EVENT_JOY_AXIS = 12,
//! Event sent after pressing a joystick button //! 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 // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #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 enum BuildType
{ {
BUILD_FACTORY = (1<<0), // factory BUILD_FACTORY = (1<<0), //! < factory
BUILD_DERRICK = (1<<1), // derrick BUILD_DERRICK = (1<<1), //! < derrick
BUILD_CONVERT = (1<<2), // converter BUILD_CONVERT = (1<<2), //! < converter
BUILD_RADAR = (1<<3), // radar BUILD_RADAR = (1<<3), //! < radar
BUILD_ENERGY = (1<<4), // factory of cells BUILD_ENERGY = (1<<4), //! < factory of cells
BUILD_NUCLEAR = (1<<5), // nuclear power plant BUILD_NUCLEAR = (1<<5), //! < nuclear power plant
BUILD_STATION = (1<<6), // base station BUILD_STATION = (1<<6), //! < base station
BUILD_REPAIR = (1<<7), // repair center BUILD_REPAIR = (1<<7), //! < repair center
BUILD_TOWER = (1<<8), // defense tower BUILD_TOWER = (1<<8), //! < defense tower
BUILD_RESEARCH = (1<<9), // research center BUILD_RESEARCH = (1<<9), //! < research center
BUILD_LABO = (1<<10), // laboratory BUILD_LABO = (1<<10), //! < laboratory
BUILD_PARA = (1<<11), // lightning protection BUILD_PARA = (1<<11), //! < lightning protection
BUILD_INFO = (1<<12), // information terminal BUILD_INFO = (1<<12), //! < information terminal
BUILD_GFLAT = (1<<16), // flat floor BUILD_GFLAT = (1<<16), //! < flat floor
BUILD_FLAG = (1<<17) // puts / removes colored flag 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 enum ResearchType
{ {
RESEARCH_TANK = (1<<0), // caterpillars RESEARCH_TANK = (1<<0), //! < caterpillars
RESEARCH_FLY = (1<<1), // wings RESEARCH_FLY = (1<<1), //! < wings
RESEARCH_CANON = (1<<2), // cannon RESEARCH_CANON = (1<<2), //! < cannon
RESEARCH_TOWER = (1<<3), // defense tower RESEARCH_TOWER = (1<<3), //! < defense tower
RESEARCH_ATOMIC = (1<<4), // nuclear RESEARCH_ATOMIC = (1<<4), //! < nuclear
RESEARCH_THUMP = (1<<5), // thumper RESEARCH_THUMP = (1<<5), //! < thumper
RESEARCH_SHIELD = (1<<6), // shield RESEARCH_SHIELD = (1<<6), //! < shield
RESEARCH_PHAZER = (1<<7), // phazer gun RESEARCH_PHAZER = (1<<7), //! < phazer gun
RESEARCH_iPAW = (1<<8), // legs of insects RESEARCH_iPAW = (1<<8), //! < legs of insects
RESEARCH_iGUN = (1<<9), // cannon of insects RESEARCH_iGUN = (1<<9), //! < cannon of insects
RESEARCH_RECYCLER = (1<<10), // recycler RESEARCH_RECYCLER = (1<<10), //! < recycler
RESEARCH_SUBM = (1<<11), // submarine RESEARCH_SUBM = (1<<11), //! < submarine
RESEARCH_SNIFFER = (1<<12) // sniffer 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_id; // unique identifier
extern long g_build; // constructible buildings extern int g_build; // constructible buildings
extern long g_researchDone; // research done extern int g_researchDone; // research done
extern long g_researchEnable; // research available extern long g_researchEnable; // research available
extern float g_unit; // conversion factor extern float g_unit; // conversion factor

View File

@ -21,6 +21,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <SDL/SDL_image.h> #include <SDL/SDL_image.h>
#include <png.h> #include <png.h>
@ -88,21 +90,21 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
/* Opening output file */ /* Opening output file */
fp = fopen(filename, "wb"); 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"); PNG_ERROR = std::string("Could not open file '") + std::string(filename) + std::string("' for saving");
return false; return false;
} }
/* Initializing png structures and callbacks */ /* Initializing png structures and callbacks */
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, PNGUserError, NULL); png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGUserError, nullptr);
if (png_ptr == NULL) if (png_ptr == nullptr)
return false; return false;
info_ptr = png_create_info_struct(png_ptr); 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!"; PNG_ERROR = "png_create_info_struct() error!";
return false; return false;
} }
@ -142,7 +144,7 @@ bool PNGSaveSurface(const char *filename, SDL_Surface *surf)
CImage::CImage() CImage::CImage()
{ {
m_data = NULL; m_data = nullptr;
} }
CImage::~CImage() CImage::~CImage()
@ -150,22 +152,22 @@ CImage::~CImage()
Free(); Free();
} }
bool CImage::IsEmpty() bool CImage::IsEmpty() const
{ {
return m_data == NULL; return m_data == nullptr;
} }
void CImage::Free() 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); SDL_FreeSurface(m_data->surface);
m_data->surface = NULL; m_data->surface = nullptr;
} }
delete m_data; delete m_data;
m_data = NULL; m_data = nullptr;
} }
} }
@ -174,6 +176,118 @@ ImageData* CImage::GetData()
return m_data; 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() std::string CImage::GetError()
{ {
return m_error; return m_error;
@ -189,10 +303,10 @@ bool CImage::Load(const std::string& fileName)
m_error = ""; m_error = "";
m_data->surface = IMG_Load(fileName.c_str()); m_data->surface = IMG_Load(fileName.c_str());
if (m_data->surface == NULL) if (m_data->surface == nullptr)
{ {
delete m_data; delete m_data;
m_data = NULL; m_data = nullptr;
m_error = std::string(IMG_GetError()); m_error = std::string(IMG_GetError());
return false; return false;

View File

@ -14,10 +14,15 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once
#include "graphics/core/color.h"
#include "math/intpoint.h"
#include <stddef.h> #include <stddef.h>
#include <string> #include <string>
@ -61,12 +66,21 @@ public:
//! Frees the allocated image data //! Frees the allocated image data
void Free(); void Free();
//! Returns whether the image is empty (has NULL data) //! Returns whether the image is empty (has null data)
bool IsEmpty(); bool IsEmpty() const;
//! Returns the image data; if empty - returns NULL //! Returns the image data; if empty - returns nullptr
ImageData* GetData(); 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 //! Loads an image from the specified file
bool Load(const std::string &fileName); bool Load(const std::string &fileName);

View File

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

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once
@ -22,36 +25,119 @@
#include <common/misc.h> #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; //! CEventQueue
int totalUsed; CLASS_EVENT = 1,
void** classPointer; //! 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> class CInstanceManager : public CSingleton<CInstanceManager>
{ {
public: public:
CInstanceManager(); CInstanceManager();
~CInstanceManager(); ~CInstanceManager();
//! Remove all managed instances
void Flush(); void Flush();
void Flush(ClassType classType); //! Removes instances of one type of class
bool AddInstance(ClassType classType, void* pointer, int max=1); void Flush(ManagedClassType classType);
bool DeleteInstance(ClassType classType, void* pointer); //! Registers new instance of class type
void* SearchInstance(ClassType classType, int rank=0); 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& GetInstance();
static CInstanceManager* GetInstancePointer(); static CInstanceManager* GetInstancePointer();
protected: protected:
void Compress(ClassType classType); //! Fills holes in instance table
void Compress(ManagedClassType classType);
protected: 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 // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once

View File

@ -29,6 +29,32 @@
// If need arises, it can be changed to custom function or anything else // If need arises, it can be changed to custom function or anything else
#define KEY(x) SDLK_ ## x #define KEY(x) SDLK_ ## x
// Key modifier defined as concatenation to KMOD_... // Key modifier defined as concatenation to KMOD_...
// If need arises, it can be changed to custom function or anything else // If need arises, it can be changed to custom function or anything else
#define KEY_MOD(x) KMOD_ ## x #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 // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once
#include "common/singleton.h"
#include <string> #include <string>
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
#include <common/singleton.h>
/**
* @file common/logger.h
* @brief Class for loggin information to file or console
*/
/** /**
* \public * \public

View File

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

View File

@ -17,195 +17,171 @@
// misc.cpp // misc.cpp
#include "common/misc.h"
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <direct.h>
#include <time.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 bool g_bUserDir = false;
static char g_userDir[100] = ""; 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. // Returns a non-accented letter.
char RetNoAccent(char letter) char GetNoAccent(char letter)
{ {
/*
if ( letter < 0 ) if ( letter < 0 )
{ {
if ( letter == 'á' || if ( letter == '<EFBFBD>' ||
letter == 'à' || letter == '<EFBFBD>' ||
letter == 'â' || letter == '<EFBFBD>' ||
letter == 'ä' || letter == '<EFBFBD>' ||
letter == 'ã' ) return 'a'; letter == '<EFBFBD>' ) return 'a';
if ( letter == 'é' || if ( letter == '<EFBFBD>' ||
letter == 'è' || letter == '<EFBFBD>' ||
letter == 'ê' || letter == '<EFBFBD>' ||
letter == 'ë' ) return 'e'; letter == '<EFBFBD>' ) return 'e';
if ( letter == 'í' || if ( letter == '<EFBFBD>' ||
letter == 'ì' || letter == '<EFBFBD>' ||
letter == 'î' || letter == '<EFBFBD>' ||
letter == 'ï' ) return 'i'; letter == '<EFBFBD>' ) return 'i';
if ( letter == 'ó' || if ( letter == '<EFBFBD>' ||
letter == 'ò' || letter == '<EFBFBD>' ||
letter == 'ô' || letter == '<EFBFBD>' ||
letter == 'ö' || letter == '<EFBFBD>' ||
letter == 'õ' ) return 'o'; letter == '<EFBFBD>' ) return 'o';
if ( letter == 'ú' || if ( letter == '<EFBFBD>' ||
letter == 'ù' || letter == '<EFBFBD>' ||
letter == 'û' || letter == '<EFBFBD>' ||
letter == 'ü' ) return 'u'; letter == '<EFBFBD>' ) return 'u';
if ( letter == 'ç' ) return 'c'; if ( letter == '<EFBFBD>' ) return 'c';
if ( letter == 'ñ' ) return 'n'; if ( letter == '<EFBFBD>' ) return 'n';
if ( letter == 'Á' || if ( letter == '<EFBFBD>' ||
letter == 'À' || letter == '<EFBFBD>' ||
letter == 'Â' || letter == '<EFBFBD>' ||
letter == 'Ä' || letter == '<EFBFBD>' ||
letter == 'Ã' ) return 'A'; letter == '<EFBFBD>' ) return 'A';
if ( letter == 'É' || if ( letter == '<EFBFBD>' ||
letter == 'È' || letter == '<EFBFBD>' ||
letter == 'Ê' || letter == '<EFBFBD>' ||
letter == 'Ë' ) return 'E'; letter == '<EFBFBD>' ) return 'E';
if ( letter == 'Í' || if ( letter == '<EFBFBD>' ||
letter == 'Ì' || letter == '<EFBFBD>' ||
letter == 'Î' || letter == '<EFBFBD>' ||
letter == 'Ï' ) return 'I'; letter == '<EFBFBD>' ) return 'I';
if ( letter == 'Ó' || if ( letter == '<EFBFBD>' ||
letter == 'Ò' || letter == '<EFBFBD>' ||
letter == 'Ô' || letter == '<EFBFBD>' ||
letter == 'Ö' || letter == '<EFBFBD>' ||
letter == 'Õ' ) return 'O'; letter == '<EFBFBD>' ) return 'O';
if ( letter == 'Ú' || if ( letter == '<EFBFBD>' ||
letter == 'Ù' || letter == '<EFBFBD>' ||
letter == 'Û' || letter == '<EFBFBD>' ||
letter == 'Ü' ) return 'U'; letter == '<EFBFBD>' ) return 'U';
if ( letter == 'Ç' ) return 'C'; if ( letter == '<EFBFBD>' ) return 'C';
if ( letter == 'Ñ' ) return 'N'; if ( letter == '<EFBFBD>' ) return 'N';
} }*/
return letter; return letter;
} }
// Returns an uppercase letter. // Returns an uppercase letter.
char RetToUpper(char letter) char GetToUpper(char letter)
{ {
if ( letter < 0 ) /*if ( letter < 0 )
{ {
if ( letter == 'á' ) return 'Á'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'à' ) return 'À'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'â' ) return 'Â'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ä' ) return 'Ä'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ã' ) return 'Ã'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'é' ) return 'É'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'è' ) return 'È'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ê' ) return 'Ê'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ë' ) return 'Ë'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'í' ) return 'Í'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ì' ) return 'Ì'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'î' ) return 'Î'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ï' ) return 'Ï'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ó' ) return 'Ó'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ò' ) return 'Ò'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ô' ) return 'Ô'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ö' ) return 'Ö'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'õ' ) return 'Õ'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ú' ) return 'Ú'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ù' ) return 'Ù'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'û' ) return 'Û'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ü' ) return 'Ü'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ç' ) return 'Ç'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'ñ' ) return 'Ñ'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
} }*/
return toupper(letter); return toupper(letter);
} }
// Returns a lowercase letter. // Returns a lowercase letter.
char RetToLower(char letter) char GetToLower(char letter)
{ {
if ( letter < 0 ) /*if ( letter < 0 )
{ {
if ( letter == 'Á' ) return 'á'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'À' ) return 'à'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Â' ) return 'â'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ä' ) return 'ä'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ã' ) return 'ã'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'É' ) return 'é'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'È' ) return 'è'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ê' ) return 'ê'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ë' ) return 'ë'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Í' ) return 'í'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ì' ) return 'ì'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Î' ) return 'î'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ï' ) return 'ï'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ó' ) return 'ó'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ò' ) return 'ò'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ô' ) return 'ô'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ö' ) return 'ö'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Õ' ) return 'õ'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ú' ) return 'ú'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ù' ) return 'ù'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Û' ) return 'û'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ü' ) return 'ü'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ç' ) return 'ç'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
if ( letter == 'Ñ' ) return 'ñ'; if ( letter == '<EFBFBD>' ) return '<EFBFBD>';
} }*/
return tolower(letter); return tolower(letter);
} }
@ -222,6 +198,7 @@ void TimeToAscii(time_t time, char *buffer)
year = when.tm_year+1900; year = when.tm_year+1900;
if ( year < 2000 ) year -= 1900; if ( year < 2000 ) year -= 1900;
else year -= 2000; else year -= 2000;
/* TODO
#if _FRENCH #if _FRENCH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d", sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year, 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_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min); when.tm_hour, when.tm_min);
#endif #endif
#if _ENGLISH #if _ENGLISH*/
char format[10]; char format[10];
int hour; int hour;
@ -251,12 +228,12 @@ void TimeToAscii(time_t time, char *buffer)
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s", sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d %s",
when.tm_mon+1, when.tm_mday, year, when.tm_mon+1, when.tm_mday, year,
hour, when.tm_min, format); hour, when.tm_min, format);
#endif /*#endif
#if _POLISH #if _POLISH
sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d", sprintf(buffer, "%.2d.%.2d.%.2d %.2d:%.2d",
when.tm_mday, when.tm_mon+1, year, when.tm_mday, when.tm_mon+1, year,
when.tm_hour, when.tm_min); when.tm_hour, when.tm_min);
#endif #endif*/
} }
@ -281,7 +258,7 @@ bool Xfer(char* src, char* dst)
return false; return false;
} }
buffer = (char*)malloc(10000); buffer = static_cast<char*>(malloc(10000));
while ( true ) while ( true )
{ {
@ -311,7 +288,9 @@ bool CopyFileToTemp(char* filename)
UserDir(dst, filename, "textures"); UserDir(dst, filename, "textures");
strcpy(g_userDir, save); strcpy(g_userDir, save);
_mkdir("temp"); //_mkdir("temp");
system("mkdir temp");
if ( !Xfer(src, dst) ) return false; if ( !Xfer(src, dst) ) return false;
strcpy(filename, dst); 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. // 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? if ( strchr(filename, '.') != 0 ) return; // already an extension?
strcat(filename, ext); strcat(filename, ext);
@ -368,7 +347,7 @@ void AddExt(char* filename, char* ext)
// Specifies the user folder. // Specifies the user folder.
void UserDir(bool bUser, char* dir) void UserDir(bool bUser, const char* dir)
{ {
g_bUserDir = bUser; g_bUserDir = bUser;
strcpy(g_userDir, dir); strcpy(g_userDir, dir);
@ -379,10 +358,10 @@ void UserDir(bool bUser, char* dir)
// def = "abc\" // def = "abc\"
// out: buffer = "abc\toto.txt" // 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 ddir[100];
char* add; const char* add;
if ( strstr(dir, "\\") == 0 && def[0] != 0 ) if ( strstr(dir, "\\") == 0 && def[0] != 0 )
{ {
@ -418,24 +397,3 @@ void UserDir(char* buffer, char* dir, char* def)
} }
*buffer = 0; *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 <time.h>
#include "common/metafile.h" // TODO: to be removed (replaced by TrackedKey enum and mouse states in app.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.
const int KS_PAGEUP = (1<<4); const int KS_PAGEUP = (1<<4);
const int KS_PAGEDOWN = (1<<5); const int KS_PAGEDOWN = (1<<5);
const int KS_SHIFT = (1<<6); 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_NUMPLUS = (1<<14);
const int KS_NUMMINUS = (1<<15); const int KS_NUMMINUS = (1<<15);
// TODO: rewrite/refactor or remove
// Procedures. extern char GetNoAccent(char letter);
extern char GetToUpper(char letter);
extern EventType GetUniqueEventType(); extern char GetToLower(char letter);
extern char RetNoAccent(char letter);
extern char RetToUpper(char letter);
extern char RetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer); extern void TimeToAscii(time_t time, char *buffer);
extern bool CopyFileToTemp(char* filename); extern bool CopyFileToTemp(char* filename);
extern bool CopyFileListToTemp(char* filename, int* list, int total); extern bool CopyFileListToTemp(char* filename, int* list, int total);
extern void AddExt(char* filename, char* ext); extern void AddExt(char* filename, const char* ext);
extern void UserDir(bool bUser, char* dir); extern void UserDir(bool bUser, const char* dir);
extern void UserDir(char* buffer, char* dir, char* def); extern void UserDir(char* buffer, const char* dir, const char* def);
extern char RetLanguageLetter();

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #pragma once

View File

@ -14,7 +14,10 @@
// * You should have received a copy of the GNU General Public License // * You should have received a copy of the GNU General Public License
// * along with this program. If not, see http://www.gnu.org/licenses/. // * 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 #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("../../../") include_directories("../../../")
add_executable(image_test ../image.cpp image_test.cpp) 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_executable(profile_test ../profile.cpp profile_test.cpp)
add_test(profile_test ./profile_test) 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()); printf("Error loading '%s': %s\n", err.c_str());
return 1; 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])) if (! image.SavePNG(argv[2]))
{ {

View File

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

View File

@ -28,67 +28,6 @@
#include "object/object.h" #include "object/object.h"
#include "physics/physics.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) //! Changes the level of transparency of an object and objects transported (battery & cargo)
void SetTransparency(CObject* obj, float value) 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; m_cameraObj = object;
} }
CObject* Gfx::CCamera::GetObject() CObject* Gfx::CCamera::GetControllingObject()
{ {
return m_cameraObj; return m_cameraObj;
} }
@ -1063,11 +1002,9 @@ bool Gfx::CCamera::EventProcess(const Event &event)
EventMouseMove(event); EventMouseMove(event);
break; break;
// TODO: mouse wheel event case EVENT_MOUSE_WHEEL:
/*case EVENT_KEY_DOWN: EventMouseWheel(event.mouseWheel.dir);
if ( event.param == VK_WHEELUP ) EventMouseWheel(+1); break;
if ( event.param == VK_WHEELDOWN ) EventMouseWheel(-1);
break;*/
default: default:
break; break;
@ -1081,17 +1018,17 @@ bool Gfx::CCamera::EventMouseMove(const Event &event)
return true; return true;
} }
void Gfx::CCamera::EventMouseWheel(int dir) void Gfx::CCamera::EventMouseWheel(WheelDirection dir)
{ {
if (m_type == Gfx::CAM_TYPE_BACK) if (m_type == Gfx::CAM_TYPE_BACK)
{ {
if (dir > 0) if (dir == WHEEL_UP)
{ {
m_backDist -= 8.0f; m_backDist -= 8.0f;
if (m_backDist < m_backMin) if (m_backDist < m_backMin)
m_backDist = m_backMin; m_backDist = m_backMin;
} }
if (dir < 0) else if (dir == WHEEL_DOWN)
{ {
m_backDist += 8.0f; m_backDist += 8.0f;
if (m_backDist > 200.0f) if (m_backDist > 200.0f)
@ -1102,13 +1039,13 @@ void Gfx::CCamera::EventMouseWheel(int dir)
if ( m_type == Gfx::CAM_TYPE_FIX || if ( m_type == Gfx::CAM_TYPE_FIX ||
m_type == Gfx::CAM_TYPE_PLANE ) m_type == Gfx::CAM_TYPE_PLANE )
{ {
if (dir > 0) if (dir == WHEEL_UP)
{ {
m_fixDist -= 8.0f; m_fixDist -= 8.0f;
if (m_fixDist < 10.0f) if (m_fixDist < 10.0f)
m_fixDist = 10.0f; m_fixDist = 10.0f;
} }
if (dir < 0) else if (dir == WHEEL_DOWN)
{ {
m_fixDist += 8.0f; m_fixDist += 8.0f;
if (m_fixDist > 200.0f) if (m_fixDist > 200.0f)
@ -1118,13 +1055,13 @@ void Gfx::CCamera::EventMouseWheel(int dir)
if ( m_type == Gfx::CAM_TYPE_VISIT ) if ( m_type == Gfx::CAM_TYPE_VISIT )
{ {
if (dir > 0) if (dir == WHEEL_UP)
{ {
m_visitDist -= 8.0f; m_visitDist -= 8.0f;
if (m_visitDist < 20.0f) if (m_visitDist < 20.0f)
m_visitDist = 20.0f; m_visitDist = 20.0f;
} }
if (dir < 0) else if (dir == WHEEL_DOWN)
{ {
m_visitDist += 8.0f; m_visitDist += 8.0f;
if (m_visitDist > 200.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); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDirV * event.rTime * factor * m_speed);
// Up/Down // 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 // Left/Right
if ( event.keyState & KS_CONTROL ) if ( event.keyState & KS_CONTROL )
{ {
if ( event.axeX < 0.0f ) if ( event.motionInput.x < 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.axeX * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH + Math::PI / 2.0f, m_directionV, -event.motionInput.x * event.rTime * factor * m_speed);
if ( event.axeX > 0.0f ) if ( event.motionInput.x > 0.0f )
m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.axeX * event.rTime * factor * m_speed); m_eyePt = Math::LookatPoint(m_eyePt, m_directionH - Math::PI / 2.0f, m_directionV, event.motionInput.x * event.rTime * factor * m_speed);
} }
else else
{ {
m_directionH -= event.axeX * event.rTime * 0.7f * m_speed; m_directionH -= event.motionInput.x * event.rTime * 0.7f * m_speed;
} }
// PageUp/PageDown // PageUp/PageDown
@ -1719,3 +1656,4 @@ Math::Vector Gfx::CCamera::ExcludeObject(Math::Vector eye, Math::Vector lookat,
return eye;*/ return eye;*/
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -200,7 +200,7 @@ void Gfx::CParticle::DrawParticle(int sheet)
// TODO! // 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"); GetLogger()->Trace("CParticle::WriteWheelTrace() stub!\n");
// TODO! // TODO!

View File

@ -306,7 +306,7 @@ public:
void FrameParticle(float rTime); void FrameParticle(float rTime);
void DrawParticle(int sheet); 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: protected:
void DeleteRank(int rank); void DeleteRank(int rank);

View File

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

View File

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

View File

@ -129,9 +129,11 @@ bool Gfx::CGLDevice::Create()
glViewport(0, 0, m_config.size.x, m_config.size.y); 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_lights = std::vector<Gfx::Light>(numLights, Gfx::Light());
m_lightsEnabled = std::vector<bool> (GL_MAX_LIGHTS, false); m_lightsEnabled = std::vector<bool> (numLights, false);
int maxTextures = 0; int maxTextures = 0;
glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTextures);
@ -182,7 +184,6 @@ void Gfx::CGLDevice::BeginScene()
void Gfx::CGLDevice::EndScene() void Gfx::CGLDevice::EndScene()
{ {
glFlush();
} }
void Gfx::CGLDevice::Clear() void Gfx::CGLDevice::Clear()
@ -434,7 +435,10 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr
else else
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
bool convert = false;
GLenum sourceFormat = 0; GLenum sourceFormat = 0;
if (params.format == Gfx::TEX_IMG_RGB) if (params.format == Gfx::TEX_IMG_RGB)
{ {
sourceFormat = GL_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->Amask != 0)
{ {
if ((data->surface->format->Rmask == 0xFF000000) && if ((data->surface->format->Amask == 0xFF000000) &&
(data->surface->format->Gmask == 0x00FF0000) && (data->surface->format->Rmask == 0x00FF0000) &&
(data->surface->format->Bmask == 0x0000FF00) && (data->surface->format->Gmask == 0x0000FF00) &&
(data->surface->format->Amask == 0x000000FF)) (data->surface->format->Bmask == 0x000000FF))
{ {
sourceFormat = GL_BGRA; sourceFormat = GL_BGRA;
result.alpha = true; result.alpha = true;
} }
else if ((data->surface->format->Bmask == 0xFF000000) && else if ((data->surface->format->Amask == 0xFF000000) &&
(data->surface->format->Gmask == 0x00FF0000) && (data->surface->format->Bmask == 0x00FF0000) &&
(data->surface->format->Rmask == 0x0000FF00) && (data->surface->format->Gmask == 0x0000FF00) &&
(data->surface->format->Amask == 0x000000FF)) (data->surface->format->Rmask == 0x000000FF))
{ {
sourceFormat = GL_RGBA; sourceFormat = GL_RGBA;
result.alpha = true; result.alpha = true;
} }
else else
{ {
GetLogger()->Error("Auto texture format failed\n"); sourceFormat = GL_RGBA;
return Gfx::Texture(); // other format? convert = true;
} }
} }
else else
@ -499,16 +503,43 @@ Gfx::Texture Gfx::CGLDevice::CreateTexture(ImageData *data, const Gfx::TextureCr
} }
else else
{ {
GetLogger()->Error("Auto texture format failed\n"); sourceFormat = GL_RGBA;
return Gfx::Texture(); // other format? convert = true;
} }
} }
} }
else else
assert(false); assert(false);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, data->surface->w, data->surface->h, SDL_Surface* actualSurface = data->surface;
0, sourceFormat, GL_UNSIGNED_BYTE, data->surface->pixels); 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 // Restore the previous state of 1st stage

View File

@ -27,5 +27,3 @@
#include "vector.h" #include "vector.h"
#include "matrix.h" #include "matrix.h"
#include "geometry.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); const float LOG_2 = log(2.0f);
}; // namespace Math }; // 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 //! Rotates a point around a center
/** \a center center of rotation /**
\a angle angle is in radians (positive is counterclockwise (CCW) ) * \param center center of rotation
\a p the point */ * \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) inline Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
{ {
Math::Point a; 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) //! 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) inline Math::Point RotatePoint(float angle, const Math::Point &p)
{ {
float x = p.x*cosf(angle) - p.y*sinf(angle); 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); return Math::Point(x, y);
} }
//! Rotates a vector (dist, 0). //! Rotates a vector (dist, 0)
/** \a angle angle is in radians (positive is counterclockwise (CCW) ) /**
\a dist distance to origin */ * \param angle angle [radians] (positive is CCW)
* \param dist distance to origin
*/
inline Math::Point RotatePoint(float angle, float dist) inline Math::Point RotatePoint(float angle, float dist)
{ {
float x = dist*cosf(angle); float x = dist*cosf(angle);
@ -117,7 +123,12 @@ inline Math::Point RotatePoint(float angle, float dist)
return Math::Point(x, y); 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) inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
{ {
float ax, ay; float ax, ay;
@ -132,11 +143,14 @@ inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
py = cy+ay; py = cy+ay;
} }
//! Rotates a point around a center in space. //! 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 angleH is rotation along Y axis (heading) while \a angleV is rotation along X axis (TODO: ?).
\a p the point *
\returns the rotated point */ * \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) inline void RotatePoint(const Math::Vector &center, float angleH, float angleV, Math::Vector &p)
{ {
p.x -= center.x; p.x -= center.x;
@ -151,11 +165,14 @@ inline void RotatePoint(const Math::Vector &center, float angleH, float angleV,
p = center + b; p = center + b;
} }
//! Rotates a point around a center in space. //! Rotates a point around a center in space
/** \a center center of rotation /**
\a angleH,angleV rotation angles in radians (positive is counterclockwise (CCW) ) ) * The rotation is performed first along Y axis (\a angleH) and then along X axis (\a angleV).
\a p the point *
\returns the rotated point */ * \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) inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
{ {
p.x -= center.x; p.x -= center.x;
@ -189,10 +206,12 @@ inline float RotateAngle(float x, float y)
return -atan + 0.5f*PI; return -atan + 0.5f*PI;
} }
//! Calculates the angle between two points and one center //! Calculates the angle between two points and a center
/** \a center the center point /**
\a p1,p2 the two points * \param center the center point
\returns The angle in radians (positive is counterclockwise (CCW) ) */ * \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) inline float RotateAngle(const Math::Point &center, const Math::Point &p1, const Math::Point &p2)
{ {
if (PointsEqual(p1, center)) 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 //! Loads view matrix from the given vectors
/** \a from origin /**
\a at view direction * \param from origin
\a worldUp up vector */ * \param at view direction
* \param worldUp up vector
*/
inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
const Math::Vector &at, const Math::Vector &worldUp) 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 //! Loads a perspective projection matrix
/** \a fov field of view in radians /**
\a aspect aspect ratio (width / height) * \param fov field of view in radians
\a nearPlane distance to near cut plane * \param aspect aspect ratio (width / height)
\a farPlane distance to far cut plane */ * \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, inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f, float aspect = 1.0f,
float nearPlane = 1.0f, float farPlane = 1000.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 //! 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 * \param left,right coordinates for left and right vertical clipping planes
\a zNear,zFar distance to nearer and farther depth 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, inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top,
float zNear = -1.0f, float zFar = 1.0f) 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 //! 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) inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
{ {
mat.LoadIdentity(); mat.LoadIdentity();
@ -330,7 +358,10 @@ inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
} }
//! Loads a scaling matrix fom given vector //! 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) inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
{ {
mat.LoadIdentity(); mat.LoadIdentity();
@ -340,7 +371,10 @@ inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
} }
//! Loads a rotation matrix along the X axis //! 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) inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
{ {
mat.LoadIdentity(); mat.LoadIdentity();
@ -351,7 +385,10 @@ inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
} }
//! Loads a rotation matrix along the Y axis //! 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) inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
{ {
mat.LoadIdentity(); mat.LoadIdentity();
@ -362,7 +399,10 @@ inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
} }
//! Loads a rotation matrix along the Z axis //! 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) inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
{ {
mat.LoadIdentity(); mat.LoadIdentity();
@ -373,8 +413,11 @@ inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
} }
//! Loads a rotation matrix along the given axis //! 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) inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
{ {
float cos = cosf(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 //! 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; Math::Matrix temp;
LoadRotationXMatrix(temp, angle.x); LoadRotationXMatrix(temp, angles.x);
LoadRotationZMatrix(mat, angle.z); LoadRotationZMatrix(mat, angles.z);
mat = Math::MultiplyMatrices(temp, mat); mat = Math::MultiplyMatrices(temp, mat);
LoadRotationYMatrix(temp, angle.y); LoadRotationYMatrix(temp, angles.y);
mat = Math::MultiplyMatrices(temp, mat); mat = Math::MultiplyMatrices(temp, mat);
} }
//! Calculates the matrix to make three rotations in the order Z, X and Y //! 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; Math::Matrix temp;
LoadRotationZMatrix(temp, angle.z); LoadRotationZMatrix(temp, angles.z);
LoadRotationXMatrix(mat, angle.x); LoadRotationXMatrix(mat, angles.x);
mat = Math::MultiplyMatrices(temp, mat); mat = Math::MultiplyMatrices(temp, mat);
LoadRotationYMatrix(temp, angle.y); LoadRotationYMatrix(temp, angles.y);
mat = Math::MultiplyMatrices(temp, mat); 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 //! 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) inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3)
{ {
Math::Vector u = p3 - p1; 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 //! 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) inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
{ {
return p1 + (p2 - p1) * dist; return p1 + (p2 - p1) * dist;
} }
//! Returns the distance between given point and a plane //! 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, inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b,
const Math::Vector &c, const Math::Vector &p) 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 //! 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]) inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&plane2)[3])
{ {
Math::Vector n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]); 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; 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, 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) 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) //! 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) 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); 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; 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) inline Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p)
{ {
return MatrixVectorMultiply(m, p); return MatrixVectorMultiply(m, p);
} }
//! Calculates the projection of the point \a p on a straight line \a a to \a b. //! 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 */ * \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) inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p)
{ {
float k = DotProduct(b - a, p - a); float k = DotProduct(b - a, p - a);

View File

@ -33,13 +33,14 @@
namespace Math namespace Math
{ {
/** \struct Matrix math/matrix.h /**
\brief 4x4 matrix * \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.). * 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: *
* The internal representation is a 16-value table in column-major order, thus:
\verbatim \verbatim
m[0 ] m[4 ] m[8 ] m[12] 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] m[3 ] m[7 ] m[11] m[15]
\endverbatim \endverbatim
This representation is native to OpenGL; DirectX requires transposing the matrix. * This representation is native to OpenGL; DirectX requires transposing the matrix.
*
The order of multiplication of matrix and vector is also OpenGL-native * The order of multiplication of matrix and vector is also OpenGL-native
(see the function MatrixVectorMultiply). * (see the function MatrixVectorMultiply).
*
All methods are made inline to maximize optimization. * All methods are made inline to maximize optimization.
*
Unit tests for the structure and related functions are in module: math/test/matrix_test.cpp. * Unit tests for the structure and related functions are in module: math/test/matrix_test.cpp.
*
**/ */
struct Matrix struct Matrix
{ {
//! Matrix values in column-major order //! Matrix values in column-major order
@ -78,8 +79,10 @@ struct Matrix
} }
//! Creates the matrix from 2D array //! 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]) inline explicit Matrix(const float (&m)[4][4])
{ {
for (int c = 0; c < 4; ++c) 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) inline void Set(int row, int col, float value)
{ {
m[(col-1)*4+(row-1)] = 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) inline float Get(int row, int col)
{ {
return m[(col-1)*4+(row-1)]; return m[(col-1)*4+(row-1)];
@ -148,9 +163,11 @@ struct Matrix
} }
//! Calculates the cofactor of the matrix //! Calculates the cofactor of the matrix
/** \a r row (0 to 3) /**
\a c column (0 to 3) * \param r row (0 to 3)
\returns the cofactor */ * \param c column (0 to 3)
* \returns the cofactor
*/
inline float Cofactor(int r, int c) const inline float Cofactor(int r, int c) const
{ {
assert(r >= 0 && r <= 3); assert(r >= 0 && r <= 3);
@ -330,8 +347,10 @@ struct Matrix
} }
//! Calculates the inverse 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 inline Matrix Inverse() const
{ {
float d = Det(); float d = Det();
@ -352,8 +371,10 @@ struct Matrix
} }
//! Calculates the multiplication of this matrix * given 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 inline Matrix Multiply(const Matrix &right) const
{ {
float result[16] = { 0.0f }; float result[16] = { 0.0f };

View File

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

View File

@ -1,33 +1,23 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE debug) 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) include_directories(
add_executable(vector_test vector_test.cpp) .
add_executable(geometry_test geometry_test.cpp ../old/math3d.cpp ../old/d3dmath.cpp ../../graphics/d3d/d3dutil.cpp) ../../..
${GTEST_DIR}/include
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
) )
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 "../func.h"
#include "../geometry.h" #include "../geometry.h"
#include "../conv.h"
#include "../../old/math3d.h"
#include "../../old/d3dutil.h"
#include <d3d.h> #include "gtest/gtest.h"
#include <cstdio>
using namespace std;
const float TEST_TOLERANCE = 1e-5; const float TEST_TOLERANCE = 1e-5;
// Test for rewritten function RotateAngle() // Test for rewritten function RotateAngle()
int TestRotateAngle() TEST(GeometryTest, RotateAngleTest)
{ {
if (! Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 0.0f), 0.0f, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 0.0f), 0.0f, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, 1.0f), 0.25f * Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, 2.0f), 0.5f * Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-0.5f, 0.5f), 0.75f * Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, 0.0f), Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(-1.0f, -1.0f), 1.25f * Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(0.0f, -2.0f), 1.5f * Math::PI, TEST_TOLERANCE));
return __LINE__;
if (! Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE)) EXPECT_TRUE(Math::IsEqual(Math::RotateAngle(1.0f, -1.0f), 1.75f * Math::PI, TEST_TOLERANCE));
return __LINE__;
return 0;
} }
// Tests for other altered, complex or uncertain functions // Tests for other altered, complex or uncertain functions
/*
TODO: write meaningful tests with proper test values
int TestAngle() int TestAngle()
{ {
const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805); const Math::Vector u(-0.0786076246943884, 0.2231249091714256, -1.1601361718477805);
@ -360,42 +348,12 @@ int TestTransform()
return 0; return 0;
} }
int main() */
{
// 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);
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"); int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return 0; return RUN_ALL_TESTS();
} }

View File

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

View File

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

View File

@ -32,16 +32,17 @@
namespace Math namespace Math
{ {
/** \struct Vector math/vector.h /**
\brief 3D (3x1) vector * \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. * 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. *
* All methods are made inline to maximize optimization.
Unit tests for the structure and related functions are in module: math/test/vector_test.cpp. *
* Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
*
*/ */
struct Vector struct Vector
{ {
@ -103,8 +104,10 @@ struct Vector
} }
//! Calculates the cross product with another 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 inline Vector CrossMultiply(const Vector &right) const
{ {
float px = y * right.z - z * right.y; float px = y * right.z - z * right.y;
@ -114,8 +117,10 @@ struct Vector
} }
//! Calculates the dot product with another 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 inline float DotMultiply(const Vector &right) const
{ {
return x * right.x + y * right.y + z * right.z; return x * right.x + y * right.y + z * right.z;
@ -218,7 +223,7 @@ struct Vector
return s.str(); return s.str();
} }
}; // struct Point }; // struct Vector
//! Checks if two vectors are equal within given \a tolerance //! Checks if two vectors are equal within given \a tolerance
inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance = 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) ); (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 }; // namespace Math

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoderrick.h" #include "object/auto/autoderrick.h"
#include "common/iman.h" #include "common/iman.h"
#include "old/terrain.h" #include "graphics/engine/terrain.h"
#include "math/geometry.h" #include "math/geometry.h"
#include "script/cmdtoken.h" #include "script/cmdtoken.h"
#include "ui/interface.h" #include "ui/interface.h"
#include "ui/window.h" #include "ui/window.h"
#include "ui/displaytext.h" #include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float DERRICK_DELAY = 10.0f; // duration of the extraction const float DERRICK_DELAY = 10.0f; // duration of the extraction
@ -62,7 +62,7 @@ void CAutoDerrick::DeleteObject(bool bAll)
if ( !bAll ) if ( !bAll )
{ {
fret = SearchFret(); fret = SearchFret();
if ( fret != 0 && fret->RetLock() ) if ( fret != 0 && fret->GetLock() )
{ {
fret->DeleteObject(); fret->DeleteObject();
delete fret; delete fret;
@ -86,25 +86,25 @@ void CAutoDerrick::Init()
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos; Math::Vector pos;
TerrainRes res; Gfx::TerrainRes res;
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
res = m_terrain->RetResource(pos); res = m_terrain->GetResource(pos);
if ( res == TR_STONE || if ( res == Gfx::TR_STONE ||
res == TR_URANIUM || res == Gfx::TR_URANIUM ||
res == TR_KEYa || res == Gfx::TR_KEY_A ||
res == TR_KEYb || res == Gfx::TR_KEY_B ||
res == TR_KEYc || res == Gfx::TR_KEY_C ||
res == TR_KEYd ) res == Gfx::TR_KEY_D )
{ {
m_type = OBJECT_FRET; m_type = OBJECT_FRET;
if ( res == TR_STONE ) m_type = OBJECT_STONE; if ( res == Gfx::TR_STONE ) m_type = OBJECT_STONE;
if ( res == TR_URANIUM ) m_type = OBJECT_URANIUM; if ( res == Gfx::TR_URANIUM ) m_type = OBJECT_URANIUM;
if ( res == TR_KEYa ) m_type = OBJECT_KEYa; if ( res == Gfx::TR_KEY_A ) m_type = OBJECT_KEYa;
if ( res == TR_KEYb ) m_type = OBJECT_KEYb; if ( res == Gfx::TR_KEY_B ) m_type = OBJECT_KEYb;
if ( res == TR_KEYc ) m_type = OBJECT_KEYc; if ( res == Gfx::TR_KEY_C ) m_type = OBJECT_KEYc;
if ( res == TR_KEYd ) m_type = OBJECT_KEYd; if ( res == Gfx::TR_KEY_D ) m_type = OBJECT_KEYd;
m_phase = ADP_EXCAVATE; m_phase = ADP_EXCAVATE;
m_progress = 0.0f; m_progress = 0.0f;
@ -119,13 +119,13 @@ void CAutoDerrick::Init()
m_time = 0.0f; m_time = 0.0f;
m_timeVirus = 0.0f; m_timeVirus = 0.0f;
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
m_lastTrack = 0.0f; m_lastTrack = 0.0f;
pos = Math::Vector(7.0f, 0.0f, 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); pos = Math::Transform(*mat, pos);
m_terrain->MoveOnFloor(pos); m_terrain->AdjustToFloor(pos);
m_fretPos = pos; m_fretPos = pos;
} }
@ -141,14 +141,14 @@ bool CAutoDerrick::EventProcess(const Event &event)
CAuto::EventProcess(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 == ADP_WAIT ) return true; if ( m_phase == ADP_WAIT ) return true;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
m_timeVirus -= 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 ) if ( m_timeVirus <= 0.0f )
{ {
@ -176,7 +176,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
{ {
factor = 1.0f; 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.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.3f, 6.0f*factor, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.5f, 1.0f, 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? 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.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = Math::Rand()*5.0f; speed.y = Math::Rand()*5.0f;
dim.x = Math::Rand()*3.0f+2.0f; dim.x = Math::Rand()*3.0f+2.0f;
dim.y = dim.x; 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? 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; m_lastTrack = m_time;
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*12.0f; speed.x = (Math::Rand()-0.5f)*12.0f;
speed.z = (Math::Rand()-0.5f)*12.0f; speed.z = (Math::Rand()-0.5f)*12.0f;
speed.y = Math::Rand()*10.0f+10.0f; speed.y = Math::Rand()*10.0f+10.0f;
@ -210,7 +210,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
dim.y = dim.x; dim.y = dim.x;
pos.y += dim.y; pos.y += dim.y;
duration = Math::Rand()*2.0f+2.0f; 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, Math::Rand()*10.0f+15.0f,
duration*0.2f, 1.0f); duration*0.2f, 1.0f);
} }
@ -222,7 +222,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
pos.y = -m_progress*16.0f; pos.y = -m_progress*16.0f;
m_object->SetPosition(1, pos); // down the drill m_object->SetPosition(1, pos); // down the drill
angle = m_object->RetAngleY(1); angle = m_object->GetAngleY(1);
angle += event.rTime*8.0f; angle += event.rTime*8.0f;
m_object->SetAngleY(1, angle); // rotates the drill 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_phase == ADP_ASCEND )
{ {
if ( m_progress <= 7.0f/16.0f && 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.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = Math::Rand()*5.0f; speed.y = Math::Rand()*5.0f;
dim.x = Math::Rand()*3.0f+2.0f; dim.x = Math::Rand()*3.0f+2.0f;
dim.y = dim.x; 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 && 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; m_lastTrack = m_time;
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
speed.x = (Math::Rand()-0.5f)*12.0f; speed.x = (Math::Rand()-0.5f)*12.0f;
speed.z = (Math::Rand()-0.5f)*12.0f; speed.z = (Math::Rand()-0.5f)*12.0f;
speed.y = Math::Rand()*10.0f+10.0f; speed.y = Math::Rand()*10.0f+10.0f;
@ -263,7 +263,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
dim.y = dim.x; dim.y = dim.x;
pos.y += dim.y; pos.y += dim.y;
duration = Math::Rand()*2.0f+2.0f; 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, Math::Rand()*10.0f+15.0f,
duration*0.2f, 1.0f); duration*0.2f, 1.0f);
} }
@ -275,7 +275,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
pos.y = -(1.0f-m_progress)*16.0f; pos.y = -(1.0f-m_progress)*16.0f;
m_object->SetPosition(1, pos); // back the drill m_object->SetPosition(1, pos); // back the drill
angle = m_object->RetAngleY(1); angle = m_object->GetAngleY(1);
angle -= event.rTime*2.0f; angle -= event.rTime*2.0f;
m_object->SetAngleY(1, angle); // rotates the drill m_object->SetAngleY(1, angle); // rotates the drill
} }
@ -308,7 +308,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
{ {
if ( SearchFree(m_fretPos) ) if ( SearchFree(m_fretPos) )
{ {
angle = m_object->RetAngleY(0); angle = m_object->GetAngleY(0);
CreateFret(m_fretPos, angle, m_type, 16.0f); CreateFret(m_fretPos, angle, m_type, 16.0f);
} }
else else
@ -324,31 +324,31 @@ bool CAutoDerrick::EventProcess(const Event &event)
if ( fret != 0 && if ( fret != 0 &&
m_progress <= 0.5f && 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 ) if ( m_progress < 0.3f )
{ {
pos = fret->RetPosition(0); pos = fret->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*5.0f; pos.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += (Math::Rand()-0.5f)*5.0f; pos.y += (Math::Rand()-0.5f)*5.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 3.0f; dim.x = 3.0f;
dim.y = dim.x; 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 else
{ {
pos = fret->RetPosition(0); pos = fret->GetPosition(0);
pos.x += (Math::Rand()-0.5f)*5.0f; pos.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += Math::Rand()*2.5f; pos.y += Math::Rand()*2.5f;
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 1.0f; dim.x = 1.0f;
dim.y = dim.x; 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 ) if ( fret != 0 )
{ {
pos = fret->RetPosition(0); pos = fret->GetPosition(0);
pos.y -= event.rTime*20.0f; // grave pos.y -= event.rTime*20.0f; // grave
if ( !m_bSoundFall && pos.y < m_fretPos.y ) if ( !m_bSoundFall && pos.y < m_fretPos.y )
{ {
@ -396,7 +396,7 @@ bool CAutoDerrick::EventProcess(const Event &event)
bool CAutoDerrick::CreateInterface(bool bSelect) bool CAutoDerrick::CreateInterface(bool bSelect)
{ {
CWindow* pw; Ui::CWindow* pw;
Math::Point pos, ddim; Math::Point pos, ddim;
float ox, oy, sx, sy; float ox, oy, sx, sy;
@ -404,7 +404,7 @@ bool CAutoDerrick::CreateInterface(bool bSelect)
if ( !bSelect ) return true; 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; if ( pw == 0 ) return false;
ox = 3.0f/640.0f; ox = 3.0f/640.0f;
@ -455,11 +455,11 @@ bool CAutoDerrick::Read(char *line)
CAuto::Read(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_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
return true; return true;
} }
@ -476,13 +476,13 @@ CObject* CAutoDerrick::SearchFret()
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
type = pObj->RetType(); type = pObj->GetType();
if ( type == OBJECT_DERRICK ) continue; if ( type == OBJECT_DERRICK ) continue;
oPos = pObj->RetPosition(0); oPos = pObj->GetPosition(0);
if ( oPos.x == m_fretPos.x && if ( oPos.x == m_fretPos.x &&
oPos.z == m_fretPos.z ) return pObj; oPos.z == m_fretPos.z ) return pObj;
@ -503,10 +503,10 @@ bool CAutoDerrick::SearchFree(Math::Vector pos)
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
type = pObj->RetType(); type = pObj->GetType();
if ( type == OBJECT_DERRICK ) continue; if ( type == OBJECT_DERRICK ) continue;
j = 0; j = 0;
@ -537,12 +537,12 @@ void CAutoDerrick::CreateFret(Math::Vector pos, float angle, ObjectType type,
} }
fret->SetLock(true); // object not yet usable fret->SetLock(true); // object not yet usable
if ( m_object->RetResetCap() == RESET_MOVE ) if ( m_object->GetResetCap() == RESET_MOVE )
{ {
fret->SetResetCap(RESET_DELETE); fret->SetResetCap(RESET_DELETE);
} }
pos = fret->RetPosition(0); pos = fret->GetPosition(0);
pos.y += height; pos.y += height;
fret->SetPosition(0, pos); fret->SetPosition(0, pos);
} }
@ -562,10 +562,10 @@ bool CAutoDerrick::ExistKey()
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
type = pObj->RetType(); type = pObj->GetType();
if ( type == m_type ) return true; 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; return ERR_BAT_VIRUS;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autoflag.h" #include "object/auto/autoflag.h"
#include "math/geometry.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_param = 0;
m_progress = 0.0f; m_progress = 0.0f;
wind = m_terrain->RetWind(); wind = m_terrain->GetWind();
angle = Math::RotateAngle(wind.x, -wind.z); angle = Math::RotateAngle(wind.x, -wind.z);
m_object->SetAngleY(0, angle); // directs the flag in the wind m_object->SetAngleY(0, angle); // directs the flag in the wind
@ -98,7 +99,7 @@ bool CAutoFlag::EventProcess(const Event &event)
CAuto::EventProcess(event); CAuto::EventProcess(event);
#if ADJUST_ANGLE #if ADJUST_ANGLE
if ( event.event == EVENT_KEYDOWN ) if ( event.type == EVENT_KEYDOWN )
{ {
if ( event.param == 'E' ) g_flag1 += 0.1f; if ( event.param == 'E' ) g_flag1 += 0.1f;
if ( event.param == 'D' ) g_flag1 -= 0.1f; if ( event.param == 'D' ) g_flag1 -= 0.1f;
@ -109,8 +110,8 @@ bool CAutoFlag::EventProcess(const Event &event)
} }
#endif #endif
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_param == 1 ) // shakes? 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; return ERR_OK;
} }

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * it under the terms of the GNU General Public License as published by
@ -34,7 +35,7 @@ public:
void Init(); void Init();
void Start(int param); void Start(int param);
bool EventProcess(const Event &event); bool EventProcess(const Event &event);
Error RetError(); Error GetError();
protected: protected:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * it under the terms of the GNU General Public License as published by
@ -42,7 +43,7 @@ protected:
float m_force; float m_force;
float m_progress; float m_progress;
float m_speed; float m_speed;
float m_lastParticule; float m_lastParticle;
Error m_error; Error m_error;
}; };

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autokid.h" #include "object/auto/autokid.h"
#include "old/particule.h" #include "graphics/engine/particle.h"
#include "old/water.h" #include "graphics/engine/water.h"
#include <stdio.h>
// Object's constructor. // Object's constructor.
@ -62,18 +62,18 @@ void CAutoKid::Init()
m_speed = 1.0f/1.0f; m_speed = 1.0f/1.0f;
m_progress = 0.0f; m_progress = 0.0f;
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
if ( m_type == OBJECT_TEEN36 ) // trunk ? 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_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); m_progress = Math::Mod(pos.x/10.0f, 1.0f);
} }
if ( m_type == OBJECT_TEEN37 ) // boat? 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_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); m_progress = Math::Mod(pos.x/10.0f, 1.0f);
} }
@ -82,7 +82,7 @@ void CAutoKid::Init()
{ {
if ( m_soundChannel == -1 ) 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; m_bSilent = false;
} }
} }
@ -100,7 +100,7 @@ bool CAutoKid::EventProcess(const Event &event)
if ( m_soundChannel != -1 ) if ( m_soundChannel != -1 )
{ {
if ( m_engine->RetPause() ) if ( m_engine->GetPause() )
{ {
if ( !m_bSilent ) if ( !m_bSilent )
{ {
@ -118,8 +118,8 @@ bool CAutoKid::EventProcess(const Event &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;
m_progress += event.rTime*m_speed; 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; vib.z = sinf(m_progress*0.5f)*0.05f;
m_object->SetCirVibration(vib); 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 = m_object->GetPosition(0);
pos.y = m_water->RetLevel()+1.0f; pos.y = m_water->GetLevel()+1.0f;
pos.x += (Math::Rand()-0.5f)*50.0f; pos.x += (Math::Rand()-0.5f)*50.0f;
pos.z += (Math::Rand()-0.5f)*50.0f; pos.z += (Math::Rand()-0.5f)*50.0f;
speed.y = 0.0f; speed.y = 0.0f;
@ -148,7 +148,7 @@ bool CAutoKid::EventProcess(const Event &event)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 50.0f; dim.x = 50.0f;
dim.y = dim.x; 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; vib.z = sinf(m_progress*0.5f)*0.15f;
m_object->SetCirVibration(vib); 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 = m_object->GetPosition(0);
pos.y = m_water->RetLevel()+1.0f; pos.y = m_water->GetLevel()+1.0f;
pos.x += (Math::Rand()-0.5f)*20.0f; pos.x += (Math::Rand()-0.5f)*20.0f;
pos.z += (Math::Rand()-0.5f)*20.0f; pos.z += (Math::Rand()-0.5f)*20.0f;
speed.y = 0.0f; speed.y = 0.0f;
@ -177,7 +177,7 @@ bool CAutoKid::EventProcess(const Event &event)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 20.0f; dim.x = 20.0f;
dim.y = dim.x; 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; return ERR_OK;
} }

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autolabo.h" #include "object/auto/autolabo.h"
#include "common/global.h" #include "common/global.h"
@ -28,6 +27,8 @@
#include "ui/window.h" #include "ui/window.h"
#include "ui/displaytext.h" #include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float LABO_DELAY = 20.0f; // duration of the analysis const float LABO_DELAY = 20.0f; // duration of the analysis
@ -69,14 +70,14 @@ void CAutoLabo::DeleteObject(bool bAll)
{ {
if ( m_partiRank[i] != -1 ) if ( m_partiRank[i] != -1 )
{ {
m_particule->DeleteParticule(m_partiRank[i]); m_particle->DeleteParticle(m_partiRank[i]);
m_partiRank[i] = -1; m_partiRank[i] = -1;
} }
} }
if ( m_partiSphere != -1 ) if ( m_partiSphere != -1 )
{ {
m_particule->DeleteParticule(m_partiSphere); m_particle->DeleteParticle(m_partiSphere);
m_partiSphere = -1; m_partiSphere = -1;
} }
@ -97,7 +98,7 @@ void CAutoLabo::Init()
{ {
m_time = 0.0f; m_time = 0.0f;
m_timeVirus = 0.0f; m_timeVirus = 0.0f;
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
m_phase = ALAP_WAIT; // waiting ... m_phase = ALAP_WAIT; // waiting ...
m_progress = 0.0f; m_progress = 0.0f;
@ -119,23 +120,23 @@ bool CAutoLabo::EventProcess(const Event &event)
CAuto::EventProcess(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? if ( m_object->GetSelect() && // center selected?
(event.event == EVENT_OBJECT_RiPAW || (event.type == EVENT_OBJECT_RiPAW ||
event.event == EVENT_OBJECT_RiGUN) ) event.type == EVENT_OBJECT_RiGUN) )
{ {
if ( m_phase != ALAP_WAIT ) if ( m_phase != ALAP_WAIT )
{ {
return false; return false;
} }
m_research = event.event; m_research = event.type;
if ( TestResearch(m_research) ) if ( TestResearch(m_research) )
{ {
@ -143,13 +144,13 @@ bool CAutoLabo::EventProcess(const Event &event)
return false; return false;
} }
power = m_object->RetPower(); power = m_object->GetPower();
if ( power == 0 ) if ( power == 0 )
{ {
m_displayText->DisplayError(ERR_LABO_NULL, m_object); m_displayText->DisplayError(ERR_LABO_NULL, m_object);
return false; return false;
} }
if ( power->RetType() != OBJECT_BULLET ) if ( power->GetType() != OBJECT_BULLET )
{ {
m_displayText->DisplayError(ERR_LABO_BAD, m_object); m_displayText->DisplayError(ERR_LABO_BAD, m_object);
return false; return false;
@ -168,12 +169,12 @@ bool CAutoLabo::EventProcess(const Event &event)
return true; return true;
} }
if ( event.event != EVENT_FRAME ) return true; if ( event.type != EVENT_FRAME ) return true;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
m_timeVirus -= 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 ) if ( m_timeVirus <= 0.0f )
{ {
@ -247,31 +248,32 @@ bool CAutoLabo::EventProcess(const Event &event)
{ {
m_object->SetAngleZ(1, 0.0f); m_object->SetAngleZ(1, 0.0f);
goal = m_object->RetPosition(0); goal = m_object->GetPosition(0);
goal.y += 3.0f; goal.y += 3.0f;
pos = goal; pos = goal;
pos.x -= 4.0f; pos.x -= 4.0f;
pos.y += 4.0f; pos.y += 4.0f;
for ( i=0 ; i<3 ; i++ ) for ( i=0 ; i<3 ; i++ )
{ {
m_partiRank[i] = m_particule->CreateRay(pos, goal, m_partiRank[i] = m_particle->CreateRay(pos, goal,
PARTIRAY2, Gfx::PARTIRAY2,
Math::Point(2.9f, 2.9f), Math::Point(2.9f, 2.9f),
LABO_DELAY); 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, 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, 2.00f, 8.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.60f, 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); 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; pos.y += 4.0f;
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = Math::Vector(0.0f, 0.0f, 0.0f);
dim.x = 4.0f; dim.x = 4.0f;
dim.y = dim.x; 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_phase = ALAP_ANALYSE;
m_progress = 0.0f; m_progress = 0.0f;
@ -283,13 +285,13 @@ bool CAutoLabo::EventProcess(const Event &event)
{ {
if ( m_progress < 1.0f ) if ( m_progress < 1.0f )
{ {
power = m_object->RetPower(); power = m_object->GetPower();
if ( power != 0 ) if ( power != 0 )
{ {
power->SetZoom(0, 1.0f-m_progress); power->SetZoom(0, 1.0f-m_progress);
} }
angle = m_object->RetAngleY(2); angle = m_object->GetAngleY(2);
if ( m_progress < 0.5f ) if ( m_progress < 0.5f )
{ {
angle -= event.rTime*m_progress*20.0f; 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 m_object->SetAngleY(2, angle); // rotates the analyzer
angle += m_object->RetAngleY(0); angle += m_object->GetAngleY(0);
for ( i=0 ; i<3 ; i++ ) for ( i=0 ; i<3 ; i++ )
{ {
rot = Math::RotatePoint(-angle, -4.0f); rot = Math::RotatePoint(-angle, -4.0f);
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
pos.x += rot.x; pos.x += rot.x;
pos.z += rot.y; pos.z += rot.y;
pos.y += 3.0f+4.0f;; 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; 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 && if ( m_progress > 0.25f &&
m_progress < 0.80f ) m_progress < 0.80f )
{ {
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
pos.y += 3.0f; pos.y += 3.0f;
pos.x += (Math::Rand()-0.5f)*2.0f; pos.x += (Math::Rand()-0.5f)*2.0f;
pos.z += (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; speed.z = (Math::Rand()-0.5f)*10.0f;
dim.x = Math::Rand()*0.4f*m_progress+1.0f; dim.x = Math::Rand()*0.4f*m_progress+1.0f;
dim.y = dim.x; 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); 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 SetResearch(m_research); // research done
power = m_object->RetPower(); power = m_object->GetPower();
if ( power != 0 ) if ( power != 0 )
{ {
m_object->SetPower(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; CObject* pObj;
ObjectType type; ObjectType type;
if ( m_object->RetVirusMode() ) if ( m_object->GetVirusMode() )
{ {
return ERR_BAT_VIRUS; return ERR_BAT_VIRUS;
} }
pObj = m_object->RetPower(); pObj = m_object->GetPower();
if ( pObj == 0 ) return ERR_LABO_NULL; if ( pObj == 0 ) return ERR_LABO_NULL;
type = pObj->RetType(); type = pObj->GetType();
if ( type != OBJECT_BULLET ) return ERR_LABO_BAD; if ( type != OBJECT_BULLET ) return ERR_LABO_BAD;
return ERR_OK; return ERR_OK;
@ -446,7 +448,7 @@ Error CAutoLabo::RetError()
bool CAutoLabo::CreateInterface(bool bSelect) bool CAutoLabo::CreateInterface(bool bSelect)
{ {
CWindow* pw; Ui::CWindow* pw;
Math::Point pos, dim, ddim; Math::Point pos, dim, ddim;
float ox, oy, sx, sy; float ox, oy, sx, sy;
@ -454,7 +456,7 @@ bool CAutoLabo::CreateInterface(bool bSelect)
if ( !bSelect ) return true; 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; if ( pw == 0 ) return false;
dim.x = 33.0f/640.0f; dim.x = 33.0f/640.0f;
@ -487,13 +489,13 @@ bool CAutoLabo::CreateInterface(bool bSelect)
void CAutoLabo::UpdateInterface() void CAutoLabo::UpdateInterface()
{ {
CWindow* pw; Ui::CWindow* pw;
if ( !m_object->RetSelect() ) return; if ( !m_object->GetSelect() ) return;
CAuto::UpdateInterface(); CAuto::UpdateInterface();
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW0); pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
if ( pw == 0 ) return; if ( pw == 0 ) return;
DeadInterface(pw, EVENT_OBJECT_RiPAW, g_researchEnable&RESEARCH_iPAW); DeadInterface(pw, EVENT_OBJECT_RiPAW, g_researchEnable&RESEARCH_iPAW);
@ -508,20 +510,20 @@ void CAutoLabo::UpdateInterface()
// Indicates the research conducted for a button. // 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); control = pw->SearchControl(event);
if ( control == 0 ) return; 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. // 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_RiPAW ) return (g_researchDone & RESEARCH_iPAW);
if ( event == EVENT_OBJECT_RiGUN ) return (g_researchDone & RESEARCH_iGUN); if ( event == EVENT_OBJECT_RiGUN ) return (g_researchDone & RESEARCH_iGUN);
@ -531,16 +533,17 @@ bool CAutoLabo::TestResearch(EventMsg event)
// Indicates a search as made. // 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_RiPAW ) g_researchDone |= RESEARCH_iPAW;
if ( event == EVENT_OBJECT_RiGUN ) g_researchDone |= RESEARCH_iGUN; if ( event == EVENT_OBJECT_RiGUN ) g_researchDone |= RESEARCH_iGUN;
m_main->WriteFreeParam(); m_main->WriteFreeParam();
m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE); Event newEvent(EVENT_UPDINTERFACE);
// m_event->MakeEvent(newEvent, EVENT_UPDINTERFACE);
m_event->AddEvent(newEvent); m_event->AddEvent(newEvent);
UpdateInterface(); UpdateInterface();
} }
@ -551,7 +554,7 @@ void CAutoLabo::SoundManip(float time, float amplitude, float frequency)
{ {
int i; 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, 0.1f, SOPER_CONTINUE);
m_sound->AddEnvelope(i, 0.5f*amplitude, 1.0f*frequency, time-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); 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); 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_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.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; return true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autonuclear.h" #include "object/auto/autonuclear.h"
#include "common/iman.h" #include "common/iman.h"
@ -26,6 +25,8 @@
#include "ui/window.h" #include "ui/window.h"
#include "ui/displaytext.h" #include "ui/displaytext.h"
#include <stdio.h>
#include <string.h>
const float NUCLEAR_DELAY = 30.0f; // duration of the generation const float NUCLEAR_DELAY = 30.0f; // duration of the generation
@ -84,9 +85,9 @@ void CAutoNuclear::Init()
m_time = 0.0f; m_time = 0.0f;
m_timeVirus = 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_pos = Math::Transform(*mat, Math::Vector(22.0f, 4.0f, 0.0f));
m_phase = ANUP_WAIT; // waiting ... m_phase = ANUP_WAIT; // waiting ...
@ -110,13 +111,13 @@ bool CAutoNuclear::EventProcess(const Event &event)
CAuto::EventProcess(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;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
m_timeVirus -= 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 ) if ( m_timeVirus <= 0.0f )
{ {
@ -146,7 +147,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
InitProgressTotal(1.5f+NUCLEAR_DELAY+1.5f); InitProgressTotal(1.5f+NUCLEAR_DELAY+1.5f);
UpdateInterface(); 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_phase = ANUP_CLOSE;
m_progress = 0.0f; m_progress = 0.0f;
@ -166,8 +167,8 @@ bool CAutoNuclear::EventProcess(const Event &event)
{ {
m_object->SetAngleZ(1, 0.0f); m_object->SetAngleZ(1, 0.0f);
mat = m_object->RetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
max = (int)(10.0f*m_engine->RetParticuleDensity()); max = static_cast< int >(10.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ ) for ( i=0 ; i<max ; i++ )
{ {
pos.x = 27.0f; pos.x = 27.0f;
@ -179,12 +180,12 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = Math::Rand()*1.0f+1.0f; dim.x = Math::Rand()*1.0f+1.0f;
dim.y = dim.x; 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, 1.0f, 1.0f, NUCLEAR_DELAY-1.0f, SOPER_CONTINUE);
m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 2.0f, SOPER_STOP); 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_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.y += 30.0f;
pos.x += (Math::Rand()-0.5f)*6.0f; pos.x += (Math::Rand()-0.5f)*6.0f;
pos.z += (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; speed.z = 0.0f;
dim.x = Math::Rand()*8.0f+8.0f; dim.x = Math::Rand()*8.0f+8.0f;
dim.y = dim.x; dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTICRASH); m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH);
pos = m_pos; pos = m_pos;
speed.x = (Math::Rand()-0.5f)*20.0f; 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; speed.z = (Math::Rand()-0.5f)*20.0f;
dim.x = 2.0f; dim.x = 2.0f;
dim.y = dim.x; 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 else
@ -234,7 +235,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
CreatePower(); // creates the atomic cell 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++ ) for ( i=0 ; i<max ; i++ )
{ {
pos = m_pos; pos = m_pos;
@ -246,10 +247,10 @@ bool CAutoNuclear::EventProcess(const Event &event)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = Math::Rand()*2.0f+2.0f; dim.x = Math::Rand()*2.0f+2.0f;
dim.y = dim.x; 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_phase = ANUP_OPEN;
m_progress = 0.0f; m_progress = 0.0f;
@ -287,7 +288,7 @@ bool CAutoNuclear::EventProcess(const Event &event)
bool CAutoNuclear::CreateInterface(bool bSelect) bool CAutoNuclear::CreateInterface(bool bSelect)
{ {
CWindow* pw; Ui::CWindow* pw;
Math::Point pos, ddim; Math::Point pos, ddim;
float ox, oy, sx, sy; float ox, oy, sx, sy;
@ -295,7 +296,7 @@ bool CAutoNuclear::CreateInterface(bool bSelect)
if ( !bSelect ) return true; 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; if ( pw == 0 ) return false;
ox = 3.0f/640.0f; ox = 3.0f/640.0f;
@ -319,9 +320,9 @@ CObject* CAutoNuclear::SearchUranium()
{ {
CObject* pObj; CObject* pObj;
pObj = m_object->RetPower(); pObj = m_object->GetPower();
if ( pObj == 0 ) return 0; if ( pObj == 0 ) return 0;
if ( pObj->RetType() == OBJECT_URANIUM ) return pObj; if ( pObj->GetType() == OBJECT_URANIUM ) return pObj;
return 0; return 0;
} }
@ -337,10 +338,10 @@ bool CAutoNuclear::SearchVehicle()
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
type = pObj->RetType(); type = pObj->GetType();
if ( type != OBJECT_HUMAN && if ( type != OBJECT_HUMAN &&
type != OBJECT_MOBILEfa && type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta && type != OBJECT_MOBILEta &&
@ -392,8 +393,8 @@ void CAutoNuclear::CreatePower()
Math::Vector pos; Math::Vector pos;
float angle; float angle;
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
angle = m_object->RetAngleY(0); angle = m_object->GetAngleY(0);
power = new CObject(m_iMan); power = new CObject(m_iMan);
if ( !power->CreateResource(pos, angle, OBJECT_ATOMIC) ) 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; CObject* pObj;
ObjectType type; ObjectType type;
//? TerrainRes res; //? TerrainRes res;
if ( m_object->RetVirusMode() ) if ( m_object->GetVirusMode() )
{ {
return ERR_BAT_VIRUS; 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 ( 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 == 0 ) return ERR_NUCLEAR_EMPTY;
if ( pObj->RetLock() ) return ERR_OK; if ( pObj->GetLock() ) return ERR_OK;
type = pObj->RetType(); type = pObj->GetType();
if ( type == OBJECT_ATOMIC ) return ERR_OK; if ( type == OBJECT_ATOMIC ) return ERR_OK;
if ( type != OBJECT_URANIUM ) return ERR_NUCLEAR_BAD; if ( type != OBJECT_URANIUM ) return ERR_NUCLEAR_BAD;
@ -472,11 +473,11 @@ bool CAutoNuclear::Read(char *line)
CAuto::Read(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_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
return true; return true;
} }

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autopara.h" #include "object/auto/autopara.h"
@ -26,6 +25,8 @@
#include "ui/interface.h" #include "ui/interface.h"
#include "ui/window.h" #include "ui/window.h"
#include <stdio.h>
#include <string.h>
@ -68,9 +69,9 @@ void CAutoPara::Init()
m_time = 0.0f; m_time = 0.0f;
m_timeVirus = 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_pos = Math::Transform(*mat, Math::Vector(22.0f, 4.0f, 0.0f));
m_phase = APAP_WAIT; // waiting ... m_phase = APAP_WAIT; // waiting ...
@ -83,9 +84,9 @@ void CAutoPara::Init()
// Reception of lightning. // Reception of lightning.
void CAutoPara::StartBlitz() void CAutoPara::StartLightning()
{ {
m_phase = APAP_BLITZ; m_phase = APAP_LIGHTNING;
m_progress = 0.0f; m_progress = 0.0f;
m_speed = 1.0f/2.0f; m_speed = 1.0f/2.0f;
} }
@ -101,13 +102,13 @@ bool CAutoPara::EventProcess(const Event &event)
CAuto::EventProcess(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;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
m_timeVirus -= 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 ) if ( m_timeVirus <= 0.0f )
{ {
@ -118,17 +119,17 @@ bool CAutoPara::EventProcess(const Event &event)
EventProgress(event.rTime); EventProgress(event.rTime);
if ( m_phase == APAP_BLITZ ) if ( m_phase == APAP_LIGHTNING )
{ {
if ( m_progress < 1.0f ) 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++ ) 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.x += (Math::Rand()-0.5f)*m_progress*40.0f;
pos.z += (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; 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; speed.y = 5.0f+Math::Rand()*5.0f;
dim.x = 2.0f; dim.x = 2.0f;
dim.y = dim.x; 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_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++ ) for ( i=0 ; i<2 ; i++ )
{ {
pos = m_object->RetPosition(0); pos = m_object->GetPosition(0);
pos.y += 16.0f; pos.y += 16.0f;
speed.x = (Math::Rand()-0.5f)*10.0f; speed.x = (Math::Rand()-0.5f)*10.0f;
speed.z = (Math::Rand()-0.5f)*10.0f; speed.z = (Math::Rand()-0.5f)*10.0f;
speed.y = -Math::Rand()*30.0f; speed.y = -Math::Rand()*30.0f;
dim.x = 1.0f; dim.x = 1.0f;
dim.y = dim.x; 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) bool CAutoPara::CreateInterface(bool bSelect)
{ {
CWindow* pw; Ui::CWindow* pw;
Math::Point pos, ddim; Math::Point pos, ddim;
float ox, oy, sx, sy; float ox, oy, sx, sy;
@ -196,7 +197,7 @@ bool CAutoPara::CreateInterface(bool bSelect)
if ( !bSelect ) return true; 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; if ( pw == 0 ) return false;
ox = 3.0f/640.0f; 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; return ERR_BAT_VIRUS;
} }
@ -242,38 +243,38 @@ void CAutoPara::ChargeObject(float rTime)
float dist, energy; float dist, energy;
int i; int i;
sPos = m_object->RetPosition(0); sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
oPos = pObj->RetPosition(0); oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, sPos); dist = Math::Distance(oPos, sPos);
if ( dist > 20.0f ) continue; 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; energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f; if ( energy > 1.0f ) energy = 1.0f;
pObj->SetEnergy(energy); pObj->SetEnergy(energy);
} }
power = pObj->RetPower(); power = pObj->GetPower();
if ( power != 0 && power->RetType() == OBJECT_POWER ) if ( power != 0 && power->GetType() == OBJECT_POWER )
{ {
energy = power->RetEnergy(); energy = power->GetEnergy();
energy += rTime/2.0f; energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f; if ( energy > 1.0f ) energy = 1.0f;
power->SetEnergy(energy); power->SetEnergy(energy);
} }
power = pObj->RetFret(); power = pObj->GetFret();
if ( power != 0 && power->RetType() == OBJECT_POWER ) if ( power != 0 && power->GetType() == OBJECT_POWER )
{ {
energy = power->RetEnergy(); energy = power->GetEnergy();
energy += rTime/2.0f; energy += rTime/2.0f;
if ( energy > 1.0f ) energy = 1.0f; if ( energy > 1.0f ) energy = 1.0f;
power->SetEnergy(energy); power->SetEnergy(energy);
@ -315,11 +316,11 @@ bool CAutoPara::Read(char *line)
CAuto::Read(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_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
return true; return true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
// * This file is part of the COLOBOT source code // * This file is part of the COLOBOT source code
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch // * 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 // * 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 // * 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/. // * along with this program. If not, see http://www.gnu.org/licenses/.
#include <stdio.h>
#include "object/auto/autorepair.h" #include "object/auto/autorepair.h"
#include "common/iman.h" #include "common/iman.h"
@ -25,6 +24,9 @@
#include "ui/interface.h" #include "ui/interface.h"
#include "ui/window.h" #include "ui/window.h"
#include <stdio.h>
#include <string.h>
// Object's constructor. // Object's constructor.
@ -60,7 +62,7 @@ void CAutoRepair::Init()
m_time = 0.0f; m_time = 0.0f;
m_timeVirus = 0.0f; m_timeVirus = 0.0f;
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
CAuto::Init(); CAuto::Init();
} }
@ -77,13 +79,13 @@ bool CAutoRepair::EventProcess(const Event &event)
CAuto::EventProcess(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;
m_progress += event.rTime*m_speed; m_progress += event.rTime*m_speed;
m_timeVirus -= 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 ) if ( m_timeVirus <= 0.0f )
{ {
@ -104,7 +106,7 @@ bool CAutoRepair::EventProcess(const Event &event)
} }
else 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_phase = ARP_DOWN;
m_progress = 0.0f; m_progress = 0.0f;
@ -123,7 +125,7 @@ bool CAutoRepair::EventProcess(const Event &event)
else else
{ {
m_object->SetAngleZ(1, 0.0f); 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_phase = ARP_REPAIR;
m_progress = 0.0f; m_progress = 0.0f;
@ -135,21 +137,21 @@ bool CAutoRepair::EventProcess(const Event &event)
{ {
vehicule = SearchVehicle(); vehicule = SearchVehicle();
if ( m_progress < 1.0f || if ( m_progress < 1.0f ||
(vehicule != 0 && vehicule->RetShield() < 1.0f) ) (vehicule != 0 && vehicule->GetShield() < 1.0f) )
{ {
if ( vehicule != 0 ) if ( vehicule != 0 )
{ {
shield = vehicule->RetShield(); shield = vehicule->GetShield();
shield += event.rTime*0.2f; shield += event.rTime*0.2f;
if ( shield > 1.0f ) shield = 1.0f; if ( shield > 1.0f ) shield = 1.0f;
vehicule->SetShield(shield); 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.x += (Math::Rand()-0.5f)*5.0f;
pos.z += (Math::Rand()-0.5f)*5.0f; pos.z += (Math::Rand()-0.5f)*5.0f;
pos.y += 1.0f; pos.y += 1.0f;
@ -158,12 +160,12 @@ bool CAutoRepair::EventProcess(const Event &event)
speed.y = Math::Rand()*15.0f; speed.y = Math::Rand()*15.0f;
dim.x = Math::Rand()*6.0f+4.0f; dim.x = Math::Rand()*6.0f+4.0f;
dim.y = dim.x; 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 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_phase = ARP_UP;
m_progress = 0.0f; m_progress = 0.0f;
@ -196,7 +198,7 @@ bool CAutoRepair::EventProcess(const Event &event)
bool CAutoRepair::CreateInterface(bool bSelect) bool CAutoRepair::CreateInterface(bool bSelect)
{ {
CWindow* pw; Ui::CWindow* pw;
Math::Point pos, ddim; Math::Point pos, ddim;
float ox, oy, sx, sy; float ox, oy, sx, sy;
@ -204,7 +206,7 @@ bool CAutoRepair::CreateInterface(bool bSelect)
if ( !bSelect ) return true; 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; if ( pw == 0 ) return false;
ox = 3.0f/640.0f; ox = 3.0f/640.0f;
@ -233,14 +235,14 @@ CObject* CAutoRepair::SearchVehicle()
float dist; float dist;
int i; int i;
sPos = m_object->RetPosition(0); sPos = m_object->GetPosition(0);
for ( i=0 ; i<1000000 ; i++ ) 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 == 0 ) break;
type = pObj->RetType(); type = pObj->GetType();
if ( type != OBJECT_MOBILEfa && if ( type != OBJECT_MOBILEfa &&
type != OBJECT_MOBILEta && type != OBJECT_MOBILEta &&
type != OBJECT_MOBILEwa && type != OBJECT_MOBILEwa &&
@ -269,10 +271,10 @@ CObject* CAutoRepair::SearchVehicle()
type != OBJECT_MOBILEit && type != OBJECT_MOBILEit &&
type != OBJECT_MOBILEdr ) continue; type != OBJECT_MOBILEdr ) continue;
physics = pObj->RetPhysics(); physics = pObj->GetPhysics();
if ( physics != 0 && !physics->RetLand() ) continue; // in flight? if ( physics != 0 && !physics->GetLand() ) continue; // in flight?
oPos = pObj->RetPosition(0); oPos = pObj->GetPosition(0);
dist = Math::Distance(oPos, sPos); dist = Math::Distance(oPos, sPos);
if ( dist <= 5.0f ) return pObj; 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; return ERR_BAT_VIRUS;
} }
@ -327,11 +329,11 @@ bool CAutoRepair::Read(char *line)
CAuto::Read(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_progress = OpFloat(line, "aProgress", 0.0f);
m_speed = OpFloat(line, "aSpeed", 1.0f); m_speed = OpFloat(line, "aSpeed", 1.0f);
m_lastParticule = 0.0f; m_lastParticle = 0.0f;
return true; return true;
} }

View File

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

View File

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

View File

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

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