remove MarketAgent, Lua can do it all now

master
Robert Norris 2013-11-14 16:43:34 +11:00
parent 4918aca6c0
commit 7f453624e6
9 changed files with 12 additions and 214 deletions

View File

@ -84,7 +84,6 @@ noinst_HEADERS = \
LuaTimer.h \
LuaUtils.h \
LuaWrappable.h \
MarketAgent.h \
MathUtil.h \
Missile.h \
ModelBody.h \
@ -224,7 +223,6 @@ pioneer_SOURCES = \
LuaStarSystem.cpp \
LuaTimer.cpp \
LuaUtils.cpp \
MarketAgent.cpp \
MathUtil.cpp \
Missile.cpp \
ModelBody.cpp \

View File

@ -1,52 +0,0 @@
// Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "MarketAgent.h"
#include "Serializer.h"
#include "Player.h"
#include "Pi.h"
#include "Lang.h"
void MarketAgent::Load(Serializer::Reader &rd)
{
m_money = rd.Int64();
}
void MarketAgent::Save(Serializer::Writer &wr) const
{
wr.Int64(m_money);
}
bool MarketAgent::SellTo(MarketAgent *other, Equip::Type t, bool verbose)
{
if (other->CanBuy(t, verbose) && CanSell(t, verbose) && other->Pay(this, GetPrice(t), verbose)) {
Sold(t);
other->Bought(t);
return true;
} else return false;
}
bool MarketAgent::BuyFrom(MarketAgent *other, Equip::Type t, bool verbose)
{
if (other->CanSell(t, verbose) && CanBuy(t, verbose) && Pay(other, GetPrice(t), verbose)) {
other->Sold(t);
Bought(t);
return true;
} else return false;
}
bool MarketAgent::Pay(MarketAgent *b, Sint64 amount, bool verbose) {
if (m_money < amount) {
if (verbose) {
if (this == Pi::player) {
Pi::Message(Lang::YOU_NOT_ENOUGH_MONEY);
} else {
Pi::Message(Lang::TRADER_NOT_ENOUGH_MONEY);
}
}
return false;
}
b->m_money += amount;
m_money -= amount;
return true;
}

View File

@ -1,40 +0,0 @@
// Copyright © 2008-2013 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef _MARKETAGENT_H
#define _MARKETAGENT_H
#include "libs.h"
#include "ShipType.h"
#include "Serializer.h"
class MarketAgent {
public:
MarketAgent(): m_money(0) {}
void SetMoney(Sint64 m) { m_money = m; }
Sint64 GetMoney() const { return m_money; }
bool Pay(MarketAgent *b, Sint64 amount, bool verbose = false);
/**
* SellTo() and BuyFrom() use the commodity price of this MarketAgent.
* When verbose=true then functions should make cpanel messages about
* why they failed ("You have no space", etc)
*/
bool SellTo(MarketAgent *other, Equip::Type t, bool verbose = false);
bool BuyFrom(MarketAgent *other, Equip::Type t, bool verbose = false);
virtual Sint64 GetPrice(Equip::Type t) const = 0;
virtual bool CanBuy(Equip::Type t, bool verbose = false) const = 0;
// can sell means do we have enough stock
virtual bool CanSell(Equip::Type t, bool verbose = false) const = 0;
// does sell means do we bother with this commodity?
virtual bool DoesSell(Equip::Type t) const = 0;
virtual int GetStock(Equip::Type t) const = 0;
protected:
virtual void Bought(Equip::Type t) = 0;
virtual void Sold(Equip::Type t) = 0;
void Load(Serializer::Reader &rd);
void Save(Serializer::Writer &wr) const;
private:
Sint64 m_money;
};
#endif /* _MARKETAGENT_H */

View File

@ -675,11 +675,6 @@ void Pi::HandleEvents()
break;
#endif
case SDLK_m: // Gimme money!
if(Pi::game) {
Pi::player->SetMoney(Pi::player->GetMoney() + 10000000);
}
break;
case SDLK_F12:
{
if(Pi::game) {

View File

@ -27,14 +27,12 @@ Player::Player(ShipType::Id shipId): Ship(shipId)
void Player::Save(Serializer::Writer &wr, Space *space)
{
Ship::Save(wr, space);
MarketAgent::Save(wr);
}
void Player::Load(Serializer::Reader &rd, Space *space)
{
Pi::player = this;
Ship::Load(rd, space);
MarketAgent::Load(rd);
}
//XXX perhaps remove this, the sound is very annoying
@ -117,58 +115,6 @@ void Player::NotifyRemoved(const Body* const removedBody)
Ship::NotifyRemoved(removedBody);
}
/* MarketAgent shite */
//XXX move to Player character .cpp
void Player::Bought(Equip::Type t)
{
m_equipment.Add(t);
UpdateEquipStats();
}
void Player::Sold(Equip::Type t)
{
m_equipment.Remove(t, 1);
UpdateEquipStats();
}
bool Player::CanBuy(Equip::Type t, bool verbose) const
{
Equip::Slot slot = Equip::types[int(t)].slot;
bool freespace = (m_equipment.FreeSpace(slot)!=0);
bool freecapacity = (GetStats().free_capacity >= Equip::types[int(t)].mass);
if (verbose) {
if (!freespace) {
Pi::Message(Lang::NO_FREE_SPACE_FOR_ITEM);
}
else if (!freecapacity) {
Pi::Message(Lang::SHIP_IS_FULLY_LADEN);
}
}
return (freespace && freecapacity);
}
bool Player::CanSell(Equip::Type t, bool verbose) const
{
Equip::Slot slot = Equip::types[int(t)].slot;
bool cansell = (m_equipment.Count(slot, t) > 0);
if (verbose) {
if (!cansell) {
Pi::Message(stringf(Lang::YOU_DO_NOT_HAVE_ANY_X, formatarg("item", Equip::types[int(t)].name)));
}
}
return cansell;
}
Sint64 Player::GetPrice(Equip::Type t) const
{
if (Ship::GetDockedWith()) {
return Ship::GetDockedWith()->GetPrice(t);
} else {
assert(0);
return 0;
}
}
//XXX ui stuff
void Player::OnEnterHyperspace()
{

View File

@ -7,14 +7,13 @@
#include "libs.h"
#include <list>
#include "HyperspaceCloud.h"
#include "MarketAgent.h"
#include "Ship.h"
#include "ShipController.h"
#include "galaxy/StarSystem.h"
namespace Graphics { class Renderer; }
class Player: public Ship, public MarketAgent {
class Player: public Ship {
public:
OBJDEF(Player, Ship, PLAYER);
Player(ShipType::Id shipId);
@ -26,13 +25,6 @@ public:
virtual void SetAlertState(Ship::AlertState as);
virtual void NotifyRemoved(const Body* const removedBody);
/* MarketAgent stuff */
int GetStock(Equip::Type t) const { assert(0); return 0; }
bool CanBuy(Equip::Type t, bool verbose) const;
bool CanSell(Equip::Type t, bool verbose) const;
bool DoesSell(Equip::Type t) const { return true; }
Sint64 GetPrice(Equip::Type t) const;
PlayerShipController *GetPlayerController() const;
//XXX temporary things to avoid causing too many changes right now
Body *GetCombatTarget() const;
@ -50,10 +42,6 @@ protected:
virtual void OnEnterSystem();
virtual void OnEnterHyperspace();
/* MarketAgent stuff */
void Bought(Equip::Type t);
void Sold(Equip::Type t);
};
#endif /* _PLAYER_H */

View File

@ -36,11 +36,7 @@ void SpaceStation::Uninit()
void SpaceStation::Save(Serializer::Writer &wr, Space *space)
{
ModelBody::Save(wr, space);
MarketAgent::Save(wr);
wr.Int32(Equip::TYPE_MAX);
for (int i=0; i<Equip::TYPE_MAX; i++) {
wr.Int32(int(m_equipmentStock[i]));
}
wr.Int32(m_shipDocking.size());
for (Uint32 i=0; i<m_shipDocking.size(); i++) {
wr.Int32(space->GetIndexForBody(m_shipDocking[i].ship));
@ -73,15 +69,8 @@ void SpaceStation::Save(Serializer::Writer &wr, Space *space)
void SpaceStation::Load(Serializer::Reader &rd, Space *space)
{
ModelBody::Load(rd, space);
MarketAgent::Load(rd);
int num = rd.Int32();
if (num > Equip::TYPE_MAX) throw SavedGameCorruptException();
for (int i=0; i<Equip::TYPE_MAX; i++) {
m_equipmentStock[i] = 0;
}
for (int i=0; i<num; i++) {
m_equipmentStock[i] = static_cast<Equip::Type>(rd.Int32());
}
const Uint32 numShipDocking = rd.Int32();
m_shipDocking.reserve(numShipDocking);
for (Uint32 i=0; i<numShipDocking; i++) {
@ -138,7 +127,6 @@ SpaceStation::SpaceStation(const SystemBody *sbody): ModelBody()
m_doorAnimationStep = m_doorAnimationState = 0.0;
SetMoney(1000000000);
InitStation();
}
@ -540,32 +528,6 @@ bool SpaceStation::IsGroundStation() const
return (m_type->dockMethod == SpaceStationType::SURFACE);
}
/* MarketAgent shite */
void SpaceStation::Bought(Equip::Type t) {
m_equipmentStock[int(t)]++;
}
void SpaceStation::Sold(Equip::Type t) {
m_equipmentStock[int(t)]--;
}
bool SpaceStation::CanBuy(Equip::Type t, bool verbose) const {
return true;
}
bool SpaceStation::CanSell(Equip::Type t, bool verbose) const {
bool result = (m_equipmentStock[int(t)] > 0);
if (verbose && !result) {
Pi::Message(Lang::ITEM_IS_OUT_OF_STOCK);
}
return result;
}
bool SpaceStation::DoesSell(Equip::Type t) const {
return Polit::IsCommodityLegal(Pi::game->GetSpace()->GetStarSystem().Get(), t);
}
Sint64 SpaceStation::GetPrice(Equip::Type t) const {
Sint64 mul = 100 + Pi::game->GetSpace()->GetStarSystem()->GetCommodityBasePriceModPercent(t);
return (mul * Sint64(Equip::types[t].basePrice)) / 100;
}
// Renders space station and adjacent city if applicable
// For orbital starports: renders as normal
// For surface starports:

View File

@ -6,7 +6,6 @@
#include "libs.h"
#include "Camera.h"
#include "MarketAgent.h"
#include "ModelBody.h"
#include "NavLights.h"
#include "Quaternion.h"
@ -26,7 +25,7 @@ class SystemBody;
namespace Graphics { class Renderer; }
namespace SceneGraph { class Animation; }
class SpaceStation: public ModelBody, public MarketAgent {
class SpaceStation: public ModelBody {
public:
OBJDEF(SpaceStation, ModelBody, SPACESTATION);
static void Init();
@ -42,13 +41,6 @@ public:
virtual void StaticUpdate(const float timeStep);
virtual void TimeStepUpdate(const float timeStep);
void AddEquipmentStock(Equip::Type t, int num) { m_equipmentStock[t] += num; }
/* MarketAgent stuff */
int GetStock(Equip::Type t) const { return m_equipmentStock[t]; }
Sint64 GetPrice(Equip::Type t) const;
bool CanBuy(Equip::Type t, bool verbose) const;
bool CanSell(Equip::Type t, bool verbose) const;
bool DoesSell(Equip::Type t) const;
virtual const SystemBody *GetSystemBody() const { return m_sbody; }
virtual void PostLoadFixup(Space *space);
virtual void NotifyRemoved(const Body* const removedBody);
@ -120,7 +112,6 @@ private:
void InitStation();
const SpaceStationType *m_type;
const SystemBody *m_sbody;
int m_equipmentStock[Equip::TYPE_MAX];
CityOnPlanet *m_adjacentCity;
double m_distFromPlanet;
int m_numPoliceDocked;

View File

@ -1032,6 +1032,10 @@ static void PlayerRequestDockingClearance(SpaceStation *s)
Pi::cpan->MsgLog()->ImportantMessage(s->GetLabel(), msg);
}
// XXX paying fine remotely can't really be done until crime and
// worldview are in Lua. I'm leaving this code here so its not
// forgotten
/*
static void PlayerPayFine()
{
Sint64 crime, fine;
@ -1053,6 +1057,7 @@ static void PlayerPayFine()
Polit::AddCrime(0, -fine);
}
}
*/
void WorldView::OnHyperspaceTargetChanged()
{
@ -1146,6 +1151,10 @@ void WorldView::UpdateCommsOptions()
ypos += 32;
}
// XXX paying fine remotely can't really be done until crime and
// worldview are in Lua. I'm leaving this code here so its not
// forgotten
/*
Sint64 crime, fine;
Polit::GetCrime(&crime, &fine);
if (fine) {
@ -1154,6 +1163,7 @@ void WorldView::UpdateCommsOptions()
button->onClick.connect(sigc::ptr_fun(&PlayerPayFine));
ypos += 32;
}
*/
}
if (hasAutopilot) {
button = AddCommsOption(stringf(Lang::AUTOPILOT_FLY_TO_VICINITY_OF, formatarg("target", navtarget->GetLabel())), ypos, optnum++);