Colobot
programmable_impl.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
20 #pragma once
21 
22 #include "object/interface/interactive_object.h"
23 #include "object/interface/programmable_object.h"
24 #include "object/interface/trace_drawing_object.h"
25 
26 #include "math/vector.h"
27 
28 #include <sstream>
29 
30 class CObject;
31 
32 enum TraceOper
33 {
34  TO_STOP = 0, // stop
35  TO_ADVANCE = 1, // advance
36  TO_RECEDE = 2, // back
37  TO_TURN = 3, // rotate
38  TO_PEN = 4, // color change
39 };
40 
42 {
43  TraceOper oper = TO_STOP;
44  float param = 0.0f;
45 };
46 
48 {
49 public:
50  explicit CProgrammableObjectImpl(ObjectInterfaceTypes& types, CObject* object);
51  virtual ~CProgrammableObjectImpl();
52 
53  bool EventProcess(const Event& event);
54 
55  bool IsProgram() override;
56  void RunProgram(Program* program) override;
57  Program* GetCurrentProgram() override;
58  void StopProgram() override;
59 
60  bool ReadStack(FILE *file) override;
61  bool WriteStack(FILE *file) override;
62 
63  void TraceRecordStart() override;
64  void TraceRecordStop() override;
65  bool IsTraceRecord() override;
66 
67  void SetActivity(bool bMode) override;
68  bool GetActivity() override;
69 
70  void SetCmdLine(unsigned int rank, float value);
71  float GetCmdLine(unsigned int rank) override;
72  std::vector<float>& GetCmdLine();
73 
74 private:
76  void TraceRecordFrame();
78  bool TraceRecordOper(TraceOper oper, float param);
80  bool TraceRecordPut(std::stringstream& buffer, TraceOper oper, float param);
81 
82 private:
83  CObject* m_object;
84 
85 private:
86  bool m_activity;
87 
88  std::vector<float> m_cmdLine;
89 
90  Program* m_currentProgram;
91 
92  bool m_traceRecord;
93  TraceOper m_traceOper;
94  Math::Vector m_tracePos;
95  float m_traceAngle;
96  TraceColor m_traceColor;
97  int m_traceRecordIndex;
98  std::unique_ptr<TraceRecord[]> m_traceRecordBuffer;
99 };
bool ReadStack(FILE *file) override
Read current execution status from file.
Definition: programmable_impl.cpp:141
bool WriteStack(FILE *file) override
Save current execution status to file.
Definition: programmable_impl.cpp:169
Definition: programmable_impl.h:47
void TraceRecordStart() override
Start recording trace.
Definition: programmable_impl.cpp:200
Definition: programmable_impl.h:41
Interface for programmable objects.
Definition: programmable_object.h:36
bool IsTraceRecord() override
Returns true if trace recording is in progress.
Definition: programmable_impl.cpp:382
void RunProgram(Program *program) override
Start a program.
Definition: programmable_impl.cpp:105
void StopProgram() override
Stop currently running program.
Definition: programmable_impl.cpp:116
bool IsProgram() override
Check if a program is running.
Definition: programmable_impl.cpp:133
void SetActivity(bool bMode) override
Management of object "activity" (temporairly stops program execution, right now used only by Aliens i...
Definition: programmable_impl.cpp:94
float GetCmdLine(unsigned int rank) override
Returns program cmdline values for an object.
Definition: programmable_impl.cpp:405
Vector struct and related functions.
3D (3x1) vector
Definition: vector.h:53
void TraceRecordStop() override
Stop recording trace and generate CBot program.
Definition: programmable_impl.cpp:286
Event sent by system, interface or game.
Definition: event.h:709
Base class for all 3D in-game objects.
Definition: object.h:59
Definition: program_storage_object.h:31
Program * GetCurrentProgram() override
Returns the currently running program, or nullptr if no program is running.
Definition: programmable_impl.cpp:128