|
From: <ka...@us...> - 2012-12-29 20:34:55
|
Revision: 7704
http://paintown.svn.sourceforge.net/paintown/?rev=7704&view=rev
Author: kazzmir
Date: 2012-12-29 20:34:48 +0000 (Sat, 29 Dec 2012)
Log Message:
-----------
[paintown] remove hearts
Modified Paths:
--------------
trunk/src/factory/collector.cpp
trunk/src/paintown-engine/factory/object_factory.cpp
trunk/src/paintown-engine/factory/object_factory.h
trunk/src/paintown-engine/game/adventure_world.cpp
trunk/src/paintown-engine/level/block.cpp
trunk/src/paintown-engine/level/block.h
trunk/src/paintown-engine/level/scene.cpp
trunk/src/paintown-engine/level/scene.h
trunk/src/paintown-engine/object/enemy.cpp
trunk/src/paintown-engine/object/enemy.h
trunk/src/paintown-engine/object/object.cpp
trunk/src/paintown-engine/object/object.h
Modified: trunk/src/factory/collector.cpp
===================================================================
--- trunk/src/factory/collector.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/factory/collector.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -1,6 +1,5 @@
#include "util/graphics/bitmap.h"
#include "collector.h"
-#include "paintown-engine/factory/heart_factory.h"
#include "paintown-engine/game/nameplacer.h"
#include "util/font_factory.h"
#include "font_render.h"
@@ -24,7 +23,6 @@
Collector::~Collector(){
ObjectFactory::destroy();
NamePlacer::destroy();
- HeartFactory::destroy();
FontFactory::destroy();
FontRender::destroy();
Graphics::Bitmap::cleanupTemporaryBitmaps();
Modified: trunk/src/paintown-engine/factory/object_factory.cpp
===================================================================
--- trunk/src/paintown-engine/factory/object_factory.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/factory/object_factory.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -8,7 +8,6 @@
#include "paintown-engine/object/network_player.h"
#include "paintown-engine/object/actor.h"
#include "paintown-engine/object/cat.h"
-#include "paintown-engine/object/heart.h"
#include "paintown-engine/object/item.h"
#include "paintown-engine/object/object.h"
#include "object_factory.h"
@@ -140,7 +139,7 @@
ret->setTriggers(block->getTriggers());
ret->setScriptObject(Script::Engine::getEngine()->createCharacter(ret));
- hearts.push_back(ret->getHeart());
+ // hearts.push_back(ret->getHeart());
return ret;
}
Modified: trunk/src/paintown-engine/factory/object_factory.h
===================================================================
--- trunk/src/paintown-engine/factory/object_factory.h 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/factory/object_factory.h 2012-12-29 20:34:48 UTC (rev 7704)
@@ -17,7 +17,6 @@
class NetworkPlayer;
}
-class Heart;
class BlockObject;
/* factory class for instantiating new objects from a BlockObject */
@@ -63,7 +62,7 @@
private:
std::map< std::string, Paintown::Object * > cached;
static ObjectFactory * factory;
- std::vector< Heart * > hearts;
+ // std::vector< Heart * > hearts;
int nextObjectId;
};
Modified: trunk/src/paintown-engine/game/adventure_world.cpp
===================================================================
--- trunk/src/paintown-engine/game/adventure_world.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/game/adventure_world.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -411,9 +411,12 @@
return scene->totalLength();
}
+/* called from the scripting engine */
void AdventureWorld::addEnemy(Paintown::Enemy * obj){
if (scene != NULL){
- scene->addEnemy(obj);
+ obj->created(*scene);
+ scene->addObject(obj);
+ // scene->addEnemy(obj);
} else {
/* scene should exist.. but just be safe */
delete obj;
Modified: trunk/src/paintown-engine/level/block.cpp
===================================================================
--- trunk/src/paintown-engine/level/block.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/level/block.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -95,14 +95,15 @@
return objects.empty();
}
+/*
vector<Heart *> Block::createObjects(int total_length, int min_x, int max_x, int min_z, int max_z, vector< Paintown::Object * > * list){
vector< Heart * > hearts;
- /* to silence compiler warnings */
- /*
+ / * to silence compiler warnings * /
+ / *
min_x = min_x;
max_x = max_x;
- */
+ * /
// cout<<"Total length = "<<total_length<<" Min_x = "<<min_x<<" Max_x = " << max_x << endl;
// cout<<"Current block has "<<objects.size()<<" total = "<<total_length<<" min = "<<min_x<<" max_x = "<<max_x<<endl;
@@ -115,7 +116,7 @@
continue;
}
- /* does this violate some OOP principle? oh wel */
+ / * does this violate some OOP principle? oh wel * /
if ( obj->getType() == ObjectFactory::EnemyType ){
Heart * h = ((Paintown::Enemy *)newobj)->getHeart();
hearts.push_back( h );
@@ -137,6 +138,7 @@
return hearts;
}
+*/
Block::~Block(){
}
Modified: trunk/src/paintown-engine/level/block.h
===================================================================
--- trunk/src/paintown-engine/level/block.h 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/level/block.h 2012-12-29 20:34:48 UTC (rev 7704)
@@ -6,7 +6,6 @@
class BlockObject;
class Token;
-class Heart;
namespace Paintown{
class Object;
@@ -60,7 +59,7 @@
bool empty();
- std::vector< Heart * > createObjects( int total_length, int min_x, int max_x, int min_z, int max_z, std::vector< Paintown::Object * > * list );
+ // std::vector< Heart * > createObjects( int total_length, int min_x, int max_x, int min_z, int max_z, std::vector< Paintown::Object * > * list );
virtual ~Block();
Modified: trunk/src/paintown-engine/level/scene.cpp
===================================================================
--- trunk/src/paintown-engine/level/scene.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/level/scene.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -4,7 +4,6 @@
#include "util/graphics/bitmap.h"
#include "block.h"
-#include "../object/heart.h"
#include "util/exceptions/load_exception.h"
#include "util/funcs.h"
#include "../object/object.h"
@@ -39,6 +38,7 @@
Scene::Scene(const Filesystem::AbsolutePath & filename, const Level::Cacher & cacher):
background(NULL),
+enemyCount(0),
block_length(0),
minimum_z(0),
maximum_z(0),
@@ -244,17 +244,6 @@
return block_length + current_block->getFinished();
}
-void Scene::clearHearts(){
- for (vector<Heart *>::iterator it = hearts.begin(); it != hearts.end(); ){
- Heart * h = *it;
- if (!h->getAlive()){
- // delete h;
- it = hearts.erase(it);
- } else
- it++;
- }
-}
-
void Scene::playIntro(){
try{
if (intro != Filesystem::RelativePath("")){
@@ -308,7 +297,7 @@
* player is past the boundary
*/
return (current_block->isContinuous() && passedBoundary(x)) ||
- (hearts.empty() && passedBoundary(x));
+ (numberOfEnemies() == 0 && passedBoundary(x));
}
/* put the enemy into a vector so that it can be added into the game objects
@@ -316,10 +305,23 @@
* the logic() method will corrupt the iterators.
*/
void Scene::addEnemy(Paintown::Enemy * const obj){
- hearts.push_back(obj->getHeart());
+ enemyCount += 1;
+ // obj->created(*this);
+ // added_objects.push_back(obj);
+}
+
+void Scene::addObject(Paintown::Object * obj){
added_objects.push_back(obj);
}
+void Scene::removeEnemy(Paintown::Enemy * const obj){
+ enemyCount -= 1;
+}
+
+int Scene::numberOfEnemies() const {
+ return enemyCount;
+}
+
void Scene::doTriggers(){
for (vector<Trigger*>::iterator it = triggers.begin(); it != triggers.end(); /**/){
Trigger * trigger = *it;
@@ -333,9 +335,7 @@
}
}
-vector<Heart*> Scene::createObjects(const vector<Util::ReferenceCount<BlockObject> > & blockObjects, int length, int minX, int minY, int minZ, int maxZ, vector<Paintown::Object*> * out){
- vector<Heart *> hearts;
-
+void Scene::createObjects(const vector<Util::ReferenceCount<BlockObject> > & blockObjects, int length, int minX, int minY, int minZ, int maxZ, vector<Paintown::Object*> * out){
for (vector<Util::ReferenceCount<BlockObject> >::const_iterator it = blockObjects.begin(); it != blockObjects.end(); it++){
Util::ReferenceCount<BlockObject> obj = *it;
@@ -344,11 +344,7 @@
continue;
}
- /* does this violate some OOP principle? oh well */
- if (obj->getType() == ObjectFactory::EnemyType){
- Heart * h = ((Paintown::Enemy *)newobj)->getHeart();
- hearts.push_back(h);
- }
+ newobj->created(*this);
// newobj->moveX( total_length );
newobj->moveRight(length);
@@ -363,11 +359,11 @@
}
- return hearts;
+ // return hearts;
}
void Scene::act(int min_x, int max_x, vector<Paintown::Object *> * objects){
- clearHearts();
+ // clearHearts();
if (canContinue(min_x)){
advanceBlocks(blockNumber + 1);
@@ -379,8 +375,8 @@
if (newBlock && objects != NULL){
newBlock = false;
// Global::debug(0) << "Creating new objects" << endl;
- vector<Heart *> new_hearts = createObjects(current_block->getObjects(), block_length, min_x, max_x, getMinimumZ(), getMaximumZ(), objects);
- hearts.insert(hearts.end(), new_hearts.begin(), new_hearts.end());
+ createObjects(current_block->getObjects(), block_length, min_x, max_x, getMinimumZ(), getMaximumZ(), objects);
+ // hearts.insert(hearts.end(), new_hearts.begin(), new_hearts.end());
objects->insert(objects->end(), added_objects.begin(), added_objects.end());
added_objects.clear();
}
@@ -460,7 +456,7 @@
atmosphere->drawScreen(work, x);
}
- if (hearts.empty() && !passedBoundary(x)){
+ if (numberOfEnemies() == 0 && !passedBoundary(x)){
if (arrow_blink > 5){
arrow->draw(work->getWidth() - ( arrow->getWidth() + 10 ), 50, *work);
}
Modified: trunk/src/paintown-engine/level/scene.h
===================================================================
--- trunk/src/paintown-engine/level/scene.h 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/level/scene.h 2012-12-29 20:34:48 UTC (rev 7704)
@@ -46,6 +46,8 @@
return description;
}
+ int numberOfEnemies() const;
+
inline int getMinimumZ() const {
return minimum_z;
}
@@ -62,11 +64,14 @@
return current_block;
}
- std::vector<Heart*> createObjects(const std::vector<Util::ReferenceCount<BlockObject> > & blockObjects, int length, int minX, int minY, int minZ, int maxZ, std::vector<Paintown::Object*> * out);
+ void createObjects(const std::vector<Util::ReferenceCount<BlockObject> > & blockObjects, int length, int minX, int minY, int minZ, int maxZ, std::vector<Paintown::Object*> * out);
void startMusic();
+ void addObject(Paintown::Object * obj);
+
void addEnemy(Paintown::Enemy * const obj);
+ void removeEnemy(Paintown::Enemy * const obj);
virtual void advanceBlocks( int n );
@@ -119,7 +124,7 @@
void calculateLength();
/* erase dead hearts */
- void clearHearts();
+ // void clearHearts();
/* try to execute the triggers */
void doTriggers();
@@ -137,9 +142,12 @@
std::deque<Util::ReferenceCount<Block> > level_blocks;
std::vector<Util::ReferenceCount<Block> > old_level_blocks;
- std::vector< Heart * > hearts;
+ // std::vector< Heart * > hearts;
std::vector<Paintown::Object*> added_objects;
+ /* current number of enemies */
+ int enemyCount;
+
int scene_length;
/* how far the scene has progressed */
Modified: trunk/src/paintown-engine/object/enemy.cpp
===================================================================
--- trunk/src/paintown-engine/object/enemy.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/object/enemy.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -9,11 +9,10 @@
#include "util/funcs.h"
#include "util/font.h"
#include "factory/font_render.h"
+#include "../level/scene.h"
#include "../game/nameplacer.h"
#include "alliance.h"
#include "util/debug.h"
-#include "heart.h"
-#include "../factory/heart_factory.h"
#include "util/file-system.h"
#include "object.h"
#include "../game/world.h"
@@ -57,8 +56,6 @@
}
void Enemy::constructSelf(){
- // heart = new Heart();
- heart = HeartFactory::createHeart();
want_path = false;
show_name_time = 0;
show_life = getHealth();
@@ -66,7 +63,6 @@
}
Enemy::~Enemy(){
- heart->setAlive( false );
}
Object * Enemy::copy(){
@@ -115,6 +111,11 @@
drawLifeBar( icon_x + x + 1, y + height + 1, work );
}
}
+
+void Enemy::died(const Util::ReferenceCount<Scene> & scene, std::vector< Object * > & objects){
+ scene->removeEnemy(this);
+ Character::died(scene, objects);
+}
static inline double min( double a, double b ){
return a < b ? a : b;
@@ -138,6 +139,10 @@
const double epsilon = 0.0001;
return fabs(a-b) < epsilon;
}
+
+void Enemy::created(Scene & scene){
+ scene.addEnemy(this);
+}
/* returns the closest object in the X plane */
const Object * Enemy::findClosest( const vector< Object * > & enemies ){
Modified: trunk/src/paintown-engine/object/enemy.h
===================================================================
--- trunk/src/paintown-engine/object/enemy.h 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/object/enemy.h 2012-12-29 20:34:48 UTC (rev 7704)
@@ -3,7 +3,6 @@
#include "character.h"
#include "util/file-system.h"
-#include "heart.h"
#include <string>
#include <vector>
@@ -30,16 +29,22 @@
virtual void drawFront( Graphics::Bitmap * work, int rel_x );
+ virtual void died(const Util::ReferenceCount<Scene> & scene, std::vector< Object * > & objects);
+
virtual void hurt( int x );
virtual inline void setMaxHealth( int h ){
Character::setMaxHealth( h );
show_life = h;
}
+
+ virtual void created(Scene & scene);
+ /*
virtual inline Heart * getHeart() const{
return heart;
}
+ */
virtual ~Enemy();
@@ -61,7 +66,7 @@
protected:
- Heart * heart;
+ // Heart * heart;
int want_x, want_z;
bool want_path;
Modified: trunk/src/paintown-engine/object/object.cpp
===================================================================
--- trunk/src/paintown-engine/object/object.cpp 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/object/object.cpp 2012-12-29 20:34:48 UTC (rev 7704)
@@ -140,9 +140,12 @@
void Object::thrown(){
}
-void Object::moveX( const int x ){
- moveX( (double)x );
+void Object::moveX(const int x){
+ moveX((double)x);
}
+
+void Object::created(Scene & scene){
+}
void Object::died(const Util::ReferenceCount<Scene> & scene, vector<Object *> & objects){
if (triggers.find(OnDeath) != triggers.end()){
Modified: trunk/src/paintown-engine/object/object.h
===================================================================
--- trunk/src/paintown-engine/object/object.h 2012-12-29 19:30:54 UTC (rev 7703)
+++ trunk/src/paintown-engine/object/object.h 2012-12-29 20:34:48 UTC (rev 7704)
@@ -271,6 +271,9 @@
virtualz = z;
}
+ /* Called when this object is instantiated */
+ virtual void created(Scene & scene);
+
/* this object died. this object can add arbitrary objects
* into 'objects'
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|