hedgewars/uScript.pas
changeset 2996 dfc7507a21a0
parent 2949 d137a9da7701
child 2997 ca60b5638fff
equal deleted inserted replaced
2995:b90745d87332 2996:dfc7507a21a0
    55     ScriptAmmoStore : shortstring;
    55     ScriptAmmoStore : shortstring;
    56     ScriptLoaded : boolean;
    56     ScriptLoaded : boolean;
    57     
    57     
    58 procedure ScriptPrepareAmmoStore; forward;
    58 procedure ScriptPrepareAmmoStore; forward;
    59 procedure ScriptApplyAmmoStore; forward;
    59 procedure ScriptApplyAmmoStore; forward;
    60 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte); forward;
    60 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte); forward;
    61 
    61 
    62 // wrapped calls //
    62 // wrapped calls //
    63 
    63 
    64 // functions called from lua:
    64 // functions called from lua:
    65 // function(L : Plua_State) : LongInt; Cdecl;
    65 // function(L : Plua_State) : LongInt; Cdecl;
   209         begin
   209         begin
   210         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
   210         ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
   211         ParseCommand('grave ' + lua_tostring(L, 3), true);
   211         ParseCommand('grave ' + lua_tostring(L, 3), true);
   212         ParseCommand('fort ' + lua_tostring(L, 4), true);
   212         ParseCommand('fort ' + lua_tostring(L, 4), true);
   213         ParseCommand('voicepack ' + lua_tostring(L, 5), true);
   213         ParseCommand('voicepack ' + lua_tostring(L, 5), true);
   214         CurrentTeam^.Binds:= DefaultBinds;
   214         CurrentTeam^.Binds:= DefaultBinds
   215         // fails on x64
   215         // fails on x64
   216         //lua_pushinteger(L, LongInt(CurrentTeam));
   216         //lua_pushinteger(L, LongInt(CurrentTeam));
   217         end;
   217         end;
   218     lc_addteam:= 0;//1;
   218     lc_addteam:= 0;//1;
   219 end;
   219 end;
   275     lc_setgearposition:= 0
   275     lc_setgearposition:= 0
   276 end;
   276 end;
   277 
   277 
   278 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
   278 function lc_setammo(L : Plua_State) : LongInt; Cdecl;
   279 begin
   279 begin
   280     if lua_gettop(L) <> 3 then
   280     if lua_gettop(L) <> 4 then
   281         WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!')
   281         WriteLnToConsole('LUA: Wrong number of parameters passed to SetAmmo!')
   282     else
   282     else
   283         begin
   283         begin
   284         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3));
   284         ScriptSetAmmo(TAmmoType(lua_tointeger(L, 1)), lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
   285         end;
   285         end;
   286     lc_setammo:= 0
   286     lc_setammo:= 0
   287 end;
   287 end;
   288 ///////////////////
   288 ///////////////////
   289 
   289 
   343 ScriptSetInteger('GameFlags', GameFlags);
   343 ScriptSetInteger('GameFlags', GameFlags);
   344 ScriptSetString('Seed', cSeed);
   344 ScriptSetString('Seed', cSeed);
   345 ScriptSetInteger('TurnTime', cHedgehogTurnTime);
   345 ScriptSetInteger('TurnTime', cHedgehogTurnTime);
   346 ScriptSetInteger('CaseFreq', cCaseFactor);
   346 ScriptSetInteger('CaseFreq', cCaseFactor);
   347 ScriptSetInteger('LandAdds', cLandAdditions);
   347 ScriptSetInteger('LandAdds', cLandAdditions);
       
   348 ScriptSetInteger('Explosives', cExplosives);
   348 ScriptSetInteger('Delay', cInactDelay);
   349 ScriptSetInteger('Delay', cInactDelay);
   349 ScriptSetString('Map', '');
   350 ScriptSetString('Map', '');
   350 ScriptSetString('Theme', '');
   351 ScriptSetString('Theme', '');
   351 
   352 
   352 // import locale
   353 // import locale
   360 ParseCommand('seed ' + ScriptGetString('Seed'), true);
   361 ParseCommand('seed ' + ScriptGetString('Seed'), true);
   361 ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true);
   362 ParseCommand('$gmflags ' + ScriptGetString('GameFlags'), true);
   362 ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true);
   363 ParseCommand('$turntime ' + ScriptGetString('TurnTime'), true);
   363 ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true);
   364 ParseCommand('$casefreq ' + ScriptGetString('CaseFreq'), true);
   364 ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true);
   365 ParseCommand('$landadds ' + ScriptGetString('LandAdds'), true);
       
   366 ParseCommand('$explosives ' + ScriptGetString('Explosives'), true);
   365 ParseCommand('$delay ' + ScriptGetString('Delay'), true);
   367 ParseCommand('$delay ' + ScriptGetString('Delay'), true);
   366 if ScriptGetString('Map') <> '' then
   368 if ScriptGetString('Map') <> '' then
   367     ParseCommand('map ' + ScriptGetString('Map'), true);
   369     ParseCommand('map ' + ScriptGetString('Map'), true);
   368 if ScriptGetString('Theme') <> '' then
   370 if ScriptGetString('Theme') <> '' then
   369     ParseCommand('theme ' + ScriptGetString('Theme'), true);    
   371     ParseCommand('theme ' + ScriptGetString('Theme'), true);    
   370 
   372 
   371 ScriptPrepareAmmoStore;
   373 ScriptPrepareAmmoStore;
   372 ScriptCall('onAmmoStoreInit');
   374 ScriptCall('onAmmoStoreInit');
       
   375 ScriptApplyAmmoStore; // doing 6 times - this is just temporary for now
       
   376 ScriptApplyAmmoStore;
       
   377 ScriptApplyAmmoStore;
       
   378 ScriptApplyAmmoStore;
       
   379 ScriptApplyAmmoStore;
   373 ScriptApplyAmmoStore;
   380 ScriptApplyAmmoStore;
   374 end;
   381 end;
   375 
   382 
   376 procedure ScriptLoad(name : shortstring);
   383 procedure ScriptLoad(name : shortstring);
   377 var ret : LongInt;
   384 var ret : LongInt;
   457 ScriptAmmoStore:= '';
   464 ScriptAmmoStore:= '';
   458 for i:=1 to ord(High(TAmmoType)) do
   465 for i:=1 to ord(High(TAmmoType)) do
   459     ScriptAmmoStore:= ScriptAmmoStore + '0000';
   466     ScriptAmmoStore:= ScriptAmmoStore + '0000';
   460 end;
   467 end;
   461 
   468 
   462 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability: Byte);
   469 procedure ScriptSetAmmo(ammo : TAmmoType; count, propability, delay: Byte);
   463 begin
   470 begin
   464 if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) then
   471 if (ord(ammo) < 1) or (count > 9) or (count < 0) or (propability < 0) or (propability > 8) or (delay < 0) or (delay > 9)then
   465     exit;
   472     exit;
   466 ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1];
   473 ScriptAmmoStore[ord(ammo)]:= inttostr(count)[1];
   467 ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1];
   474 ScriptAmmoStore[ord(ammo) + ord(high(TAmmoType))]:= inttostr(propability)[1];
       
   475 ScriptAmmoStore[ord(ammo) + 2 * ord(high(TAmmoType))]:= inttostr(delay)[1];
   468 end;
   476 end;
   469 
   477 
   470 procedure ScriptApplyAmmoStore;
   478 procedure ScriptApplyAmmoStore;
   471 begin
   479 begin
   472     AddAmmoStore(ScriptAmmoStore);
   480     AddAmmoStore(ScriptAmmoStore);