[1341] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "CommandEvaluation.h" |
---|
| 30 | #include "ConsoleCommand.h" |
---|
| 31 | |
---|
| 32 | namespace orxonox |
---|
| 33 | { |
---|
| 34 | CommandEvaluation::CommandEvaluation() |
---|
| 35 | { |
---|
| 36 | this->processedCommand_ = ""; |
---|
| 37 | this->additionalParameter_ = ""; |
---|
| 38 | |
---|
| 39 | this->functionclass_ = 0; |
---|
| 40 | this->configvalueclass_ = 0; |
---|
| 41 | this->shortcut_ = 0; |
---|
| 42 | this->function_ = 0; |
---|
| 43 | this->configvalue_ = 0; |
---|
| 44 | this->key_ = 0; |
---|
| 45 | |
---|
| 46 | this->errorMessage_ = ""; |
---|
| 47 | this->state_ = CS_Uninitialized; |
---|
| 48 | |
---|
| 49 | this->bEvaluatedParams_ = false; |
---|
| 50 | this->evaluatedExecutor_ = 0; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | KeybindMode CommandEvaluation::getKeybindMode() |
---|
| 54 | { |
---|
| 55 | if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) |
---|
| 56 | { |
---|
| 57 | // if (this->shortcut_ != 0) |
---|
| 58 | // return this->shortcut_->getKeybindMode(); |
---|
| 59 | } |
---|
| 60 | else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) |
---|
| 61 | { |
---|
| 62 | // if (this->function_ != 0) |
---|
| 63 | // return this->function_->getKeybindMode(); |
---|
| 64 | } |
---|
| 65 | else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished) |
---|
| 66 | { |
---|
| 67 | // return KeybindMode::onPress; |
---|
| 68 | } |
---|
| 69 | else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished) |
---|
| 70 | { |
---|
| 71 | // return KeybindMode::onPress; |
---|
| 72 | } |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | // return KeybindMode::onPress; |
---|
| 76 | } |
---|
| 77 | // FIXME: Had to insert a return statement |
---|
| 78 | return (KeybindMode)0; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | bool CommandEvaluation::isValid() const |
---|
| 82 | { |
---|
| 83 | if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) |
---|
| 84 | { |
---|
| 85 | return this->shortcut_; |
---|
| 86 | } |
---|
| 87 | else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) |
---|
| 88 | { |
---|
| 89 | return (this->functionclass_ && this->function_); |
---|
| 90 | } |
---|
| 91 | else if (this->state_ == CS_ConfigValueType || this->state_ == CS_ConfigValueFinished) |
---|
| 92 | { |
---|
| 93 | return (this->configvalueclass_ && this->configvalue_); |
---|
| 94 | } |
---|
| 95 | else if (this->state_ == CS_KeybindCommand || this->state_ == CS_KeybindFinished) |
---|
| 96 | { |
---|
| 97 | return this->key_; |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | return false; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void CommandEvaluation::evaluateParams() |
---|
| 106 | { |
---|
| 107 | this->bEvaluatedParams_ = false; |
---|
| 108 | this->evaluatedExecutor_ = 0; |
---|
| 109 | |
---|
| 110 | for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++) |
---|
| 111 | this->param_[i] = MT_null; |
---|
| 112 | |
---|
| 113 | if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) |
---|
| 114 | { |
---|
| 115 | if (this->shortcut_) |
---|
| 116 | { |
---|
| 117 | if (this->tokens_.size() <= 1) |
---|
| 118 | { |
---|
| 119 | if (this->shortcut_->evaluate(this->getAdditionalParameter(), this->param_, " ")) |
---|
| 120 | { |
---|
| 121 | this->bEvaluatedParams_ = true; |
---|
| 122 | this->evaluatedExecutor_ = this->shortcut_; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | else if (this->tokens_.size() > 1) |
---|
| 126 | { |
---|
| 127 | if (this->shortcut_->evaluate(this->tokens_.subSet(1).join() + this->getAdditionalParameter(), this->param_, " ")) |
---|
| 128 | { |
---|
| 129 | this->bEvaluatedParams_ = true; |
---|
| 130 | this->evaluatedExecutor_ = this->shortcut_; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) |
---|
| 136 | { |
---|
| 137 | if (this->function_) |
---|
| 138 | { |
---|
| 139 | if (this->tokens_.size() <= 2) |
---|
| 140 | { |
---|
| 141 | if (this->function_->evaluate(this->getAdditionalParameter(), this->param_, " ")) |
---|
| 142 | { |
---|
| 143 | this->bEvaluatedParams_ = true; |
---|
| 144 | this->evaluatedExecutor_ = this->function_; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | else if (this->tokens_.size() > 2) |
---|
| 148 | { |
---|
| 149 | if (this->function_->evaluate(this->tokens_.subSet(2).join() + this->getAdditionalParameter(), this->param_, " ")) |
---|
| 150 | { |
---|
| 151 | this->bEvaluatedParams_ = true; |
---|
| 152 | this->evaluatedExecutor_ = this->function_; |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param) |
---|
| 160 | { |
---|
| 161 | if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) |
---|
| 162 | this->param_[index] = param; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const |
---|
| 166 | { |
---|
| 167 | if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS) |
---|
| 168 | return this->param_[index]; |
---|
| 169 | |
---|
| 170 | return MT_null; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | bool CommandEvaluation::hasReturnvalue() const |
---|
| 174 | { |
---|
| 175 | if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) |
---|
| 176 | { |
---|
| 177 | if (this->shortcut_) |
---|
| 178 | return this->shortcut_->hasReturnvalue(); |
---|
| 179 | } |
---|
| 180 | else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) |
---|
| 181 | { |
---|
| 182 | if (this->function_) |
---|
| 183 | return this->function_->hasReturnvalue(); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | return MT_null; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | MultiTypeMath CommandEvaluation::getReturnvalue() const |
---|
| 190 | { |
---|
| 191 | if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished) |
---|
| 192 | { |
---|
| 193 | if (this->shortcut_) |
---|
| 194 | return this->shortcut_->getReturnvalue(); |
---|
| 195 | } |
---|
| 196 | else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished) |
---|
| 197 | { |
---|
| 198 | if (this->function_) |
---|
| 199 | return this->function_->getReturnvalue(); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | return MT_null; |
---|
| 203 | } |
---|
| 204 | } |
---|