Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mission fix #583

Closed
wants to merge 14 commits into from
47 changes: 47 additions & 0 deletions data/scripts/missions/easymission.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function main()
showMessage("Welcome to another mission script")

ships = {}
count = 5
radius = 40

playerPos = position(playerShip())

for i = 1, count do
local type = "basicship"
local ship = createShip(type)
local angle = (i/count) * (2 * math.pi)

local position = vec3(playerPos.x - 10 + math.cos(angle) * radius, playerPos.y -10 + math.sin(angle) * radius, playerPos.z - 60)

setPosition(ship, position)

task = createFightTask(ship)
addFightTaskTarget(task, playerShip())

spawn(ship)
ships[i] = ship

onWorldObjectDestroyed(ship, "destroyed")
end

missionMessage("...and go!")
end

function missionTitle()
return "Leave the turtle be"
end

function missionCaption()
return "The turtle has down thou no harm"
end

function destroyed(ship)
count = count - 1
if count == 0 then
missionSucceed()
end
end



2 changes: 1 addition & 1 deletion data/scripts/missions/killemall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function main()
showMessage("Welcome to a mission script")

ships = {}
count = 6
count = 1
radius = 40

playerPos = position(playerShip())
Expand Down
20 changes: 18 additions & 2 deletions data/scripts/scenarios/demo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function startFightingMission(player)
onMissionSuccess(mission, "firework")
end

function startEasyFightingMission(player)
local mission = missionStart("easymission")
onMissionFailure(mission, "reset")
end

function reset(dummy)
missionStartBanner = createWorldObject("missionstart")
setShowOnHud(missionStartBanner, true)
Expand All @@ -37,8 +42,11 @@ function firstChallengeTaken(dummy)
end

function startSecondChallenge()
print("lol, mission over")

initDifficultSecondChallenge()
initEasySecondChallenge()
end

function initDifficultSecondChallenge()
dareyouBanner = createWorldObject("idareyou")
setShowOnHud(dareyouBanner, true)
setCanLockOn(dareyouBanner, false)
Expand All @@ -49,6 +57,14 @@ function startSecondChallenge()
onAABBEntered(playerShip(), vec3(-120, 30, -380), vec3(-80, 70, -340), "startFightingMission")
end

function initEasySecondChallenge()
tortess = createShip("startortress")
setPosition(tortess, vec3(200, 50, -300))
spawn(tortess)

onAABBEntered(playerShip(), vec3(180, 30, -320), vec3(220, 70, -280), "startEasyFightingMission")
end

function secondChallengeTaken(dummy)
createSingleShotTimer("firework", 3)
end
Expand Down
1 change: 0 additions & 1 deletion src/collision/collisiondetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ std::list<VoxelCollision>& CollisionDetector::checkCollisions() {
return m_collisions;
}


std::list<VoxelCollision>& CollisionDetector::checkCollisions(const std::unordered_set<WorldTreeGeode*>& possibleColliders) {
for (WorldTreeGeode* possibleCollider : possibleColliders) {
assert(possibleCollider->worldObject() != nullptr);
Expand Down
5 changes: 1 addition & 4 deletions src/events/aabbenteredpoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ bool AABBEnteredPoll::isDead() {
}

bool AABBEnteredPoll::poll() {
if (m_worldObject.valid()) {
return m_worldObject->bounds().aabb().intersects(m_aabb);
}
return false;
return m_worldObject.valid() ? m_worldObject->bounds().aabb().intersects(m_aabb) : false;
}

void AABBEnteredPoll::specialOnCallback() {
Expand Down
8 changes: 4 additions & 4 deletions src/events/missionstatepoll.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#include "missionstatepoll.h"


MissionStatePoll::MissionStatePoll(const Handle<Mission>& mission, MissionState state, const Callback& callback):
MissionStatePoll::MissionStatePoll(Mission& mission, MissionState state, const Callback& callback):
EventPoll(callback),
m_mission(mission),
m_mission(&mission),
m_state(state),
m_dead(false)
{
}

bool MissionStatePoll::isDead() {
return m_dead || !m_mission.valid();
return m_dead;
}

bool MissionStatePoll::poll() {
return m_mission.valid() && m_mission->state() == m_state;
return m_mission->state() == m_state;
}

void MissionStatePoll::specialOnCallback() {
Expand Down
6 changes: 4 additions & 2 deletions src/events/missionstatepoll.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <glow/ref_ptr.h>

#include "missions/mission.h"

#include "utils/handle/handle.h"
Expand All @@ -9,13 +11,13 @@

class MissionStatePoll : public EventPoll {
public:
MissionStatePoll(const Handle<Mission>& mission, MissionState state, const Callback& callback);
MissionStatePoll(Mission& mission, MissionState state, const Callback& callback);

virtual bool isDead() override;


protected:
Handle<Mission> m_mission;
const glow::ref_ptr<Mission> m_mission;
MissionState m_state;
bool m_dead;

Expand Down
13 changes: 11 additions & 2 deletions src/missions/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,27 @@ void Mission::succeed() {

m_state = MissionState::Succeeded;
m_script->onSuccess();
m_script->stop();

over();
}

void Mission::fail() {
assert(m_state == MissionState::Running);

m_state = MissionState::Failed;
m_script->onFailure();
m_script->stop();

over();
}

void Mission::update(float deltaSec) {

}

void Mission::over() {
m_script->stop();

assert(world());
world()->removeElement(this);
}

11 changes: 8 additions & 3 deletions src/missions/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include <memory>
#include <string>

#include "utils/handle/handleowner.h"

#include "scripting/scriptable.h"

#include "world/worldelement.h"


class MissionScript;
class World;

enum class MissionState {
Idle,
Expand All @@ -17,7 +18,7 @@ enum class MissionState {
Succeeded
};

class Mission : public Scriptable, public HandleOwner {
class Mission : public WorldElement {
public:
Mission(const std::string& path);
~Mission();
Expand All @@ -41,6 +42,10 @@ class Mission : public Scriptable, public HandleOwner {
void update(float deltaSec);


protected:
void over();


protected:
std::shared_ptr<MissionScript> m_script;
MissionState m_state;
Expand Down
40 changes: 0 additions & 40 deletions src/missions/missionsystem.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions src/missions/missionsystem.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/scenarios/missionscenario.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "missionscenario.h"

#include "missions/mission.h"
#include "missions/missionsystem.h"

#include "player.h"

Expand All @@ -18,7 +17,7 @@ MissionScenario::MissionScenario(GamePlay* gamePlay, const std::string& path):
BaseScenario(gamePlay),
m_mission(new Mission(path))
{

World::instance()->addElement(m_mission);
}

void MissionScenario::populateWorld() {
Expand All @@ -28,6 +27,7 @@ void MissionScenario::populateWorld() {
m_world->god().scheduleSpawn(playerShip);

World::instance()->player().setShip(playerShip);
World::instance()->missionSystem().addMission(m_mission);

m_mission->start();
}

2 changes: 1 addition & 1 deletion src/scenarios/missionscenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MissionScenario : public BaseScenario {


protected:
std::shared_ptr<Mission> m_mission;
Mission* m_mission;

virtual void populateWorld() override;
};
Expand Down
10 changes: 5 additions & 5 deletions src/scripting/bindings/externalmissionbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "events/eventpoller.h"
#include "events/missionstatepoll.h"

#include "missions/missionsystem.h"

#include "scripting/scriptengine.h"
#include "scripting/gameplayscript.h"
#include "scripting/elematelua/luawrapper.h"
Expand All @@ -29,8 +27,10 @@ void ExternalMissionBindings::bind() {
apikey ExternalMissionBindings::apiMissionStart(const std::string& name) {
std::string path = std::string("data/scripts/missions/") + name + ".lua";

auto mission = std::make_shared<Mission>(path);
World::instance()->missionSystem().addMission(mission);
auto mission = new Mission(path);
World::instance()->addElement(mission);

mission->start();

return mission->scriptKey();
}
Expand All @@ -49,7 +49,7 @@ apikey ExternalMissionBindings::createStatePoll(apikey missionKey, MissionState
return -1;
}

auto poll = std::make_shared<MissionStatePoll>(makeHandle(mission), state, createCallback(callback, missionKey));
auto poll = std::make_shared<MissionStatePoll>(*mission, state, createCallback(callback, missionKey));

World::instance()->eventPoller().addPoll(poll);
m_script.addLocal(poll);
Expand Down
15 changes: 10 additions & 5 deletions src/scripting/gameplayscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
GamePlayScript::GamePlayScript(ScriptEngine& scriptEngine):
m_scriptEngine(&scriptEngine)
{
addBindings(new CommonBindings(*this));
addBindings(new WorldObjectBindings(*this));
addBindings(new AiBindings(*this));
addBindings(new SquadBindings(*this));
addBindings(new ExternalMissionBindings(*this));
addGamePlayBindings();
}

GamePlayScript::~GamePlayScript() {
Expand Down Expand Up @@ -60,3 +56,12 @@ void GamePlayScript::addLocal(Scriptable* scriptable) {
scriptable->setScriptLocal(true);
m_locals.push_back(scriptable->scriptKey());
}

void GamePlayScript::addGamePlayBindings() {
addBindings(new CommonBindings(*this));
addBindings(new WorldObjectBindings(*this));
addBindings(new AiBindings(*this));
addBindings(new SquadBindings(*this));
addBindings(new ExternalMissionBindings(*this));
}

Loading