/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ /* Ideas : Instantiate player Player one : 17::49::582::281::nil Player two : 395::420::74::657::nil */ struct RunePlayerStr = [ RRP_iId : I, RRP_player1 : SO3_OBJECT, RRP_lMarks : [[I I] r1], //marker id pos RRP_iCurrentRelPos : I, //position from the snake head (until death) RRP_iNbSuccess : I, RRP_iPlayerState : I, RRP_iWaitedRuneIdx : I ] MkRunePlayerStr;; struct RuneStr = [ RRN_instance : PInstance, RRN_iNumLevels : I, RRN_iNbRunes : I, RRN_iInitialSpeed : F, RRN_fCurrentSpeed : F, RRN_lPlayers : [RunePlayerStr r1], RRN_trmLoop : Timer, RRN_bState : I ] MkRuneStr;; fun deleteOb(inst, runestr)= _deltimer runestr.RRN_trmLoop; 0;; fun cbMarker(inst, from, action, param, rep, runestr)= let atoi param -> id in let sizelist runestr.RRN_lPlayers -> size in let 0 -> i in while (i < size) do ( let nth_list runestr.RRN_lPlayers i -> playerstr in let switch playerstr.RRP_lMarks id -> markerpos in if ((markerpos == nil) || (playerstr.RRP_iPlayerState != 0) || (playerstr.RRP_iWaitedRuneIdx == nil)) then nil else ( //addLogMessage strcatn "marker "::(itoa id)::" found for player ("::(itoa playerstr.RRP_iId)::")"::nil; //addLogMessage strcatn "Player : "::(itoa playerstr.RRP_iId)::" markermode : "::(itoa markerpos)::" waitedmode "::(itoa playerstr.RRP_iWaitedRuneIdx)::nil; if (markerpos != playerstr.RRP_iWaitedRuneIdx) then ( set playerstr.RRP_iPlayerState = 2; SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" bad rune"::nil nil nil; //addLogMessage strcatn "Player : "::(itoa playerstr.RRP_iId)::" bad marker found"::nil ) else ( set playerstr.RRP_iPlayerState = 1; SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" good rune"::nil nil nil; //addLogMessage strcatn "Player : "::(itoa playerstr.RRP_iId)::" good marker found nth : "::(itoa (playerstr.RRP_iNbSuccess + 1))::nil; ); ); set i = i + 1; ); 0;; fun cbStop(inst, from, action, param, rep, runestr)= _deltimer runestr.RRN_trmLoop; set runestr.RRN_trmLoop = nil; set runestr.RRN_bState = 0; let sizelist runestr.RRN_lPlayers -> size in let 0 -> i in while (i < size) do ( let nth_list runestr.RRN_lPlayers i -> playerstr in ( set playerstr.RRP_iCurrentRelPos = runestr.RRN_iNumLevels; set playerstr.RRP_iPlayerState = 0; set playerstr.RRP_iNbSuccess = 0; set playerstr.RRP_iWaitedRuneIdx = nil; ); set i = i + 1; ); 0;; fun cbTimerLoop(trm, runestr)= let nil -> gameOverPlayer in ( let sizelist runestr.RRN_lPlayers -> size in let 0 -> i in while (i < size) do ( let nth_list runestr.RRN_lPlayers i -> playerstr in ( //addLogMessage strcatn "Player ("::(itoa playerstr.RRP_iId)::") state "::(itoa playerstr.RRP_iPlayerState)::nil; if (playerstr.RRP_iPlayerState != 1) then ( set playerstr.RRP_iCurrentRelPos = playerstr.RRP_iCurrentRelPos - 1; if (playerstr.RRP_iCurrentRelPos > 0) then nil else set gameOverPlayer = playerstr; //addLogMessage strcatn "Player ("::(itoa playerstr.RRP_iId)::") missed: new pos "::(itoa playerstr.RRP_iCurrentRelPos)::nil; let -.(itof (playerstr.RRP_iCurrentRelPos)) *. (45.0 /. (itof runestr.RRN_iNumLevels)) -> yrot in SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" pos"::nil strcatn "0 "::(ftoa yrot)::" 0"::nil nil; 0; ) else ( // do not change his pos set playerstr.RRP_iNbSuccess = playerstr.RRP_iNbSuccess + 1; SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" score"::nil (itoa playerstr.RRP_iNbSuccess) nil; //addLogMessage strcatn "Player ("::(itoa playerstr.RRP_iId)::") good match: new pos "::(itoa playerstr.RRP_iCurrentRelPos)::nil; //addLogMessage strcatn "Player ("::(itoa playerstr.RRP_iId)::") scores "::(itoa playerstr.RRP_iNbSuccess)::nil; 0; ); set playerstr.RRP_iPlayerState = 0; set playerstr.RRP_iWaitedRuneIdx = (mod rand (sizelist playerstr.RRP_lMarks)); let nth_list playerstr.RRP_lMarks playerstr.RRP_iWaitedRuneIdx -> [mid _] in ( SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" next rune"::nil (itoa mid) nil; //addLogMessage strcatn "Player ("::(itoa playerstr.RRP_iId)::") Wait for: "::(itoa mid)::nil; ); ); set i = i + 1; ); if(gameOverPlayer == nil) then nil else ( cbStop runestr.RRN_instance nil nil nil nil runestr; SendPluginEvent runestr.RRN_instance "Game over" (itoa gameOverPlayer.RRP_iId) nil; addLogMessage strcatn "Game over for player ("::(itoa gameOverPlayer.RRP_iId)::")"::nil; 0; ); ); 0;; fun cbStart(inst, from, action, param, rep, runestr)= if(runestr.RRN_bState) then nil else ( set runestr.RRN_bState = 1; let sizelist runestr.RRN_lPlayers -> size in let 0 -> i in while (i < size) do ( let nth_list runestr.RRN_lPlayers i -> playerstr in ( let -.(itof (playerstr.RRP_iCurrentRelPos)) *. (45.0 /. (itof runestr.RRN_iNumLevels)) -> yrot in SendPluginEvent runestr.RRN_instance strcatn "Update player "::(itoa playerstr.RRP_iId)::" pos init"::nil strcatn "0 "::(ftoa yrot)::" 0"::nil nil; ); set i = i + 1; ); set runestr.RRN_trmLoop = _rfltimer _starttimer _channel (ftoi runestr.RRN_fCurrentSpeed) * 1000 @cbTimerLoop runestr; ); 0;; fun cbRestart(inst, from, action, param, rep, runestr)= cbStop inst from action param rep runestr; cbStart inst from action param rep runestr; 0;; fun newOb(inst)= srand time; let (getPluginInstanceParam inst "player1") -> player1 in let (getPluginInstanceParam inst "player2") -> player2 in let atoi (getPluginInstanceParam inst "nblevels") -> nblevels in let if nblevels == nil then 16 else nblevels -> nblevels in let atoi (getPluginInstanceParam inst "nbRunes") -> nbrunes in let if nbrunes == nil then 4 else nbrunes -> nbrunes in let atof (getPluginInstanceParam inst "initialSpeed") -> initialSpeed in let if initialSpeed == nil then 5.0 else initialSpeed -> initialSpeed in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let MkRuneStr [inst nblevels nbrunes initialSpeed initialSpeed nil nil 0] -> runestr in ( let SO3SceneGetObject (V3DgetSession c3dXsession) player1 -> objplayer1 in if objplayer1 == nil then nil else let MkRunePlayerStr [1 objplayer1 [17 0]::[49 1]::[582 2]::[281 3]::nil nblevels 0 0 nil] -> player1str in set runestr.RRN_lPlayers = lcat player1str::nil runestr.RRN_lPlayers; let SO3SceneGetObject (V3DgetSession c3dXsession) player2 -> objplayer2 in if objplayer2 == nil then nil else let MkRunePlayerStr [2 objplayer2 [395 0]::[420 1]::[74 2]::[657 3]::nil nblevels 0 0 nil] -> player2str in set runestr.RRN_lPlayers = lcat player2str::nil runestr.RRN_lPlayers; if (!init) then nil else cbStart inst nil nil nil nil runestr; PluginRegisterAction inst "Restart" mkfun6 @cbRestart runestr; PluginRegisterAction inst "Start" mkfun6 @cbStart runestr; PluginRegisterAction inst "Stop" mkfun6 @cbStop runestr; PluginRegisterAction inst "Marker" mkfun6 @cbMarker runestr; setPluginInstanceCbDel inst mkfun2 @deleteOb runestr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;