Skip to content

Commit

Permalink
Merge branch 'feature/smart-ptr'
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Oct 1, 2014
2 parents a52595a + 8d31206 commit 26316f3
Show file tree
Hide file tree
Showing 71 changed files with 498 additions and 627 deletions.
2 changes: 1 addition & 1 deletion src/badguy/bomb.cpp
Expand Up @@ -90,7 +90,7 @@ Bomb::explode()

if(is_valid()) {
remove_me();
Explosion* explosion = new Explosion(get_bbox().get_middle());
auto explosion = std::make_shared<Explosion>(get_bbox().get_middle());
Sector::current()->add_object(explosion);
}

Expand Down
2 changes: 1 addition & 1 deletion src/badguy/darttrap.cpp
Expand Up @@ -97,7 +97,7 @@ DartTrap::fire()
py += MUZZLE_Y;

SoundManager::current()->play("sounds/dartfire.wav", get_pos());
Sector::current()->add_object(new Dart(Vector(px, py), dir, this));
Sector::current()->add_object(std::make_shared<Dart>(Vector(px, py), dir, this));
state = IDLE;
sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
}
Expand Down
35 changes: 17 additions & 18 deletions src/badguy/dispenser.cpp
Expand Up @@ -205,8 +205,7 @@ Dispenser::launch_badguy()
}

try {
GameObject *game_object;
BadGuy *bad_guy;
GameObjectPtr game_object;
Vector spawnpoint;
Rectf object_bbox;

Expand All @@ -215,33 +214,33 @@ Dispenser::launch_badguy()
if (game_object == NULL)
throw std::runtime_error("Creating " + badguy + " object failed.");

bad_guy = dynamic_cast<BadGuy *> (game_object);
if (bad_guy == NULL)
throw std::runtime_error(badguy + " is not a badguy.");
BadGuy& bad_guy = dynamic_cast<BadGuy&>(*game_object);

object_bbox = bad_guy->get_bbox ();
object_bbox = bad_guy.get_bbox();

if (type == "dropper") {
spawnpoint = get_anchor_pos (get_bbox (), ANCHOR_BOTTOM);
spawnpoint.x -= 0.5 * object_bbox.get_width ();
if (type == "dropper")
{
spawnpoint = get_anchor_pos (get_bbox(), ANCHOR_BOTTOM);
spawnpoint.x -= 0.5 * object_bbox.get_width();
}
else if ((type == "cannon") || (type == "rocketlauncher")) {
spawnpoint = get_pos (); /* top-left corner of the cannon */
else if ((type == "cannon") || (type == "rocketlauncher"))
{
spawnpoint = get_pos(); /* top-left corner of the cannon */
if (launchdir == LEFT)
spawnpoint.x -= object_bbox.get_width () + 1;
spawnpoint.x -= object_bbox.get_width() + 1;
else
spawnpoint.x += get_bbox ().get_width () + 1;
spawnpoint.x += get_bbox().get_width() + 1;
}

/* Now we set the real spawn position */
bad_guy->set_pos (spawnpoint);
bad_guy.set_pos(spawnpoint);

/* We don't want to count dispensed badguys in level stats */
if(bad_guy->countMe)
bad_guy->countMe = false;
if(bad_guy.countMe)
bad_guy.countMe = false;

Sector::current()->add_object(bad_guy);
} catch(std::exception& e) {
Sector::current()->add_object(game_object);
} catch(const std::exception& e) {
log_warning << "Error dispensing badguy: " << e.what() << std::endl;
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/badguy/flame.cpp
Expand Up @@ -110,7 +110,10 @@ Flame::freeze()
{
SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
sprite->set_action("fade", 1);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", bbox.get_middle(), ANCHOR_MIDDLE, Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
"default",
bbox.get_middle(), ANCHOR_MIDDLE,
Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2));
set_group(COLGROUP_DISABLED);

// start dead-script
Expand Down
5 changes: 4 additions & 1 deletion src/badguy/flyingsnowball.cpp
Expand Up @@ -113,7 +113,10 @@ FlyingSnowBall::active_update(float elapsed_time)
Vector ppos = bbox.get_middle();
Vector pspeed = Vector(gameRandom.randf(-10, 10), 150);
Vector paccel = Vector(0,0);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
"default",
ppos, ANCHOR_MIDDLE, pspeed, paccel,
LAYER_OBJECTS-1));
puff_timer.start(gameRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));

normal_propeller_speed = gameRandom.randf(0.95, 1.05);
Expand Down
29 changes: 15 additions & 14 deletions src/badguy/ghosttree.cpp
Expand Up @@ -70,10 +70,9 @@ GhostTree::die()
sprite->set_action("dying", 1);
glow_sprite->set_action("dying", 1);

std::vector<TreeWillOWisp*>::iterator iter;
for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
TreeWillOWisp *willo = *iter;
willo->vanish();
for(auto iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
TreeWillOWisp& willo = **iter;
willo.vanish();
}
run_dead_script();
}
Expand Down Expand Up @@ -113,11 +112,10 @@ GhostTree::active_update(float elapsed_time)
if(suck_timer.check()) {
Color col = glow_sprite->get_color();
SoundManager::current()->play("sounds/tree_suck.ogg", get_pos());
std::vector<TreeWillOWisp*>::iterator iter;
for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
TreeWillOWisp *willo = *iter;
if(willo->get_color() == col) {
willo->start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD)));
for(auto iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
TreeWillOWisp& willo = **iter;
if(willo.get_color() == col) {
willo.start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), gameRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD)));
}
}
mystate = STATE_SUCKING;
Expand All @@ -126,8 +124,7 @@ GhostTree::active_update(float elapsed_time)
if(willowisp_timer.check()) {
if(willowisps.size() < WILLOWISP_COUNT) {
Vector pos = Vector(bbox.get_width() / 2, bbox.get_height() / 2 + willo_spawn_y + WILLOWISP_TOP_OFFSET);
TreeWillOWisp *willowisp
= new TreeWillOWisp(this, pos, 200 + willo_radius, willo_speed);
auto willowisp = std::make_shared<TreeWillOWisp>(this, pos, 200 + willo_radius, willo_speed);

Sector::current()->add_object(willowisp);
willowisps.push_back(willowisp);
Expand Down Expand Up @@ -166,7 +163,7 @@ GhostTree::active_update(float elapsed_time)
/* TODO indicate root with an animation */
Player* player = get_nearest_player();
if (player) {
Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()+ROOT_TOP_OFFSET));
auto root = std::make_shared<Root>(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()+ROOT_TOP_OFFSET));
Sector::current()->add_object(root);
}
}
Expand Down Expand Up @@ -215,7 +212,11 @@ GhostTree::willowisp_died(TreeWillOWisp *willowisp)
if ((mystate == STATE_SUCKING) && (willowisp->was_sucked)) {
mystate = STATE_IDLE;
}
willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp));
willowisps.erase(std::find_if(willowisps.begin(), willowisps.end(),
[willowisp](const std::shared_ptr<TreeWillOWisp>& lhs)
{
return lhs.get() == willowisp;
}));
}

void
Expand Down Expand Up @@ -266,7 +267,7 @@ GhostTree::collision(GameObject& other, const CollisionHit& ) {

void
GhostTree::spawn_lantern() {
Lantern* lantern = new Lantern(get_bbox().get_middle() + SUCK_TARGET_OFFSET);
auto lantern = std::make_shared<Lantern>(get_bbox().get_middle() + SUCK_TARGET_OFFSET);
Sector::current()->add_object(lantern);
}

Expand Down
2 changes: 1 addition & 1 deletion src/badguy/ghosttree.hpp
Expand Up @@ -62,7 +62,7 @@ class GhostTree : public BadGuy

Lantern* suck_lantern; /**< Lantern that is currently being sucked in */

std::vector<TreeWillOWisp*> willowisps;
std::vector<std::shared_ptr<TreeWillOWisp> > willowisps;

bool is_color_deadly(Color color) const;
void spawn_lantern();
Expand Down
4 changes: 2 additions & 2 deletions src/badguy/goldbomb.cpp
Expand Up @@ -160,8 +160,8 @@ GoldBomb::kill_fall()

if(is_valid()) {
remove_me();
Sector::current()->add_object(new Explosion(get_bbox().get_middle()));
Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40)));
Sector::current()->add_object(std::make_shared<Explosion>(get_bbox().get_middle()));
Sector::current()->add_object(std::make_shared<CoinExplode>(get_pos() + Vector (0, -40)));
}

run_dead_script();
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/haywire.cpp
Expand Up @@ -173,7 +173,7 @@ Haywire::kill_fall()
}
if(is_valid()) {
remove_me();
Explosion* explosion = new Explosion(get_bbox().get_middle());
auto explosion = std::make_shared<Explosion>(get_bbox().get_middle());
Sector::current()->add_object(explosion);
}

Expand Down
6 changes: 5 additions & 1 deletion src/badguy/iceflame.cpp
Expand Up @@ -88,7 +88,11 @@ Iceflame::ignite()
{
SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
sprite->set_action("fade", 1);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", bbox.get_middle(), ANCHOR_MIDDLE, Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
"default",
bbox.get_middle(), ANCHOR_MIDDLE,
Vector(0, -150), Vector(0,0),
LAYER_BACKGROUNDTILES+2));
set_group(COLGROUP_DISABLED);

// start dead-script
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/igel.cpp
Expand Up @@ -79,7 +79,7 @@ Igel::active_update(float elapsed_time)
// check if we see a fire bullet
Sector* sector = Sector::current();
for (Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) {
Bullet* bullet = dynamic_cast<Bullet*>(*i);
Bullet* bullet = dynamic_cast<Bullet*>(i->get());
if (!bullet) continue;
if (bullet->get_type() != FIRE_BONUS) continue;
if (can_see(*bullet)) wants_to_flee = true;
Expand Down
5 changes: 4 additions & 1 deletion src/badguy/livefire.cpp
Expand Up @@ -136,7 +136,10 @@ LiveFire::kill_fall()
Vector ppos = bbox.get_middle();
Vector pspeed = Vector(0, -150);
Vector paccel = Vector(0,0);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
"default", ppos, ANCHOR_MIDDLE,
pspeed, paccel,
LAYER_BACKGROUNDTILES+2));
// extinguish the flame
sprite->set_action(dir == LEFT ? "extinguish-left" : "extinguish-right", 1);
physic.set_velocity_y(0);
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/mole.cpp
Expand Up @@ -96,7 +96,7 @@ Mole::throw_rock()
float vy = -sin(angle) * THROW_VELOCITY;

SoundManager::current()->play("sounds/dartfire.wav", get_pos());
Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this));
Sector::current()->add_object(std::make_shared<MoleRock>(Vector(px, py), Vector(vx, vy), this));
}

void
Expand Down
4 changes: 2 additions & 2 deletions src/badguy/mrbomb.cpp
Expand Up @@ -86,7 +86,7 @@ MrBomb::collision_squished(GameObject& object)
}
if(is_valid()) {
remove_me();
Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name ));
Sector::current()->add_object(std::make_shared<Bomb>(get_pos(), dir, sprite_name));
}
kill_squished(object);
return true;
Expand All @@ -105,7 +105,7 @@ MrBomb::kill_fall()
{
if(is_valid()) {
remove_me();
Explosion* explosion = new Explosion(get_bbox().get_middle());
auto explosion = std::make_shared<Explosion>(get_bbox().get_middle());
Sector::current()->add_object(explosion);
}

Expand Down
12 changes: 8 additions & 4 deletions src/badguy/mrtree.cpp
Expand Up @@ -54,7 +54,7 @@ MrTree::collision_squished(GameObject& object)
Vector stumpy_pos = get_pos();
stumpy_pos.x += 20;
stumpy_pos.y += 25;
Stumpy* stumpy = new Stumpy(stumpy_pos, dir);
auto stumpy = std::make_shared<Stumpy>(stumpy_pos, dir);
remove_me();
Sector::current()->add_object(stumpy);

Expand All @@ -73,14 +73,18 @@ MrTree::collision_squished(GameObject& object)
float vy = -cos(angle)*velocity;
Vector pspeed = Vector(vx, vy);
Vector paccel = Vector(0, 100);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/leaf.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/leaf.sprite",
"default",
ppos, ANCHOR_MIDDLE,
pspeed, paccel,
LAYER_OBJECTS-1));
}

// spawn PoisonIvy
Vector leaf1_pos(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
Rectf leaf1_bbox(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
auto leaf1 = std::make_shared<PoisonIvy>(leaf1_bbox.p1, LEFT);
leaf1->countMe = false;
Sector::current()->add_object(leaf1);
}
Expand All @@ -89,7 +93,7 @@ MrTree::collision_squished(GameObject& object)
Vector leaf2_pos(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
Rectf leaf2_bbox(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
auto leaf2 = std::make_shared<PoisonIvy>(leaf2_bbox.p1, RIGHT);
leaf2->countMe = false;
Sector::current()->add_object(leaf2);
}
Expand Down
29 changes: 15 additions & 14 deletions src/badguy/owl.cpp
Expand Up @@ -50,27 +50,28 @@ Owl::Owl(const Vector& pos, Direction d) :
void
Owl::initialize()
{
GameObject *game_object;

physic.set_velocity_x(dir == LEFT ? -FLYING_SPEED : FLYING_SPEED);
physic.enable_gravity(false);
sprite->set_action(dir == LEFT ? "left" : "right");

game_object = ObjectFactory::instance().create(carried_obj_name, get_pos(), dir);
if (game_object == NULL) {
auto game_object = ObjectFactory::instance().create(carried_obj_name, get_pos(), dir);
if (game_object == NULL)
{
log_fatal << "Creating \"" << carried_obj_name << "\" object failed." << std::endl;
return;
}

carried_object = dynamic_cast<Portable *> (game_object);
if (carried_object == NULL) {
log_warning << "Object is not portable: " << carried_obj_name << std::endl;
delete game_object;
return;
else
{
carried_object = dynamic_cast<Portable*>(game_object.get());
if (carried_object == NULL)
{
log_warning << "Object is not portable: " << carried_obj_name << std::endl;
}
else
{
Sector::current()->add_object(game_object);
}
}

Sector::current ()->add_object (game_object);
} /* void initialize */
}

bool
Owl::is_above_player (void)
Expand Down
6 changes: 5 additions & 1 deletion src/badguy/poisonivy.cpp
Expand Up @@ -54,7 +54,11 @@ PoisonIvy::collision_squished(GameObject& object)
float vy = -cos(angle)*velocity;
Vector pspeed = Vector(vx, vy);
Vector paccel = Vector(0, 100);
Sector::current()->add_object(new SpriteParticle("images/objects/particles/poisonivy.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/poisonivy.sprite",
"default",
ppos, ANCHOR_MIDDLE,
pspeed, paccel,
LAYER_OBJECTS-1));
}
kill_squished(object);
return true;
Expand Down
16 changes: 8 additions & 8 deletions src/badguy/short_fuse.cpp
Expand Up @@ -48,19 +48,19 @@ ShortFuse::ShortFuse(const Reader& reader) :
}

void
ShortFuse::explode (void)
ShortFuse::explode()
{
if (!is_valid ())
if (!is_valid())
return;

Explosion *explosion = new Explosion (get_bbox ().get_middle ());
auto explosion = std::make_shared<Explosion>(get_bbox ().get_middle());

explosion->hurts (false);
explosion->pushes (true);
Sector::current()->add_object (explosion);
explosion->hurts(false);
explosion->pushes(true);
Sector::current()->add_object(explosion);

run_dead_script ();
remove_me ();
run_dead_script();
remove_me();
}

bool
Expand Down

0 comments on commit 26316f3

Please sign in to comment.