100 ScriptAmmoReinforcement : shortstring; |
100 ScriptAmmoReinforcement : shortstring; |
101 ScriptLoaded : boolean; |
101 ScriptLoaded : boolean; |
102 mapDims : boolean; |
102 mapDims : boolean; |
103 PointsBuffer: shortstring; |
103 PointsBuffer: shortstring; |
104 PrevCursorX, PrevCursorY: LongInt; |
104 PrevCursorX, PrevCursorY: LongInt; |
|
105 PendingTurnTimeLeft, PendingReadyTimeLeft: LongWord; |
|
106 isPendingTurnTimeLeft, isPendingReadyTimeLeft: boolean; |
105 |
107 |
106 {$IFDEF USE_LUA_SCRIPT} |
108 {$IFDEF USE_LUA_SCRIPT} |
107 procedure ScriptPrepareAmmoStore; forward; |
109 procedure ScriptPrepareAmmoStore; forward; |
108 procedure ScriptApplyAmmoStore; forward; |
110 procedure ScriptApplyAmmoStore; forward; |
109 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
111 procedure ScriptSetAmmo(ammo : TAmmoType; count, probability, delay, reinforcement: Byte); forward; |
134 // get source name and line count |
136 // get source name and line count |
135 lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo); |
137 lua_getinfo(luaState, PChar('Sl'), @LuaDebugInfo); |
136 exit(true); |
138 exit(true); |
137 end; |
139 end; |
138 |
140 |
139 procedure LuaError(s: shortstring); |
141 procedure LuaErrorOrWarning(s: shortstring; isWarning: boolean); |
140 var src: shortstring; |
142 var src, intro: shortstring; |
141 const |
143 const |
142 maxsrclen = 20; |
144 maxsrclen = 20; |
143 begin |
145 begin |
|
146 if isWarning then |
|
147 intro:= 'LUA WARNING' |
|
148 else |
|
149 intro:= 'LUA ERROR'; |
144 if LuaUpdateDebugInfo() then |
150 if LuaUpdateDebugInfo() then |
145 begin |
151 begin |
146 src:= StrPas(LuaDebugInfo.source); |
152 src:= StrPas(LuaDebugInfo.source); |
147 s:= 'LUA ERROR [ ... ' |
153 s:= intro + ': [ ... ' |
148 + copy(src, Length(src) - maxsrclen, maxsrclen - 3) + ':' |
154 + copy(src, Length(src) - maxsrclen, maxsrclen - 3) + ':' |
149 + inttostr(LuaDebugInfo.currentLine) + ']: ' + s; |
155 + inttostr(LuaDebugInfo.currentLine) + ']: ' + s; |
150 end |
156 end |
151 else |
157 else |
152 s:= 'LUA ERROR: ' + s; |
158 s:= intro + ': ' + s; |
153 WriteLnToConsole(s); |
159 WriteLnToConsole(s); |
154 AddChatString(#5 + s); |
160 AddChatString(#5 + s); |
155 if cTestLua then |
161 if cTestLua and (not isWarning) then |
156 halt(HaltTestLuaError); |
162 halt(HaltTestLuaError); |
|
163 end; |
|
164 |
|
165 procedure LuaError(s: shortstring); |
|
166 begin |
|
167 LuaErrorOrWarning(s, false); |
|
168 end; |
|
169 |
|
170 procedure LuaWarning(s: shortstring); |
|
171 begin |
|
172 LuaErrorOrWarning(s, true); |
157 end; |
173 end; |
158 |
174 |
159 procedure LuaCallError(error, call, paramsyntax: shortstring); |
175 procedure LuaCallError(error, call, paramsyntax: shortstring); |
160 begin |
176 begin |
161 LuaError(call + ': ' + error); |
177 LuaError(call + ': ' + error); |
3185 lua_pushboolean(L, false); |
3201 lua_pushboolean(L, false); |
3186 lc_explode:= 1; |
3202 lc_explode:= 1; |
3187 end; |
3203 end; |
3188 |
3204 |
3189 function lc_setturntimeleft(L : Plua_State) : LongInt; Cdecl; |
3205 function lc_setturntimeleft(L : Plua_State) : LongInt; Cdecl; |
|
3206 var number: Int64; |
3190 begin |
3207 begin |
3191 if CheckLuaParamCount(L, 1, 'SetTurnTimeLeft', 'TurnTimeLeft') then |
3208 if CheckLuaParamCount(L, 1, 'SetTurnTimeLeft', 'TurnTimeLeft') then |
3192 TurnTimeLeft:= Trunc(lua_tonumber(L, 1)); |
3209 begin |
|
3210 number:= Trunc(lua_tonumber(L, 1)); |
|
3211 if number < 0 then |
|
3212 number:= 0; |
|
3213 if number > cMaxTurnTime then |
|
3214 number:= cMaxTurnTime; |
|
3215 // The real TurnTimeLeft will be set in SetGlobals |
|
3216 PendingTurnTimeLeft:= number; |
|
3217 isPendingTurnTimeLeft:= true; |
|
3218 end; |
3193 lc_setturntimeleft:= 0; |
3219 lc_setturntimeleft:= 0; |
3194 end; |
3220 end; |
3195 |
3221 |
3196 function lc_setreadytimeleft(L : Plua_State) : LongInt; Cdecl; |
3222 function lc_setreadytimeleft(L : Plua_State) : LongInt; Cdecl; |
|
3223 var number: Int64; |
3197 begin |
3224 begin |
3198 if CheckLuaParamCount(L, 1, 'SetReadyTimeLeft', 'ReadyTimeLeft') then |
3225 if CheckLuaParamCount(L, 1, 'SetReadyTimeLeft', 'ReadyTimeLeft') then |
3199 ReadyTimeLeft:= Trunc(lua_tonumber(L, 1)); |
3226 begin |
|
3227 number:= Trunc(lua_tonumber(L, 1)); |
|
3228 if number < 0 then |
|
3229 number:= 0; |
|
3230 if number > cMaxTurnTime then |
|
3231 number:= cMaxTurnTime; |
|
3232 // The real ReadyTimeLeft will be set in SetGlobals |
|
3233 PendingReadyTimeLeft:= number; |
|
3234 isPendingReadyTimeLeft:= true; |
|
3235 end; |
3200 lc_setreadytimeleft:= 0; |
3236 lc_setreadytimeleft:= 0; |
3201 end; |
3237 end; |
3202 |
3238 |
3203 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl; |
3239 function lc_startghostpoints(L : Plua_State) : LongInt; Cdecl; |
3204 begin |
3240 begin |
3680 else |
3716 else |
3681 ScriptSetNil('CurrentHedgehog'); |
3717 ScriptSetNil('CurrentHedgehog'); |
3682 end; |
3718 end; |
3683 |
3719 |
3684 procedure GetGlobals; |
3720 procedure GetGlobals; |
3685 begin |
3721 var currentTTL, currentRTL, newTTL, newRTL: LongInt; |
3686 // This function is deprecated. |
3722 begin |
3687 // TODO: Remove this function. |
3723 // Setting TurnTimeLeft and ReadyTimeLeft should now be done in the setter functions. |
3688 // Setting TurnTimeLeft and ReadyTimeLeft is now done in the setter functions |
|
3689 // SetTurnTimeLeft and SetReadTimeLeft. |
3724 // SetTurnTimeLeft and SetReadTimeLeft. |
3690 // GetGloals should be removed in a future release. |
3725 // GetGloals should be removed in a future release. |
3691 TurnTimeLeft:= ScriptGetInteger('TurnTimeLeft'); |
3726 |
3692 ReadyTimeLeft:= ScriptGetInteger('ReadyTimeLeft'); |
3727 // DEPRECATED: Read TurnTimeLeft and ReadyTimeLeft from script directly. |
|
3728 // TODO: Remove this behaviour in a future version. |
|
3729 currentTTL:= TurnTimeLeft; |
|
3730 currentRTL:= ReadyTimeLeft; |
|
3731 newTTL:= ScriptGetInteger('TurnTimeLeft'); |
|
3732 newRTL:= ScriptGetInteger('ReadyTimeLeft'); |
|
3733 if currentTTL <> newTTL then |
|
3734 begin |
|
3735 TurnTimeLeft:= newTTL; |
|
3736 LuaWarning('Writing to TurnTimeLeft directly is deprecated! Use SetTurnTimeLeft instead!'); |
|
3737 end; |
|
3738 |
|
3739 if currentRTL <> newRTL then |
|
3740 begin |
|
3741 ReadyTimeLeft:= newRTL; |
|
3742 LuaWarning('Writing to ReadyTimeLeft directly is deprecated! Use SetReadyTimeLeft instead!'); |
|
3743 end; |
|
3744 |
|
3745 // Set TurnTimeLeft and ReadyTimeLeft if activated by SetTurnTimeLeft and SetReadyTimeLeft before |
|
3746 if isPendingTurnTimeLeft then |
|
3747 begin |
|
3748 TurnTimeLeft:= PendingTurnTimeLeft; |
|
3749 isPendingTurnTimeLeft:= false; |
|
3750 end; |
|
3751 if isPendingReadyTimeLeft then |
|
3752 begin |
|
3753 ReadyTimeLeft:= PendingReadyTimeLeft; |
|
3754 isPendingReadyTimeLeft:= false; |
|
3755 end; |
3693 end; |
3756 end; |
3694 |
3757 |
3695 procedure ScriptCall(fname : shortstring); |
3758 procedure ScriptCall(fname : shortstring); |
3696 begin |
3759 begin |
3697 if (not ScriptLoaded) or (not ScriptExists(fname)) then |
3760 if (not ScriptLoaded) or (not ScriptExists(fname)) then |