summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/errorstateplugins/random_ai/random_ai_plugin.h
blob: d3670bd02df2a340ac06c0e064b0ee186d61d9eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef RANDOM_AI_PLUGIN_H
#define RANDOM_AI_PLUGIN_H

#include <QObject>
#include <QState>

#include <errorstate/plugin.h>

class SelectActionState: public QState
{
    Q_OBJECT
public:
    SelectActionState(QState *parent = 0) : QState(parent)
    {
    }

signals:
    void fireSelected();
    void moveForwardsSelected();
    void moveBackwardsSelected();
    void turnSelected();
    
protected:
    void onEntry()
    {
        int rand = qrand() % 4;
        switch (rand) {
        case 0: emit fireSelected(); break;
        case 1: emit moveForwardsSelected(); break;
        case 2: emit moveBackwardsSelected(); break;
        case 3: emit turnSelected(); break;
        };
    }
};

class RandomDistanceState: public QState
{
    Q_OBJECT
public:
    RandomDistanceState(QState *parent = 0) : QState(parent)
    {
    }

signals:
    void distanceComputed(qreal distance);

protected:
    void onEntry() 
    {
        emit distanceComputed(qreal(qrand() % 180));
    }
};

class RandomAiPlugin: public QObject, public Plugin
{
    Q_OBJECT
    Q_INTERFACES(Plugin)
public:
    virtual QState *create(QState *parentState, QObject *tank);
};

#endif // RANDOM_AI_PLUGIN_H