Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 27, 2017, 4:38:50 PM (6 years ago)
Author:
kohlia
Message:

Pawn killing works too now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h

    r11583 r11606  
    1515class WorldEntity;
    1616
     17/**
     18 * @brief API for ScriptableController's lua-scripts
     19 *
     20 * Defines the interface that lua can use in the scripts to communicate with orxonox.
     21 *
     22 * \sa ScriptableController
     23 */
    1724class ScriptableControllerAPI
    1825{
    1926public:
     27    /**
     28     * @brief Constructs the API with the given lua state
     29     * @param lua The lua state
     30     * @param controller The parent controller
     31     *
     32     * This will not run any scripts, it'll just make the API visible to lua.
     33     */
    2034    ScriptableControllerAPI(lua_State *lua, ScriptableController *controller);
     35
     36    /**
     37     * @brief Destructs the API and closes the lua state.
     38     */
    2139    ~ScriptableControllerAPI();
    2240
    23     void testOutput(std::function<void(std::string)> callback);
    24 
     41    // --- API ----------------------------------
     42
     43    /**
     44     * @brief Print a message
     45     * @param msg The message
     46     *
     47     * Use this function instead of printing from lua directly, because that will mess up the
     48     * output as it is not synchronized.
     49     */
    2550    void orxPrint(std::string msg);
     51
     52    /**
     53     * @brief Register a function that will be called after a timeout
     54     * @param callback The function to call after the timeout expired
     55     * @param timeout The timeout in seconds
     56     */
    2657    void registerAfterTimeout(std::function<void (void)> callback, double timeout);
    2758
     59    /**
     60     * @brief Register a function that will be called when two object are close to eachother
     61     * @param callback The function to call when the objects are close enough
     62     * @param id1 The first object
     63     * @param id2 The second object
     64     * @param distance If the distance between the two objects is smaller than this value,
     65     * the function is called
     66     *
     67     * Note: Distances are only checked every 0.5s!
     68     */
    2869    void registerAtNearObject(std::function<void(std::string, std::string)> callback, std::string id1, std::string id2, double distance);
     70
     71    /**
     72     * @brief Register a function that will be called when an object is close to a certain point
     73     * @param callback The function to call when the object is close enough
     74     * @param id The object
     75     * @param x X-coordinate of the point
     76     * @param y Y-coordinate of the point
     77     * @param z Z-coordinate of the point
     78     * @param distance If the distance between the object and the point is smaller than this value, the
     79     * function is called.
     80     *
     81     * Note: Distances are only checked every 0.5s!
     82     */
    2983    void registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance);
    30     void registerAtAreaEnter(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
    31     void registerAtAreaLeave(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
    32 
    33     void registerAtObjectDestroyed(std::function<void (std::string)> callback, std::string obj);
    34     void registerAtPickup(std::function<void (int)> callback, int pickup_id);
    35 
    36     void destroyObject(std::string obj);
    37     void removeObject(std::string obj);
    38     void setObjectPosition(std::string obj, double x, double y, double z);
     84
     85    /**
     86     * @brief Register a function that will be called when an object enters a cubic area
     87     * @param callback The function to call when the object entered the area
     88     * @param id The object
     89     * @param x X-coordinate of the top-left corner
     90     * @param y Y-coordinate of the top-left corner
     91     * @param z Z-coordinate of the top-left corner
     92     * @param dx Size in X-direction of the cube
     93     * @param dy Size in Y-direction of the cube
     94     * @param dz Size in Z-direction of the cube
     95     *
     96     * Note: Distances are only checked every 0.5s!
     97     */
     98    void registerAtAreaEnter(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz);
     99
     100    /**
     101     * @brief Register a function that will be called when an object leaves a cubic area
     102     * @param callback The function to call when the object left the area
     103     * @param id The object
     104     * @param x X-coordinate of the top-left corner
     105     * @param y Y-coordinate of the top-left corner
     106     * @param z Z-coordinate of the top-left corner
     107     * @param dx Size in X-direction of the cube
     108     * @param dy Size in Y-direction of the cube
     109     * @param dz Size in Z-direction of the cube
     110     *
     111     * Note: Distances are only checked every 0.5s!
     112     */
     113    void registerAtAreaLeave(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz);
     114
     115    /**
     116     * @brief Register a function that will be called when a Pawn is killed
     117     * @param callback The function to call as soon as the Pawn is dead
     118     * @param id The Pawn
     119     *
     120     * Note: Once a Pawn is dead, the callback is removed, even if the pawn got magically revived.
     121     */
     122    void registerAtPawnKilled(std::function<void (std::string)> callback, std::string id);
     123
     124    /**
     125     * @brief Register a function that will be called when a Pawn is hit
     126     * @param callback The function to call as soon as the Pawn is hit
     127     * @param id The Pawn
     128     *
     129     * Note: Once a Pawn is dead, the all hit-callbacks are removed, even if the pawn got magically revived.
     130     */
     131    void registerAtPawnHit(std::function<void (std::string, std::string, double, double)> callback, std::string id);
     132
     133    /**
     134     * @brief Kill a pawn
     135     * @param id The pawn to kill
     136     *
     137     * Note: It might up to 0.5s until the pawn is actually killed.
     138     */
     139    void killPawn(std::string id);
     140
     141    // ------------------------------------------
     142
     143    /**
     144     * @brief Called by ScriptableController when a pawn is killed
     145     * @param id The dead pawn
     146     *
     147     * Calls the lua callbacks associated with this event.
     148     */
     149    void pawnKilled(std::string id);
     150
     151    /**
     152     * @brief Called by ScriptableController when a Pawn is hit
     153     * @param target_id The hit Pawn
     154     * @param source_id The shooting Pawn
     155     * @param new_health The new health of the hit Pawn
     156     * @param new_shield The new shield health of the hit Pawn
     157     */
     158    void pawnHit(std::string target_id, std::string source_id, double new_health, double new_shield);
    39159
    40160private:
     161    /**
     162     * @brief Groups everything together that is needed to handle a near-object event
     163     */
    41164    struct NearObjectHandler
    42165    {
     
    51174    };
    52175
     176    /**
     177     * @brief Groups everything together that is needed to handle a near-poinb event
     178     */
    53179    struct NearPointHandler
    54180    {
     
    64190    };
    65191
     192    /**
     193     * @brief Groups everything together that is needed to handle an area enter/leave event
     194     */
    66195    struct AreaHandler
    67196    {
     
    83212    std::list<NearPointHandler> nearPointHandlers_;
    84213    std::list<AreaHandler> areaHandlers_;
    85     Timer areaCheckTimer;
    86 
    87     void checkAreas(void);
     214    std::list<std::string> pawnsToKill_;
     215    std::map<std::string, std::list<std::function<void (std::string)> > > pawnDestroyedHandlers_;
     216    std::map<std::string, std::list<std::function<void (std::string, std::string, double, double)> > > pawnHitHandlers_;
     217    Timer periodicTimer;
     218    static const double periodic_interval;
     219
     220    /**
     221     * @brief Called every 0.5s
     222     *
     223     * This handles things that have to be checked periodically (like area events) and
     224     * things that are done by lua that have to synchronize with the main thread (like
     225     * killing a pawn). Doing this in every tick would be an overkill.
     226     */
     227    void periodic(void);
    88228};
    89229
Note: See TracChangeset for help on using the changeset viewer.