Colobot
programmable_impl.h
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, 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/programmable_object.h"
23 
24 #include "math/vector.h"
25 
26 #include "object/interface/interactive_object.h"
27 #include "object/interface/trace_drawing_object.h"
28 
29 #include <sstream>
30 
31 class CObject;
32 
33 enum TraceOper
34 {
35  TO_STOP = 0, // stop
36  TO_ADVANCE = 1, // advance
37  TO_RECEDE = 2, // back
38  TO_TURN = 3, // rotate
39  TO_PEN = 4, // color change
40 };
41 
43 {
44  TraceOper oper = TO_STOP;
45  float param = 0.0f;
46 };
47 
49 {
50 public:
51  explicit CProgrammableObjectImpl(ObjectInterfaceTypes& types, CObject* object);
52  virtual ~CProgrammableObjectImpl();
53 
54  bool EventProcess(const Event& event);
55 
56  bool IsProgram() override;
57  void RunProgram(Program* program) override;
58  Program* GetCurrentProgram() override;
59  void StopProgram() override;
60 
61  bool ReadStack(FILE *file) override;
62  bool WriteStack(FILE *file) override;
63 
64  void TraceRecordStart() override;
65  void TraceRecordStop() override;
66  bool IsTraceRecord() override;
67 
68  void SetActivity(bool activity) override;
69  bool GetActivity() override;
70 
71  void SetCmdLine(unsigned int rank, float value);
72  float GetCmdLine(unsigned int rank) override;
73  std::vector<float>& GetCmdLine();
74 
75 private:
77  void TraceRecordFrame();
79  bool TraceRecordOper(TraceOper oper, float param);
81  bool TraceRecordPut(std::stringstream& buffer, TraceOper oper, float param);
82 
83 private:
84  CObject* m_object;
85 
86 private:
87  bool m_activity;
88 
89  std::vector<float> m_cmdLine;
90 
91  Program* m_currentProgram;
92 
93  bool m_traceRecord;
94  TraceOper m_traceOper;
95  Math::Vector m_tracePos;
96  float m_traceAngle;
97  TraceColor m_traceColor;
98  int m_traceRecordIndex;
99  std::unique_ptr<TraceRecord[]> m_traceRecordBuffer;
100 };
Definition: programmable_impl.h:48
Definition: programmable_impl.h:42
Interface for programmable objects.
Definition: programmable_object.h:36
Vector struct and related functions.
3D (3x1) vector
Definition: vector.h:53
Event sent by system, interface or game.
Definition: event.h:735
Base class for all 3D in-game objects.
Definition: object.h:63
Definition: program_storage_object.h:31