Added Bucket object. Water pump now fills bucket (then cycles to empty and repeats)

coolant-mod
immibis 2020-02-02 12:46:27 +01:00
parent 80840b7c95
commit d7cf54c55b
10 changed files with 35 additions and 14 deletions

View File

@ -369,6 +369,7 @@ set(BASE_SOURCES
object/interface/flying_object.h
object/interface/fragile_object.h
object/interface/interactive_object.h
object/interface/liquid_container_object.h
object/interface/jet_flying_object.h
object/interface/jostleable_object.h
object/interface/movable_object.h
@ -426,6 +427,7 @@ set(BASE_SOURCES
object/subclass/base_robot.h
object/subclass/base_vehicle.cpp
object/subclass/base_vehicle.h
object/subclass/bucket.cpp
object/subclass/exchange_post.cpp
object/subclass/exchange_post.h
object/subclass/shielder.cpp

View File

@ -924,7 +924,8 @@ void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
type == OBJECT_ANT ||
type == OBJECT_SPIDER ||
type == OBJECT_BEE ||
type == OBJECT_WORM ) continue;
type == OBJECT_WORM ||
type == OBJECT_BUCKET ) continue;
Math::Sphere objSphere = obj->GetCameraCollisionSphere();
Math::Vector objPos = objSphere.pos;

View File

@ -534,6 +534,7 @@ ObjectType CLevelParserParam::ToObjectType(std::string value)
if (value == "Tech" ) return OBJECT_TECH;
if (value == "MissionController" ) return OBJECT_CONTROLLER;
if (value == "WaterPump" ) return OBJECT_WATERPUMP;
if (value == "Bucket" ) return OBJECT_BUCKET;
return static_cast<ObjectType>(Cast<int>(value, "object"));
}
@ -732,6 +733,7 @@ const std::string CLevelParserParam::FromObjectType(ObjectType value)
if (value == OBJECT_TECH ) return "Tech";
if (value == OBJECT_CONTROLLER ) return "MissionController";
if (value == OBJECT_WATERPUMP ) return "WaterPump";
if (value == OBJECT_BUCKET ) return "Bucket";
return boost::lexical_cast<std::string>(static_cast<int>(value));
}

View File

@ -91,6 +91,10 @@ CObjectUPtr CObjectFactory::CreateObject(const ObjectCreateParams& params)
case OBJECT_WATERPUMP:
return CreateObjectWaterPump(params, m_oldModelManager, m_modelManager, m_engine);
case OBJECT_BUCKET:
std::unique_ptr<CObject> CreateObjectBucket(const ObjectCreateParams&, Gfx::COldModelManager*, Gfx::CEngine*);
return CreateObjectBucket(params, m_oldModelManager, m_engine);
case OBJECT_PORTICO:
case OBJECT_BASE:
case OBJECT_DERRICK:

View File

@ -45,6 +45,8 @@ struct ObjectCreateParams;
using CObjectUPtr = std::unique_ptr<CObject>;
std::unique_ptr<CObject> CreateObjectBucket(const ObjectCreateParams &params, Gfx::COldModelManager *modelManager, Gfx::CEngine *graphicsEngine);
class CObjectFactory
{
public:

View File

@ -54,6 +54,7 @@ enum class ObjectInterfaceType
Shielded, //!< objects that can be destroyed after the shield goes down to 0
ShieldedAutoRegen, //!< shielded objects with auto shield regeneration
Old, //!< old objects, TODO: remove once no longer necessary
LiquidContainer, //!< liquid container
Max //!< maximum value (for getting number of items in enum)
};

View File

@ -231,6 +231,7 @@ enum ObjectType
OBJECT_APOLLO5 = 904, //!< ApolloAntenna
OBJECT_HOME1 = 910, //!< Home
OBJECT_WATERPUMP = 920, //!< WaterPump
OBJECT_BUCKET = 921, //!< Bucket
OBJECT_MAX = 1000 //!< number of values
};

View File

@ -773,6 +773,7 @@ void COldObject::SetType(ObjectType type)
m_type == OBJECT_SPIDER ||
m_type == OBJECT_BEE ||
m_type == OBJECT_TEEN28 )
// TODO OBJECT_BUCKET
{
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Damageable)] = true;
m_implementedInterfaces[static_cast<int>(ObjectInterfaceType::Destroyable)] = true;
@ -3205,13 +3206,15 @@ float COldObject::GetLightningHitProbability()
m_type == OBJECT_NUCLEAR ||
m_type == OBJECT_PARA ||
m_type == OBJECT_SAFE ||
m_type == OBJECT_HUSTON ) // building?
m_type == OBJECT_HUSTON ||
m_type == OBJECT_WATERPUMP) // building?
{
return 1.0f;
}
if ( m_type == OBJECT_METAL ||
m_type == OBJECT_POWER ||
m_type == OBJECT_ATOMIC ) // resource?
m_type == OBJECT_ATOMIC ||
m_type == OBJECT_BUCKET ) // resource?
{
return 0.3f;
}

View File

@ -18,6 +18,7 @@
*/
#include "object/subclass/water_pump.h"
#include "object/interface/liquid_container_object.h"
#include "common/make_unique.h"
#include "common/regex_utils.h"
@ -67,18 +68,21 @@ struct CAutoWaterPump : public CAuto
CObject *powerCell = m_object->GetPower();
if (powerCell != nullptr) {
if (powerCell->Implements(ObjectInterfaceType::PowerContainer)) {
CPowerContainerObject *asPC = dynamic_cast<CPowerContainerObject*>(powerCell);
float energy = asPC->GetEnergyLevel();
energy += (0.2f * event.rTime) / asPC->GetCapacity();
asPC->SetEnergyLevel(energy);
}
if (powerCell->Implements(ObjectInterfaceType::LiquidContainer)) {
// test code
CLiquidContainerObject *asPC = dynamic_cast<CLiquidContainerObject*>(powerCell);
float energy = asPC->GetLiquidAmount();
energy += (0.2f * event.rTime);
if(energy > 1.0f) energy = 0.0f;
asPC->SetLiquid(LiquidType::WATER, energy);
cycle = fmodf(cycle + event.rTime, 1.0f);
if (cycle < 0.5f)
m_object->SetPartPosition(1, Math::Vector(0.0f, 4.0f * cycle + 1.5f, 0.0f));
else
m_object->SetPartPosition(1, Math::Vector(0.0f, 4.0f - (4.0f * cycle) + 1.5f, 0.0f));
// animation
cycle = fmodf(cycle + event.rTime, 1.0f);
if (cycle < 0.5f)
m_object->SetPartPosition(1, Math::Vector(0.0f, 4.0f * cycle + 1.5f, 0.0f));
else
m_object->SetPartPosition(1, Math::Vector(0.0f, 4.0f - (4.0f * cycle) + 1.5f, 0.0f));
}
}
}
return true; // XXX what does this mean?

View File

@ -116,6 +116,7 @@ const char* GetObjectName(ObjectType type)
if ( type == OBJECT_WORM ) return "AlienWorm";
if ( type == OBJECT_RUINmobilew1) return "Wreck";
if ( type == OBJECT_WATERPUMP ) return "WaterPump";
if ( type == OBJECT_BUCKET ) return "Bucket";
return "";
}