mission.php

From Galactineers
Jump to navigationJump to search

The mission.php file contains the main mission script of the mission. It can define event handlers and use commands and properties to control the mission process.

File Defition

The basic mission.php file contents look like this:

<?php
    class Mission {   
        public function OnMissionInitialize() {
            global $MissionContext;

            /* implementation of the MissionInitialize event handler */
        }

        /* other event handlers */
    }
?>

It must contain a class called Mission. The mission instance will create one instance of your Mission class and call its event handler functions at certain events. The Mission class may have event handler functions according to the $MissionContext events reference. Via the global variable $MissionContext, you can access properties of the current mission state. All available properties can be found here: $MissionContext properties reference. The $MissionContext also provides the commands to control the mission process. All available commands can be found here: $MissionContext commands reference. You can define any sort of variable at function scope, or even at class scope.

Example

The following is a (shortened) version of the First Blood mission script:

<?php
    class Mission {   
        
        public function OnMissionInitialize() {
            global $MissionContext;
            
            $MissionContext->AddShip('PirateProbe', array(12, -10), 0, 'X');
            $MissionContext->AddShip('PirateProbe', array(5, 7), 0, 'X');           

            $MissionContext->SetMissionObjective('killEnemies',array('EN' => 'Defeat all enemies.', 
                                                                     'DE' => 'Besiegen Sie alle Feinde.'));
            $MissionContext->SetTimer('missionTimer', 600, true, array('EN' => 'Time remaining', 
                                                                       'DE' => 'Verbleibende Zeit'));
            $MissionContext->SetTimer('5minTimer', 300, false, null);
            $MissionContext->SetCounter('enemyCounter', $MissionContext->EnemiesShipList->Count, array('EN' => 'Remaining enemies', 
                                                                                                       'DE' => 'Verbleibende Feinde'));
        }
        
        public function OnTimerExpired($timerId) {
            global $MissionContext;
            
            if ($timerId == 'missionTimer') {
                $MissionContext->SetMissionFailed(array('EN' => 'Time is up', 
                                                        'DE' => 'Die Zeit ist abgelaufen'));
            } else if ($timerId == '5minTimer') {
                $MissionContext->SendSystemMessage(array('EN' => '5:00 minutes left...', 
                                                         'DE' => 'Noch 5:00 Minuten verbleiben...'));
            }
        }
        
        public function OnShipKilled($shipId) {
            global $MissionContext;
            
            if ($MissionContext->PlayersShipList->Count == 0) {
                $MissionContext->SetMissionFailed(array('EN' => 'All your ships have been defeated', 
                                                        'DE' => 'Alle eure Schiffe wurden besiegt'));
            } else {
                if ($MissionContext->EnemiesShipList->Count == 0) {
                    $MissionContext->SetMissionSuccessful(array('EN' => 'All enemy ships have been defeated', 
                                                                'DE' => 'Alle feindlichen Schiffe wurden besiegt'));
                } else {
                    $MissionContext->SetCounter('enemyCounter', $MissionContext->EnemiesShipList->Count, array('EN' => 'Remaining enemies', 
                                                                                                               'DE' => 'Verbleibende Feinde'));
                }
            }                
        }
    }
?>