spawn pirates on entry to system. not determining strength by system yet.

git-svn-id: https://pioneer.svn.sourceforge.net/svnroot/pioneer/trunk@214 e632f14b-6550-0410-b89e-a82653faca30
master
tompox 2009-02-19 18:40:11 +00:00
parent 20cf579a8d
commit 329666a7d1
12 changed files with 150 additions and 5 deletions

3
TODO
View File

@ -1,6 +1,9 @@
There is much to be done...
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Collision fuckup: sometimes you can be shot by pirates but you cannot score hits on them...
* Sfx look utterly shit
* Make scanner only appear at appropriate times
* Internal engine fuel usage (refuel on inventory page)
* Political alignments of systems (probably needed for trade model):

View File

@ -32,5 +32,5 @@ LIBS="$LIBS $SDL_LIBS -lSDL_image"
CXXFLAGS="$CFLAGS"
AC_CONFIG_FILES([Makefile src/Makefile src/sbre/Makefile src/collider/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile src/sbre/Makefile src/collider/Makefile src/mods/Makefile])
AC_OUTPUT

View File

@ -1,5 +1,5 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = sbre/ collider/
SUBDIRS = sbre/ collider/ mods/
bin_PROGRAMS = pioneer sbreviewer
noinst_LIBRARIES = libgui.a
@ -21,7 +21,7 @@ pioneer_SOURCES = main.cpp glfreetype.cpp Body.cpp Space.cpp Ship.cpp Player.cpp
SpaceStationView.cpp ModelBody.cpp ShipType.cpp InfoView.cpp ModelCollMeshData.cpp \
ObjectViewerView.cpp custom_starsystems.cpp Serializer.cpp Sfx.cpp Ship-AI.cpp MarketAgent.cpp \
EquipType.cpp CargoBody.cpp
pioneer_LDADD = sbre/libsbre.a collider/libcollider.a libgui.a
pioneer_LDADD = sbre/libsbre.a collider/libcollider.a mods/libmods.a libgui.a
sbreviewer_SOURCES = SbreViewer.cpp glfreetype.cpp
sbreviewer_LDADD = sbre/libsbre.a collider/libcollider.a libgui.a

View File

@ -69,6 +69,7 @@ public:
static sigc::signal<void, int, int, int> onMouseButtonUp;
static sigc::signal<void, int, int, int> onMouseButtonDown;
static sigc::signal<void> onPlayerChangeHyperspaceTarget;
static sigc::signal<void> onPlayerHyperspaceToNewSystem;
static MTRand rng;

View File

@ -39,11 +39,15 @@ void Sfx::SetPosition(vector3d p)
void Sfx::TimeStepUpdate(const float timeStep)
{
m_age += timeStep;
m_pos += m_vel * timeStep;
switch (m_type) {
case TYPE_EXPLOSION:
if (m_age > 0.2) Space::KillBody(this);
break;
case TYPE_DAMAGE:
if (m_age > 2.0) Space::KillBody(this);
break;
}
}
void Sfx::Render(const Frame *camFrame)
@ -69,6 +73,14 @@ void Sfx::Render(const Frame *camFrame)
gluSphere(Pi::gluQuadric, 2000*m_age, 20,20);
glPopAttrib();
break;
case TYPE_DAMAGE:
glPushAttrib(GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT);
glDisable(GL_LIGHTING);
float s = 0.5*sin(m_age*10);
glColor3f(.5,.5,.5);
gluSphere(Pi::gluQuadric, 5+s*s*8, 10,10);
glPopAttrib();
break;
}
glPopMatrix();
@ -80,5 +92,6 @@ void Sfx::Add(const Body *b, TYPE t)
sfx->m_type = t;
sfx->SetFrame(b->GetFrame());
sfx->SetPosition(b->GetPosition());
sfx->m_vel = b->GetVelocity();
Space::AddBody(sfx);
}

View File

@ -8,7 +8,7 @@ class Frame;
class Sfx: public Body {
public:
OBJDEF(Sfx, Body, SFX);
enum TYPE { TYPE_EXPLOSION };
enum TYPE { TYPE_EXPLOSION, TYPE_DAMAGE };
static void Add(const Body *, TYPE);
@ -25,6 +25,7 @@ protected:
virtual void Load();
private:
vector3d m_pos;
vector3d m_vel;
float m_age;
enum TYPE m_type;
};

View File

@ -120,6 +120,16 @@ void Ship::PostLoadFixup()
}
}
static std::string make_random_ship_registration()
{
char buf[32];
snprintf(buf, sizeof(buf), "%c%c-%04d",
'A' + Pi::rng.Int32(26),
'A' + Pi::rng.Int32(26),
Pi::rng.Int32(10000));
return std::string(buf);
}
Ship::Ship(ShipType::Type shipType): DynamicBody()
{
m_flightState = FLYING;
@ -139,6 +149,7 @@ Ship::Ship(ShipType::Type shipType): DynamicBody()
m_gunState[i] = 0;
}
memset(m_thrusters, 0, sizeof(m_thrusters));
SetLabel(make_random_ship_registration().c_str());
Init();
}
@ -155,6 +166,8 @@ bool Ship::OnDamage(Body *attacker, float kgDamage)
if (m_stats.hull_mass_left < 0) {
Space::KillBody(this);
Sfx::Add(this, Sfx::TYPE_EXPLOSION);
} else {
Sfx::Add(this, Sfx::TYPE_DAMAGE);
}
//printf("Ouch! %s took %.1f kilos of damage from %s! (%.1f t hull left)\n", GetLabel().c_str(), kgDamage, attacker->GetLabel().c_str(), m_stats.hull_mass_left);
return true;
@ -445,8 +458,16 @@ bool Ship::IsFiringLasers()
/* Assumed to be at model coords */
void Ship::RenderLaserfire()
{
static const GLfloat fogDensity = 0.001;
static const GLfloat fogColor[4] = { 0,0,0,1.0 };
const ShipType &stype = GetShipType();
glDisable(GL_LIGHTING);
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, fogDensity);
glHint(GL_FOG_HINT, GL_NICEST);
for (int i=0; i<ShipType::GUNMOUNT_MAX; i++) {
if (!m_gunState[i]) continue;
glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT);
@ -467,6 +488,7 @@ void Ship::RenderLaserfire()
glEnd();
glPopAttrib();
}
glDisable(GL_FOG);
glEnable(GL_LIGHTING);
}

View File

@ -20,6 +20,7 @@
#include "CargoBody.h"
#include "InfoView.h"
#include "Serializer.h"
#include "mods/Mods.h"
float Pi::timeAccel = 1.0f;
int Pi::scrWidth;
@ -31,6 +32,7 @@ sigc::signal<void, SDL_keysym*> Pi::onKeyRelease;
sigc::signal<void, int, int, int> Pi::onMouseButtonUp;
sigc::signal<void, int, int, int> Pi::onMouseButtonDown;
sigc::signal<void> Pi::onPlayerChangeHyperspaceTarget;
sigc::signal<void> Pi::onPlayerHyperspaceToNewSystem;
char Pi::keyState[SDLK_LAST];
char Pi::mouseButton[5];
int Pi::mouseMotion[2];
@ -108,6 +110,7 @@ void Pi::Init(IniConfig &config)
Space::Init();
Gui::Init(scrWidth, scrHeight, 800, 600);
Mods::Init();
}
void Pi::InitOpenGL()
@ -223,7 +226,6 @@ void Pi::HandleEvents()
} else {
Ship *ship = new Ship(ShipType::LADYBIRD);
ship->AIInstruct(Ship::DO_KILL, Pi::player);
ship->SetLabel("A friend");
ship->SetFrame(Pi::player->GetFrame());
ship->SetPosition(Pi::player->GetPosition()+100.0*dir);
ship->SetVelocity(Pi::player->GetVelocity());
@ -572,6 +574,7 @@ StarSystem *Pi::GetSelectedSystem()
void Pi::HyperspaceTo(const SBodyPath *dest)
{
bool new_system = false;
if (currentSystem) {
if (!currentSystem->IsSystem(dest->sectorX, dest->sectorY, dest->systemIdx)) {
delete currentSystem;
@ -582,6 +585,7 @@ void Pi::HyperspaceTo(const SBodyPath *dest)
currentSystem = new StarSystem(dest->sectorX, dest->sectorY, dest->systemIdx);
Space::Clear();
Space::BuildSystem();
new_system = true;
}
@ -596,6 +600,8 @@ void Pi::HyperspaceTo(const SBodyPath *dest)
cos(longitude)*cos(latitude)*dist));
Pi::player->SetVelocity(vector3d(0.0));
Pi::player->SetFrame(pframe);
if (new_system) Pi::onPlayerHyperspaceToNewSystem.emit();
}
void Pi::Serialize()

6
src/mods/Makefile.am Normal file
View File

@ -0,0 +1,6 @@
# Process this file with automake to produce Makefile.in
noinst_LIBRARIES = libmods.a
libmods_a_SOURCES = Mods.cpp pirates.cpp
include_HEADERS = Mods.h

17
src/mods/Mods.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "../libs.h"
#include "Mods.h"
/* yes, truly dynamic my friend */
namespace Mods {
extern void InitModPirates();
void Init()
{
InitModPirates();
printf("Modules initialised!\n");
}
}

8
src/mods/Mods.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _MODS_H
#define _MODS_H
namespace Mods {
extern void Init();
}
#endif /* _MODS_H */

68
src/mods/pirates.cpp Normal file
View File

@ -0,0 +1,68 @@
#include "../libs.h"
#include "../Pi.h"
#include "../Ship.h"
#include "../Space.h"
#include "../Frame.h"
#include "../Player.h"
#include "Mods.h"
namespace Mods {
static void spawn_random_pirate(int power, Ship *victim)
{
float longitude = Pi::rng.Double(M_PI);
float latitude = Pi::rng.Double(M_PI);
float dist = 2000.0f;
vector3d relpos(vector3d(sin(longitude)*cos(latitude)*dist,
sin(latitude)*dist,
cos(longitude)*cos(latitude)*dist));
ShipType::Type t;
switch(Pi::rng.Int32(5) + power) {
case 0: case 1:
case 2: case 3:
t = ShipType::LADYBIRD;
break;
default:
t = ShipType::SWANKY;
break;
}
Ship *ship = new Ship(t);
ship->AIInstruct(Ship::DO_KILL, victim);
ship->SetFrame(victim->GetFrame());
ship->SetPosition(victim->GetPosition() + relpos);
ship->SetVelocity(victim->GetVelocity());
Space::AddBody(ship);
ship->m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1);
switch (power) {
case 1:
ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::LASER_2MW_BEAM);
break;
case 2:
ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::LASER_4MW_BEAM);
break;
case 0:
default:
ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::LASER_1MW_BEAM);
break;
}
int amount = Pi::rng.Int32(5);
while (amount--) ship->m_equipment.Add(Equip::SLOT_CARGO, Equip::HYDROGEN);
}
static void OnPlayerHyperspaceToNewSystem()
{
int num_pirates = Pi::rng.Int32(4);
while (num_pirates--) spawn_random_pirate(Pi::rng.Int32(1,3), Pi::player);
}
void InitModPirates()
{
Pi::onPlayerHyperspaceToNewSystem.connect(sigc::ptr_fun(&OnPlayerHyperspaceToNewSystem));
}
}