colobot/src/CBot/CBotVar/CBotVarInt.cpp

112 lines
2.6 KiB
C++
Raw Normal View History

/*
* This file is part of the Colobot: Gold Edition source code
2016-02-13 13:11:30 +00:00
* Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "CBot/CBotVar/CBotVarInt.h"
2015-12-26 13:19:24 +00:00
namespace CBot
{
void CBotVarInt::Copy(CBotVar* pSrc, bool bName)
{
2016-05-28 20:59:34 +00:00
CBotVarNumber::Copy(pSrc, bName);
CBotVarInt* p = static_cast<CBotVarInt*>(pSrc);
m_defnum = p->m_defnum;
}
void CBotVarInt::SetValInt(int val, const std::string& defnum)
{
2016-05-28 20:59:34 +00:00
CBotVarNumber::SetValInt(val, defnum);
m_defnum = defnum;
}
std::string CBotVarInt::GetValString()
{
2016-05-28 20:59:34 +00:00
if (!m_defnum.empty()) return m_defnum;
return CBotVarValue::GetValString();
}
2016-05-28 20:59:34 +00:00
void CBotVarInt::Neg()
{
2016-05-28 20:59:34 +00:00
CBotVarNumber::Neg();
m_defnum.empty();
}
2016-05-28 20:59:34 +00:00
void CBotVarInt::Inc()
{
2016-05-28 20:59:34 +00:00
CBotVarNumber::Inc();
m_defnum.empty();
}
2016-05-28 20:59:34 +00:00
void CBotVarInt::Dec()
{
2016-05-28 20:59:34 +00:00
CBotVarNumber::Dec();
m_defnum.empty();
}
void CBotVarInt::XOr(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
SetValInt(left->GetValInt() ^ right->GetValInt());
}
void CBotVarInt::And(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
SetValInt(left->GetValInt() & right->GetValInt());
}
void CBotVarInt::Or(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
SetValInt(left->GetValInt() | right->GetValInt());
}
void CBotVarInt::SL(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
SetValInt(left->GetValInt() << right->GetValInt());
}
void CBotVarInt::ASR(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
SetValInt(left->GetValInt() >> right->GetValInt());
}
void CBotVarInt::SR(CBotVar* left, CBotVar* right)
{
2016-05-28 20:59:34 +00:00
int source = left->GetValInt();
int shift = right->GetValInt();
2016-05-28 20:59:34 +00:00
if (shift >= 1) source &= 0x7fffffff;
SetValInt(source >> shift);
}
void CBotVarInt::Not()
{
m_val = ~m_val;
}
bool CBotVarInt::Save0State(FILE* pf)
{
2016-05-28 20:59:34 +00:00
if (!m_defnum.empty())
{
2016-05-28 20:59:34 +00:00
if(!WriteWord(pf, 200)) return false; // special marker
if(!WriteString(pf, m_defnum)) return false;
}
return CBotVar::Save0State(pf);
}
bool CBotVarInt::Save1State(FILE* pf)
{
2016-05-28 20:59:34 +00:00
return WriteWord(pf, m_val);
}
2015-12-26 13:19:24 +00:00
} // namespace CBot