melee / ranged effects
[gemrb.git] / gemrb / core / Dialog.cpp
bloba8399ee59f2e54f09b876a33d606eb82aeab7053
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "Dialog.h"
23 #include "win32def.h"
25 #include "GameScript/GameScript.h"
27 Dialog::Dialog(void)
29 TopLevelCount = 0;
32 Dialog::~Dialog(void)
34 if (initialStates) {
35 for (unsigned int i = 0; i < TopLevelCount; i++) {
36 if (initialStates[i]) {
37 FreeDialogState( initialStates[i] );
40 free(initialStates);
42 if (Order) free(Order);
45 DialogState* Dialog::GetState(unsigned int index)
47 if (index >= TopLevelCount) {
48 return NULL;
50 return initialStates[index];
53 void Dialog::FreeDialogState(DialogState* ds)
55 for (unsigned int i = 0; i < ds->transitionsCount; i++) {
56 DialogTransition *trans = ds->transitions[i];
57 for (size_t j = 0; j < trans->actions.size(); ++j)
58 trans->actions[j]->Release();
59 if (trans->condition)
60 delete trans->condition;
61 delete( trans );
63 free( ds->transitions );
64 if (ds->condition) {
65 delete ds->condition;
67 delete( ds );
70 int Dialog::FindFirstState(Scriptable* target)
72 for (unsigned int i = 0; i < TopLevelCount; i++) {
73 Condition *cond = GetState( Order[i] )->condition;
74 if (cond && cond->Evaluate(target)) {
75 return Order[i];
78 return -1;
81 int Dialog::FindRandomState(Scriptable* target)
83 unsigned int i;
84 unsigned int max = TopLevelCount;
85 if (!max) return -1;
86 unsigned int pick = rand()%max;
87 for (i=pick; i < max; i++) {
88 Condition *cond = GetState(i)->condition;
89 if (cond && cond->Evaluate(target)) {
90 return i;
93 for (i=0; i < pick; i++) {
94 Condition *cond = GetState(i)->condition;
95 if (cond && cond->Evaluate(target)) {
96 return i;
99 return -1;