Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- test.hps
- 19/06/12
- Updated 20/06/12
- @Javist
- **/
- funcdef void IsSolvedCallBack(bool solveState);
- class BitwisePuzzle
- {
- IsSolvedCallBack@ solvedCallBack;
- uint64 bitField;
- uint64[] bitMasks;
- string[] switches;
- int[] sols;
- BitwisePuzzle(string[] &in switchNames, int[] solutions, IsSolvedCallBack@ &in callback )
- {
- switches = switchNames;
- sols = solutions;
- @solvedCallBack = @callback;
- bitField = 0;
- bitMasks.resize(switchNames.length());
- for(uint i=0;i<switchNames.length();i++)
- {
- AddDebugMessage(" "+i, false);
- bitMasks[i]=(1<<i);
- }
- AddDebugMessage("BWPuzzle ready. (sz "+switches.length()+")", false);
- }
- void checkValidity()
- {
- uint64 requiredMask = 0;
- for(uint i=0;i<sols.length();i++)
- {
- requiredMask |= bitMasks[sols[i]-1];
- }
- solvedCallBack(requiredMask == bitField);
- }
- void notifySwitch(string &in switchName, int alState)
- {
- for(uint i=0;i<switches.length();i++)
- {
- if(switches[i]==switchName)
- {
- bitField = alState > 0 ? bitField |= bitMasks[i] : bitField ^ bitMasks[i];
- checkValidity();
- return;
- }
- }
- AddDebugMessage("ERR: "+switchName+" isn't declared in BWPuzzle (sz "+switches.length()+") ?!",false);
- }
- uint64 getBitField()
- {
- return bitField;
- }
- ~BitwisePuzzle()
- {
- @solvedCallBack = null;
- }
- }
- BitwisePuzzle bp;
- /////////////////////////////////////////////
- /////////////////////////////////////////////
- /////////////////////////////////////////////
- /////////////////////////////////////////////
- void OnStart()
- {
- GiveItemFromFile("lantern", "lantern.ent"); // Светилка. Мы ведь не негры и уголь не воруем)
- IsSolvedCallBack@ cb = @puzzleSolvedCallBack;
- string[] levers = {"lever_nice01_1","lever_nice01_2","lever_nice01_3","lever_nice01_4"}; // Имена ответственных рычагов. Порядок указания учитывается!
- int[] solutionz = {1,2,4}; // Позиции правильных рычагов для решения паззла.
- bp = BitwisePuzzle(levers,solutionz,@cb);
- }
- void puzzleSolvedCallBack(bool solveState)
- {
- SetSwingDoorLocked("castle_1", !solveState, true);
- SetLampLit("hanging_lantern_wall_5", solveState, true);
- }
- void doSw(string &in asEntity, int alState)
- {
- SetLeverStuckState(asEntity, alState, true);
- bp.notifySwitch(asEntity, alState);
- uint64 field = bp.getBitField();
- for(int i=0;i<4;i++)
- SetLampLit("hanging_lantern_wall_"+(i+1), (1<<i&field) > 0, true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement