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.
25 #include "GameScript/GameScript.h"
35 for (unsigned int i
= 0; i
< TopLevelCount
; i
++) {
36 if (initialStates
[i
]) {
37 FreeDialogState( initialStates
[i
] );
42 if (Order
) free(Order
);
45 DialogState
* Dialog::GetState(unsigned int index
)
47 if (index
>= TopLevelCount
) {
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();
60 delete trans
->condition
;
63 free( ds
->transitions
);
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
)) {
81 int Dialog::FindRandomState(Scriptable
* target
)
84 unsigned int max
= TopLevelCount
;
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
)) {
93 for (i
=0; i
< pick
; i
++) {
94 Condition
*cond
= GetState(i
)->condition
;
95 if (cond
&& cond
->Evaluate(target
)) {