Пример #1
0
 private int fnWipeHands(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     ScriptVars[(int)ScriptVariableNames.OBJECT_HELD] = 0;
     _mouse.SetLuggage(0, 0);
     _menu.Refresh(Menu.MENU_TOP);
     return(SCRIPT_CONT);
 }
Пример #2
0
        public int FnCheckForEvent(SwordObject cpt, int id, int pause)
        {
            if (pause != 0)
            {
                cpt.pause = pause;
                cpt.logic = Logic.LOGIC_pause_for_event;
                return Logic.SCRIPT_STOP;
            }

            for (var objCnt = 0; objCnt < SwordObject.O_TOTAL_EVENTS; objCnt++)
            {
                if (cpt.event_list[objCnt].o_event != 0)
                    for (var globCnt = 0; globCnt < TOTAL_EVENT_SLOTS; globCnt++)
                    {
                        if (_eventPendingList[globCnt].delay!=0 && (_eventPendingList[globCnt].eventNumber == cpt.event_list[objCnt].o_event))
                        {
                            cpt.logic = Logic.LOGIC_script;      //force into script mode
                            _eventPendingList[globCnt].delay = 0; //started, so remove from queue
                            cpt.tree.script_level++;
                            cpt.tree.script_id[cpt.tree.script_level] =
                                cpt.event_list[objCnt].o_event_script;
                            cpt.tree.script_pc[cpt.tree.script_level] =
                                cpt.event_list[objCnt].o_event_script;
                            return Logic.SCRIPT_STOP;
                        }
                    }
            }
            return Logic.SCRIPT_CONT;
        }
Пример #3
0
        private int fnKillId(SwordObject cpt, int id, int target, int d, int e, int f, int z, int x)
        {
            SwordObject targetObj = _objMan.FetchObject((uint)target);

            targetObj.status = 0;
            return(SCRIPT_CONT);
        }
Пример #4
0
        private int fnIsFacing(SwordObject cpt, int id, int targetId, int b, int c, int d, int a, int z)
        {
            SwordObject target = _objMan.FetchObject((uint)targetId);
            int         x, y, dir;

            if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
            {
                x   = target.xcoord;
                y   = target.ycoord;
                dir = target.dir;
            }
            else
            {
                throw new InvalidOperationException("fnIsFacing:: Target isn't a mega");
            }

            int lookDir = WhatTarget(x, y, cpt.xcoord, cpt.ycoord);

            lookDir -= dir;
            lookDir  = Math.Abs(lookDir);

            if (lookDir > 4)
            {
                lookDir = 8 - lookDir;
            }

            ScriptVars[(int)ScriptVariableNames.RETURN_VALUE] = (uint)lookDir;
            return(SCRIPT_STOP);
        }
Пример #5
0
        public int FnCheckForEvent(SwordObject cpt, int id, int pause)
        {
            if (pause != 0)
            {
                cpt.pause = pause;
                cpt.logic = Logic.LOGIC_pause_for_event;
                return(Logic.SCRIPT_STOP);
            }

            for (var objCnt = 0; objCnt < SwordObject.O_TOTAL_EVENTS; objCnt++)
            {
                if (cpt.event_list[objCnt].o_event != 0)
                {
                    for (var globCnt = 0; globCnt < TOTAL_EVENT_SLOTS; globCnt++)
                    {
                        if (_eventPendingList[globCnt].delay != 0 && (_eventPendingList[globCnt].eventNumber == cpt.event_list[objCnt].o_event))
                        {
                            cpt.logic = Logic.LOGIC_script;       //force into script mode
                            _eventPendingList[globCnt].delay = 0; //started, so remove from queue
                            cpt.tree.script_level++;
                            cpt.tree.script_id[cpt.tree.script_level] =
                                cpt.event_list[objCnt].o_event_script;
                            cpt.tree.script_pc[cpt.tree.script_level] =
                                cpt.event_list[objCnt].o_event_script;
                            return(Logic.SCRIPT_STOP);
                        }
                    }
                }
            }
            return(Logic.SCRIPT_CONT);
        }
Пример #6
0
        private int fnSendSync(SwordObject cpt, int id, int sendId, int syncValue, int e, int f, int z, int x)
        {
            SwordObject target = _objMan.FetchObject((uint)sendId);

            target.sync = syncValue;
            return(SCRIPT_CONT);
        }
Пример #7
0
        private int fnFaceXy(SwordObject cpt, int id, int x, int y, int c, int d, int a, int b)
        {
            int megaTarDir = WhatTarget(cpt.xcoord, cpt.ycoord, x, y);

            fnTurn(cpt, id, megaTarDir, 0, 0, 0, 0, 0);
            return(SCRIPT_STOP);
        }
Пример #8
0
        private int fnChangeSpeechText(SwordObject cpt, int id, int tar, int width, int pen, int f, int z, int x)
        {
            SwordObject target = _objMan.FetchObject((uint)tar);

            target.speech_width = width;
            target.speech_pen   = pen;
            return(SCRIPT_STOP);
        }
Пример #9
0
 private int fnLeaveSection(SwordObject cpt, int id, int oldScreen, int d, int e, int f, int z, int x)
 {
     if (oldScreen >= ObjectMan.TOTAL_SECTIONS)
     {
         throw new InvalidOperationException($"mega {id} leaving section {oldScreen}");
     }
     _objMan.MegaLeaving((ushort)oldScreen, id);
     return(SCRIPT_CONT);
 }
Пример #10
0
        private int fnChangeFloor(SwordObject cpt, int id, int floor, int d, int e, int f, int z, int x)
        {
            cpt.place = floor;
            SwordObject floorCpt = _objMan.FetchObject((uint)floor);

            cpt.scale_a = floorCpt.scale_a;
            cpt.scale_b = floorCpt.scale_b;
            return(SCRIPT_CONT);
        }
Пример #11
0
        private int fnGetTo(SwordObject cpt, int id, int a, int b, int c, int d, int z, int x)
        {
            SwordObject place = _objMan.FetchObject((uint)cpt.place);

            cpt.tree.script_level++;
            cpt.tree.script_pc[cpt.tree.script_level] = place.get_to_script;
            cpt.tree.script_id[cpt.tree.script_level] = place.get_to_script;
            return(SCRIPT_STOP);
        }
Пример #12
0
        private int fnWalk(SwordObject cpt, int id, int x, int y, int dir, int stance, int a, int b)
        {
            if (stance > 0)
            {
                dir = 9;
            }
            cpt.walk_pc        = 0;
            cpt.route[1].frame = 512; // end of sequence
            if (id == PLAYER)
            {
                _router.SetPlayerTarget(x, y, dir, stance);
            }

            int routeRes = _router.RouteFinder(id, cpt, x, y, dir);

            if (id == PLAYER)
            {
                if ((routeRes == 1) || (routeRes == 2))
                {
                    ScriptVars[(int)ScriptVariableNames.MEGA_ON_GRID]   = 0;
                    ScriptVars[(int)ScriptVariableNames.REROUTE_GEORGE] = 0;
                }
            }
            if ((routeRes == 1) || (routeRes == 2))
            {
                cpt.down_flag = 1; // 1 means okay.
                                   // if both mouse buttons were pressed on an exit => skip george's walk
                if ((id == GEORGE) && (_mouse.TestEvent() == Mouse.MOUSE_BOTH_BUTTONS))
                {
                    int target = (int)ScriptVars[(int)ScriptVariableNames.CLICK_ID];
                    // exceptions: compacts that use hand pointers but are not actually exits
                    if ((target != LEFT_SCROLL_POINTER) && (target != RIGHT_SCROLL_POINTER) &&
                        (target != FLOOR_63) && (target != ROOF_63) && (target != GUARD_ROOF_63) &&
                        (target != LEFT_TREE_POINTER_71) && (target != RIGHT_TREE_POINTER_71))
                    {
                        target = _objMan.FetchObject(ScriptVars[(int)ScriptVariableNames.CLICK_ID]).mouse_on;
                        if ((target >= SCR_exit0) && (target <= SCR_exit9))
                        {
                            fnStandAt(cpt, id, x, y, dir, stance, 0, 0);
                            return(SCRIPT_STOP);
                        }
                    }
                }
                cpt.logic = LOGIC_AR_animate;
                return(SCRIPT_STOP);
            }
            else if (routeRes == 3)
            {
                cpt.down_flag = 1; // pretend it was successful
            }
            else
            {
                cpt.down_flag = 0; // 0 means error
            }
            return(SCRIPT_CONT);
        }
Пример #13
0
 public void FnIssueEvent(SwordObject cpt, int id, int evt, int delay)
 {
     var evSlot = 0;
     while (_eventPendingList[evSlot].delay != 0)
         evSlot++;
     if (evSlot >= TOTAL_EVENT_SLOTS)
         throw new InvalidOperationException("EventManager ran out of event slots");
     _eventPendingList[evSlot].delay = delay;
     _eventPendingList[evSlot].eventNumber = evt;
 }
Пример #14
0
        private int cfnSetScript(SwordObject cpt, int id, int target, int script, int e, int f, int z, int x)
        {
            SwordObject tar = _objMan.FetchObject((uint)target);

            tar.tree.script_level = 0;
            tar.tree.script_pc[0] = script;
            tar.tree.script_id[0] = script;
            tar.logic             = LOGIC_script;
            return(SCRIPT_CONT);
        }
Пример #15
0
        private int fnFullAnim(SwordObject cpt, int id, int anim, int graphic, int e, int f, int z, int x)
        {
            cpt.logic = LOGIC_full_anim;

            cpt.anim_pc       = 0;
            cpt.anim_resource = anim;
            cpt.resource      = graphic;
            cpt.status       &= ~STAT_SHRINK;
            cpt.sync          = 0;
            return(SCRIPT_STOP);
        }
Пример #16
0
        private int fnWeWait(SwordObject cpt, int id, int tar, int d, int e, int f, int z, int x)
        {
            SwordObject target = _objMan.FetchObject((uint)tar);

            target.status &= ~STAT_TALK_WAIT;

            cpt.logic     = LOGIC_wait_for_talk;
            cpt.down_flag = tar;

            return(SCRIPT_STOP);
        }
Пример #17
0
        private int cfnClickInteract(SwordObject cpt, int id, int target, int d, int e, int f, int z, int x)
        {
            SwordObject tar = _objMan.FetchObject((uint)target);

            cpt = _objMan.FetchObject(PLAYER);
            cpt.tree.script_level = 0;
            cpt.tree.script_pc[0] = tar.interact;
            cpt.tree.script_id[0] = tar.interact;
            cpt.logic             = LOGIC_script;
            return(SCRIPT_STOP);
        }
Пример #18
0
        //send instructions to mega in conversation with player
        //the instruction is interpreted by the script mega_interact
        private int fnTheyDo(SwordObject cpt, int id, int tar, int instruc, int param1, int param2, int param3, int x)
        {
            SwordObject target;

            target           = _objMan.FetchObject((uint)tar);
            target.down_flag = instruc; // instruction for the mega
            target.ins1      = param1;
            target.ins2      = param2;
            target.ins3      = param3;
            return(SCRIPT_CONT);
        }
Пример #19
0
 private int fnSubScript(SwordObject cpt, int id, int script, int d, int e, int f, int z, int x)
 {
     cpt.tree.script_level++;
     if (cpt.tree.script_level == ScriptTree.TOTAL_script_levels)
     {
         throw new InvalidOperationException($"Compact {id}: script level exceeded in fnSubScript");
     }
     cpt.tree.script_pc[cpt.tree.script_level] = script;
     cpt.tree.script_id[cpt.tree.script_level] = script;
     return(SCRIPT_STOP);
 }
Пример #20
0
 private int fnQuitGame(SwordObject cpt, int id, int a, int b, int c, int d, int z, int x)
 {
     if (SystemVars.IsDemo)
     {
         // TODO:GUI::MessageDialog dialog(_("This is the end of the Broken Sword 1 Demo"), _("OK"), NULL);
         //dialog.runModal();
         SwordEngine.ShouldQuit = true;
     }
     else
     {
         throw new InvalidOperationException("fnQuitGame() called");
     }
     return(fnQuit(cpt, id, 0, 0, 0, 0, 0, 0));
 }
Пример #21
0
        private int fnDeathScreen(SwordObject cpt, int id, int a, int b, int c, int d, int z, int x)
        {
            if (ScriptVars[(int)ScriptVariableNames.FINALE_OPTION_FLAG] == 4) // successful end of game!
            {
                SystemVars.ControlPanelMode = ControlPanelMode.CP_THEEND;
            }
            else
            {
                SystemVars.ControlPanelMode = ControlPanelMode.CP_DEATHSCREEN;
            }

            cpt.logic = LOGIC_quit;
            return(SCRIPT_STOP);
        }
Пример #22
0
        private int fnPlaySequence(SwordObject cpt, int id, int sequenceId, int d, int e, int f, int z, int x)
        {
            // A cutscene usually (always?) means the room will change. In the
            // meantime, we don't want any looping sound effects still playing.
            _sound.QuitScreen();

            var player = new MoviePlayer(_vm, _textMan, _resMan);

            _screen.ClearScreen();
            player.Load(sequenceId);
            player.Play();

            return(SCRIPT_CONT);
        }
Пример #23
0
 private int fnStandAt(SwordObject cpt, int id, int x, int y, int dir, int stance, int a, int b)
 {
     if ((dir < 0) || (dir > 8))
     {
         // TODO: warning("fnStandAt:: invalid direction %d", dir);
         return(SCRIPT_CONT);
     }
     if (dir == 8)
     {
         dir = cpt.dir;
     }
     cpt.xcoord = x;
     cpt.ycoord = y;
     return(fnStand(cpt, id, dir, stance, 0, 0, 0, 0));
 }
Пример #24
0
        public void FnIssueEvent(SwordObject cpt, int id, int evt, int delay)
        {
            var evSlot = 0;

            while (_eventPendingList[evSlot].delay != 0)
            {
                evSlot++;
            }
            if (evSlot >= TOTAL_EVENT_SLOTS)
            {
                throw new InvalidOperationException("EventManager ran out of event slots");
            }
            _eventPendingList[evSlot].delay       = delay;
            _eventPendingList[evSlot].eventNumber = evt;
        }
Пример #25
0
        private int fnInteract(SwordObject cpt, int id, int target, int d, int e, int f, int z, int x)
        {
            SwordObject tar = _objMan.FetchObject((uint)target);

            cpt.place = tar.place;

            SwordObject floorObject = _objMan.FetchObject((uint)tar.place);

            cpt.scale_a = floorObject.scale_a;
            cpt.scale_b = floorObject.scale_b;

            cpt.tree.script_level++;
            cpt.tree.script_pc[cpt.tree.script_level] = tar.interact;
            cpt.tree.script_id[cpt.tree.script_level] = tar.interact;

            return(SCRIPT_STOP);
        }
Пример #26
0
        private int fnPlayMusic(SwordObject cpt, int id, int tuneId, int loopFlag, int c, int d, int z, int x)
        {
            if (tuneId == 153)
            {
                return(SCRIPT_CONT);
            }
            if (loopFlag == LOOPED)
            {
                ScriptVars[(int)ScriptVariableNames.CURRENT_MUSIC] = (uint)tuneId; // so it gets restarted when saving & reloading
            }
            else
            {
                ScriptVars[(int)ScriptVariableNames.CURRENT_MUSIC] = 0;
            }

            _music.StartMusic(tuneId, loopFlag);
            return(SCRIPT_CONT);
        }
Пример #27
0
 private int fnStand(SwordObject cpt, int id, int dir, int stance, int c, int d, int a, int b)
 {
     if ((dir < 0) || (dir > 8))
     {
         // TODO: warning("fnStand:: invalid direction %d", dir);
         return(SCRIPT_CONT);
     }
     if (dir == 8)
     {
         dir = cpt.dir;
     }
     cpt.resource = cpt.walk_resource;
     cpt.status  |= STAT_SHRINK;
     cpt.anim_x   = cpt.xcoord;
     cpt.anim_y   = cpt.ycoord;
     cpt.frame    = 96 + dir;
     cpt.dir      = dir;
     return(SCRIPT_STOP);
 }
Пример #28
0
        private int fnFace(SwordObject cpt, int id, int targetId, int b, int c, int d, int a, int z)
        {
            SwordObject target = _objMan.FetchObject((uint)targetId);
            int         x, y;

            if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
            {
                x = target.xcoord;
                y = target.ycoord;
            }
            else
            {
                x = (target.mouse_x1 + target.mouse_x2) / 2;
                y = target.mouse_y2;
            }
            int megaTarDir = WhatTarget(cpt.xcoord, cpt.ycoord, x, y);

            fnTurn(cpt, id, megaTarDir, 0, 0, 0, 0, 0);
            return(SCRIPT_STOP);
        }
Пример #29
0
        //send an instruction to mega we're talking to and wait
        //until it has finished before returning to script
        private int fnTheyDoWeWait(SwordObject cpt, int id, int tar, int instruc, int param1, int param2, int param3, int x)
        {
            // workaround for scriptbug #928791: Freeze at hospital
            // in at least one game version, a script forgets to set sam_returning back to zero
            if ((tar == SAM) && (instruc == INS_talk) && (param2 == 2162856))
            {
                ScriptVars[(int)ScriptVariableNames.SAM_RETURNING] = 0;
            }
            SwordObject target = _objMan.FetchObject((uint)tar);

            target.down_flag = instruc; // instruction for the mega
            target.ins1      = param1;
            target.ins2      = param2;
            target.ins3      = param3;
            target.status   &= ~STAT_TALK_WAIT;

            cpt.logic     = LOGIC_wait_for_talk;
            cpt.down_flag = tar;
            return(SCRIPT_STOP);
        }
Пример #30
0
        private int fnAnim(SwordObject cpt, int id, int cdt, int spr, int e, int f, int z, int x)
        {
            if (cdt != 0 && (spr == 0))
            {
                var animTab    = _resMan.OpenFetchRes((uint)cdt);
                var animOffset = Header.Size + cpt.dir * AnimSet.Size;
                var anim       = new AnimSet(animTab, animOffset);
                cpt.anim_resource = (int)_resMan.ReadUInt32(anim.cdt);
                cpt.resource      = (int)_resMan.ReadUInt32(anim.spr);
                _resMan.ResClose((uint)cdt);
            }
            else
            {
                cpt.anim_resource = cdt;
                cpt.resource      = spr;
            }
            if ((cpt.anim_resource == 0) || (cpt.resource == 0))
            {
                throw new InvalidOperationException($"fnAnim called width ({cdt}/{spr}) => ({cpt.anim_resource}/{cpt.resource})");
            }

            var frameHead = new FrameHeader(_resMan.FetchFrame(_resMan.OpenFetchRes((uint)cpt.resource), 0));

            if (frameHead.offsetX != 0 || frameHead.offsetY != 0)
            {                             // boxed mega anim?
                cpt.status |= STAT_SHRINK;
                cpt.anim_x  = cpt.xcoord; // set anim coords to 'feet' coords - only need to do this once
                cpt.anim_y  = cpt.ycoord;
            }
            else
            {
                // Anim_driver sets anim coords to cdt coords for every frame of a loose anim
                cpt.status &= ~STAT_SHRINK;
            }
            _resMan.ResClose((uint)cpt.resource);

            cpt.logic   = LOGIC_anim;
            cpt.anim_pc = 0;
            cpt.sync    = 0;
            return(SCRIPT_STOP);
        }
Пример #31
0
        private int fnGetPos(SwordObject cpt, int id, int targetId, int b, int c, int d, int z, int x)
        {
            SwordObject target = _objMan.FetchObject((uint)targetId);

            if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
            {
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE]   = (uint)target.xcoord;
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_2] = (uint)target.ycoord;
            }
            else
            {
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE]   = (uint)((target.mouse_x1 + target.mouse_x2) / 2);
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_2] = (uint)target.mouse_y2;
            }
            ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_3] = (uint)target.dir;

            int megaSeperation;

            if (targetId == DUANE)
            {
                megaSeperation = 70; // George & Duane stand with feet 70 pixels apart when at full scale
            }
            else if (targetId == BENOIR)
            {
                megaSeperation = 61; // George & Benoir
            }
            else
            {
                megaSeperation = 42; // George & Nico/Goinfre stand with feet 42 pixels apart when at full scale
            }
            if ((target.status & STAT_SHRINK) != 0)
            {
                int scale = (target.scale_a * target.ycoord + target.scale_b) / 256;
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_4] = (uint)((megaSeperation * scale) / 256);
            }
            else
            {
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_4] = (uint)megaSeperation;
            }
            return(SCRIPT_CONT);
        }
Пример #32
0
 public void CheckForEvent(SwordObject compact)
 {
     for (var objCnt = 0; objCnt < SwordObject.O_TOTAL_EVENTS; objCnt++)
     {
         if (compact.event_list[objCnt].o_event != 0)
             for (var globCnt = 0; globCnt < TOTAL_EVENT_SLOTS; globCnt++)
             {
                 if (_eventPendingList[globCnt].delay != 0 &&
                         (_eventPendingList[globCnt].eventNumber == compact.event_list[objCnt].o_event))
                 {
                     compact.logic = Logic.LOGIC_script;      //force into script mode
                     _eventPendingList[globCnt].delay = 0; //started, so remove from queue
                     compact.tree.script_level++;
                     compact.tree.script_id[compact.tree.script_level] =
                         compact.event_list[objCnt].o_event_script;
                     compact.tree.script_pc[compact.tree.script_level] =
                         compact.event_list[objCnt].o_event_script;
                 }
             }
     }
 }
Пример #33
0
        private int fnTurn(SwordObject cpt, int id, int dir, int stance, int c, int d, int a, int b)
        {
            if (stance > 0)
            {
                dir = 9;
            }
            int route = _router.RouteFinder(id, cpt, cpt.xcoord, cpt.ycoord, dir);

            if (route != 0)
            {
                cpt.down_flag = 1;       //1 means ok
            }
            else
            {
                cpt.down_flag = 0;       //0 means error
            }
            cpt.logic   = LOGIC_AR_animate;
            cpt.walk_pc = 0;                     //reset

            return(SCRIPT_STOP);
        }
Пример #34
0
        private int fnBackground(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
        {

            cpt.status &= ~(STAT_FORE | STAT_SORT);
            cpt.status |= STAT_BACK;
            return SCRIPT_CONT;
        }
Пример #35
0
 private int fnFace(SwordObject cpt, int id, int targetId, int b, int c, int d, int a, int z)
 {
     SwordObject target = _objMan.FetchObject((uint)targetId);
     int x, y;
     if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
     {
         x = target.xcoord;
         y = target.ycoord;
     }
     else
     {
         x = (target.mouse_x1 + target.mouse_x2) / 2;
         y = target.mouse_y2;
     }
     int megaTarDir = WhatTarget(cpt.xcoord, cpt.ycoord, x, y);
     fnTurn(cpt, id, megaTarDir, 0, 0, 0, 0, 0);
     return SCRIPT_STOP;
 }
Пример #36
0
 private int fnStandAt(SwordObject cpt, int id, int x, int y, int dir, int stance, int a, int b)
 {
     if ((dir < 0) || (dir > 8))
     {
         // TODO: warning("fnStandAt:: invalid direction %d", dir);
         return SCRIPT_CONT;
     }
     if (dir == 8)
         dir = cpt.dir;
     cpt.xcoord = x;
     cpt.ycoord = y;
     return fnStand(cpt, id, dir, stance, 0, 0, 0, 0);
 }
Пример #37
0
 private int fnEndMenu(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     _menu.FnEndMenu();
     return SCRIPT_CONT;
 }
Пример #38
0
 private int fnRandom(SwordObject compact, int id, int min, int max, int e, int f, int z, int x)
 {
     ScriptVars[(int)ScriptVariableNames.RETURN_VALUE] = (uint)_rnd.Next(min, max);
     return SCRIPT_CONT;
 }
Пример #39
0
        private int fnGetTo(SwordObject cpt, int id, int a, int b, int c, int d, int z, int x)
        {
            SwordObject place = _objMan.FetchObject((uint)cpt.place);

            cpt.tree.script_level++;
            cpt.tree.script_pc[cpt.tree.script_level] = place.get_to_script;
            cpt.tree.script_id[cpt.tree.script_level] = place.get_to_script;
            return SCRIPT_STOP;
        }
Пример #40
0
 private int fnLeaveSection(SwordObject cpt, int id, int oldScreen, int d, int e, int f, int z, int x)
 {
     if (oldScreen >= ObjectMan.TOTAL_SECTIONS)
         throw new InvalidOperationException($"mega {id} leaving section {oldScreen}");
     _objMan.MegaLeaving((ushort) oldScreen, id);
     return SCRIPT_CONT;
 }
Пример #41
0
        private int fnEnterSection(SwordObject cpt, int id, int screen, int d, int e, int f, int z, int x)
        {
            if (screen >= ObjectMan.TOTAL_SECTIONS)
                throw new InvalidOperationException($"mega {id} tried entering section {screen}");

            /* if (cpt.o_type == TYPE_PLAYER)
               ^= this was the original condition from the game sourcecode.
               not sure why it doesn't work*/
            if (id == PLAYER)
                ScriptVars[(int)ScriptVariableNames.NEW_SCREEN] = (uint)screen;
            else
                cpt.screen = screen; // move the mega
            _objMan.MegaEntering((ushort)screen);
            return SCRIPT_CONT;
        }
Пример #42
0
 private int fnRemoveObject(SwordObject cpt, int id, int objectNo, int d, int e, int f, int z, int x)
 {
     ScriptVars[(int)ScriptVariableNames.POCKET_1 + objectNo - 1] = 0;
     return SCRIPT_CONT;
 }
Пример #43
0
 private int fnAddObject(SwordObject cpt, int id, int objectNo, int d, int e, int f, int z, int x)
 {
     ScriptVars[(int)ScriptVariableNames.POCKET_1 + objectNo - 1] = 1; // basically means: carrying object objectNo = true;
     return SCRIPT_CONT;
 }
Пример #44
0
        public int RouteFinder(int id, SwordObject megaObject, int x, int y, int dir)
        {
            int routeFlag = 0;
            int solidFlag = 0;
            WalkData[] walkAnim;

            megaId = id;

            LoadWalkResources(megaObject, x, y, dir);

            walkAnim = megaObject.route;

            _framesPerStep = (int)(_nWalkFrames / 2);
            _framesPerChar = (int)(_nWalkFrames * NO_DIRECTIONS);

            // offset pointers added Oct 30 95 JPS
            standFrames = _framesPerChar;
            turnFramesLeft = standFrames;
            turnFramesRight = standFrames;
            walkFramesLeft = 0;
            walkFramesRight = 0;
            slowInFrames = 0;
            slowOutFrames = 0;

            if (megaId == Logic.GEORGE)
            {
                turnFramesLeft = 3 * _framesPerChar + NO_DIRECTIONS + 2 * SLOW_IN + 4 * SLOW_OUT;
                turnFramesRight = 3 * _framesPerChar + NO_DIRECTIONS + 2 * SLOW_IN + 4 * SLOW_OUT + NO_DIRECTIONS;
                walkFramesLeft = _framesPerChar + NO_DIRECTIONS;
                walkFramesRight = 2 * _framesPerChar + NO_DIRECTIONS;
                slowInFrames = 3 * _framesPerChar + NO_DIRECTIONS;
                slowOutFrames = 3 * _framesPerChar + NO_DIRECTIONS + 2 * SLOW_IN;
            }
            else if (megaId == Logic.NICO)
            {
                turnFramesLeft = _framesPerChar + NO_DIRECTIONS;
                turnFramesRight = _framesPerChar + 2 * NO_DIRECTIONS;
                walkFramesLeft = 0;
                walkFramesRight = 0;
                slowInFrames = 0;
                slowOutFrames = 0;
            }

            // **************************************************************************
            // All route data now loaded start finding a route
            // **************************************************************************
            // **************************************************************************
            // Check if we can get a route through the floor        changed 12 Oct95 JPS
            // **************************************************************************

            routeFlag = GetRoute();

            switch (routeFlag)
            {
                case 2:
                    // special case for zero length route

                    // if target direction specified as any
                    if (_targetDir > 7)
                        _targetDir = _startDir;

                    // just a turn on the spot is required set an end module for
                    // the route let the animator deal with it
                    // modularPath is normally set by extractRoute

                    _modularPath[0].dir = _startDir;
                    _modularPath[0].num = 0;
                    _modularPath[0].x = _startX;
                    _modularPath[0].y = _startY;
                    _modularPath[1].dir = _targetDir;
                    _modularPath[1].num = 0;
                    _modularPath[1].x = _startX;
                    _modularPath[1].y = _startY;
                    _modularPath[2].dir = 9;
                    _modularPath[2].num = ROUTE_END_FLAG;

                    SlidyWalkAnimator(walkAnim);
                    routeFlag = 2;
                    break;
                case 1:
                    // A normal route. Convert the route to an exact path
                    SmoothestPath();

                    // The Route had waypoints and direction options

                    // The Path is an exact set of lines in 8 directions that
                    // reach the target.

                    // The path is in module format, but steps taken in each
                    // direction are not accurate

                    // if target dir = 8 then the walk isn't linked to an anim so
                    // we can create a route without sliding and miss the exact
                    // target

                    if (_targetDir == NO_DIRECTIONS)
                    {
                        // can end facing ANY direction (ie. exact end
                        // position not vital) . so use SOLID walk to
                        // avoid sliding to exact position

                        SolidPath();
                        solidFlag = SolidWalkAnimator(walkAnim);
                    }

                    if (solidFlag == 0)
                    {
                        // if we failed to create a SOLID route, do a SLIDY
                        // one instead

                        SlidyPath();
                        SlidyWalkAnimator(walkAnim);
                    }

                    break;
                default:
                    // Route didn't reach target so assume point was off the floor
                    // routeFlag = 0;
                    break;
            }

            return routeFlag;   // send back null route
        }
Пример #45
0
 private int fnFaceXy(SwordObject cpt, int id, int x, int y, int c, int d, int a, int b)
 {
     int megaTarDir = WhatTarget(cpt.xcoord, cpt.ycoord, x, y);
     fnTurn(cpt, id, megaTarDir, 0, 0, 0, 0, 0);
     return SCRIPT_STOP;
 }
Пример #46
0
 private int fnChangeFloor(SwordObject cpt, int id, int floor, int d, int e, int f, int z, int x)
 {
     cpt.place = floor;
     SwordObject floorCpt = _objMan.FetchObject((uint)floor);
     cpt.scale_a = floorCpt.scale_a;
     cpt.scale_b = floorCpt.scale_b;
     return SCRIPT_CONT;
 }
Пример #47
0
        private int fnIsFacing(SwordObject cpt, int id, int targetId, int b, int c, int d, int a, int z)
        {
            SwordObject target = _objMan.FetchObject((uint)targetId);
            int x, y, dir;
            if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
            {
                x = target.xcoord;
                y = target.ycoord;
                dir = target.dir;
            }
            else
                throw new InvalidOperationException("fnIsFacing:: Target isn't a mega");

            int lookDir = WhatTarget(x, y, cpt.xcoord, cpt.ycoord);
            lookDir -= dir;
            lookDir = Math.Abs(lookDir);

            if (lookDir > 4)
                lookDir = 8 - lookDir;

            ScriptVars[(int)ScriptVariableNames.RETURN_VALUE] = (uint)lookDir;
            return SCRIPT_STOP;
        }
Пример #48
0
        private int fnWalk(SwordObject cpt, int id, int x, int y, int dir, int stance, int a, int b)
        {
            if (stance > 0)
                dir = 9;
            cpt.walk_pc = 0;
            cpt.route[1].frame = 512; // end of sequence
            if (id == PLAYER)
                _router.SetPlayerTarget(x, y, dir, stance);

            int routeRes = _router.RouteFinder(id, cpt, x, y, dir);

            if (id == PLAYER)
            {
                if ((routeRes == 1) || (routeRes == 2))
                {
                    ScriptVars[(int)ScriptVariableNames.MEGA_ON_GRID] = 0;
                    ScriptVars[(int)ScriptVariableNames.REROUTE_GEORGE] = 0;
                }
            }
            if ((routeRes == 1) || (routeRes == 2))
            {
                cpt.down_flag = 1; // 1 means okay.
                                   // if both mouse buttons were pressed on an exit => skip george's walk
                if ((id == GEORGE) && (_mouse.TestEvent() == Mouse.MOUSE_BOTH_BUTTONS))
                {
                    int target = (int)ScriptVars[(int)ScriptVariableNames.CLICK_ID];
                    // exceptions: compacts that use hand pointers but are not actually exits
                    if ((target != LEFT_SCROLL_POINTER) && (target != RIGHT_SCROLL_POINTER) &&
                            (target != FLOOR_63) && (target != ROOF_63) && (target != GUARD_ROOF_63) &&
                            (target != LEFT_TREE_POINTER_71) && (target != RIGHT_TREE_POINTER_71))
                    {

                        target = _objMan.FetchObject(ScriptVars[(int)ScriptVariableNames.CLICK_ID]).mouse_on;
                        if ((target >= SCR_exit0) && (target <= SCR_exit9))
                        {
                            fnStandAt(cpt, id, x, y, dir, stance, 0, 0);
                            return SCRIPT_STOP;
                        }
                    }
                }
                cpt.logic = LOGIC_AR_animate;
                return SCRIPT_STOP;
            }
            else if (routeRes == 3)
                cpt.down_flag = 1; // pretend it was successful
            else
                cpt.down_flag = 0; // 0 means error

            return SCRIPT_CONT;
        }
Пример #49
0
 private int fnGetToError(SwordObject cpt, int id, int a, int b, int c, int d, int z, int x)
 {
     // TODO: debug(1, "fnGetToError: compact %d at place %d no get-to for target %d, click_id %d\n", id, cpt.o_place, cpt.o_target, ScriptVars[(int) ScriptVariableNames.CLICK_ID]);
     return SCRIPT_CONT;
 }
Пример #50
0
        private int fnTurn(SwordObject cpt, int id, int dir, int stance, int c, int d, int a, int b)
        {
            if (stance > 0)
                dir = 9;
            int route = _router.RouteFinder(id, cpt, cpt.xcoord, cpt.ycoord, dir);

            if (route != 0)
                cpt.down_flag = 1;       //1 means ok
            else
                cpt.down_flag = 0;       //0 means error

            cpt.logic = LOGIC_AR_animate;
            cpt.walk_pc = 0;                     //reset

            return SCRIPT_STOP;
        }
Пример #51
0
        private int fnGetPos(SwordObject cpt, int id, int targetId, int b, int c, int d, int z, int x)
        {
            SwordObject target = _objMan.FetchObject((uint)targetId);
            if ((target.type == Screen.TYPE_MEGA) || (target.type == Screen.TYPE_PLAYER))
            {
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE] = (uint)target.xcoord;
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_2] = (uint)target.ycoord;
            }
            else
            {
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE] = (uint)((target.mouse_x1 + target.mouse_x2) / 2);
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_2] = (uint)target.mouse_y2;
            }
            ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_3] = (uint)target.dir;

            int megaSeperation;
            if (targetId == DUANE)
                megaSeperation = 70; // George & Duane stand with feet 70 pixels apart when at full scale
            else if (targetId == BENOIR)
                megaSeperation = 61; // George & Benoir
            else
                megaSeperation = 42; // George & Nico/Goinfre stand with feet 42 pixels apart when at full scale

            if ((target.status & STAT_SHRINK) != 0)
            {
                int scale = (target.scale_a * target.ycoord + target.scale_b) / 256;
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_4] = (uint)((megaSeperation * scale) / 256);
            }
            else
                ScriptVars[(int)ScriptVariableNames.RETURN_VALUE_4] = (uint)megaSeperation;
            return SCRIPT_CONT;
        }
Пример #52
0
 private int fnStand(SwordObject cpt, int id, int dir, int stance, int c, int d, int a, int b)
 {
     if ((dir < 0) || (dir > 8))
     {
         // TODO: warning("fnStand:: invalid direction %d", dir);
         return SCRIPT_CONT;
     }
     if (dir == 8)
         dir = cpt.dir;
     cpt.resource = cpt.walk_resource;
     cpt.status |= STAT_SHRINK;
     cpt.anim_x = cpt.xcoord;
     cpt.anim_y = cpt.ycoord;
     cpt.frame = 96 + dir;
     cpt.dir = dir;
     return SCRIPT_STOP;
 }
Пример #53
0
 private int cfnReleaseMenu(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     _menu.CfnReleaseMenu();
     return SCRIPT_STOP;
 }
Пример #54
0
 private int fnChooser(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     _menu.FnChooser(cpt);
     return SCRIPT_STOP;
 }
Пример #55
0
 private int fnUnlockMouse(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     _mouse.FnUnlockMouse();
     return SCRIPT_CONT;
 }
Пример #56
0
 private int fnAddSubject(SwordObject cpt, int id, int sub, int d, int e, int f, int z, int x)
 {
     _menu.FnAddSubject(sub);
     return SCRIPT_CONT;
 }
Пример #57
0
 public void AddToList(int id, SwordObject compact)
 {
     _objList[_numObjs].id = id;
     _objList[_numObjs].compact = compact;
     _numObjs++;
 }
Пример #58
0
 private int fnSetMouseLuggage(SwordObject cpt, int id, int tag, int rate, int e, int f, int z, int x)
 {
     _mouse.SetLuggage((uint) tag, (uint) rate);
     return SCRIPT_CONT;
 }
Пример #59
0
        private int LoadWalkResources(SwordObject megaObject, int x, int y, int dir)
        {
            var floorHeader = new WalkGridHeader();
            int i;

            int floorId;
            int walkGridResourceId;
            SwordObject floorObject;

            int cnt;
            uint cntu;

            // load in floor grid for current mega

            floorId = megaObject.place;

            //floorObject = (object *)Lock_object(floorId);
            floorObject = _objMan.FetchObject((uint)floorId);
            walkGridResourceId = floorObject.resource;
            //Unlock_object(floorId);

            //ResOpen(walkGridResourceId);          // mouse wiggle
            //fPolygrid = ResLock(walkGridResourceId);          // mouse wiggle
            var fPolygrid = _resMan.OpenFetchRes((uint)walkGridResourceId);


            var fPolygridOff = Header.Size;
            Array.Copy(fPolygrid, fPolygridOff, floorHeader.Data, floorHeader.Offset, WalkGridHeader.Size);
            fPolygridOff += WalkGridHeader.Size;
            _nBars = (int)_resMan.ReadUInt32((uint)floorHeader.numBars);

            if (_nBars >= O_GRID_SIZE)
            {
#if DEBUG //Check for id > number in file,
                throw new InvalidOperationException($"RouteFinder Error too many _bars {_nBars}");
#endif
                _nBars = 0;
            }

            _nNodes = (int)(_resMan.ReadUInt32((uint)floorHeader.numNodes) + 1); //array starts at 0 begins at a start _node has nnodes nodes and a target _node

            if (_nNodes >= O_GRID_SIZE)
            {
#if DEBUG //Check for id > number in file,
                throw new InvalidOperationException($"RouteFinder Error too many nodes {_nNodes}");
#endif
                _nNodes = 0;
            }

            /*memmove(&_bars[0],fPolygrid,_nBars*sizeof(BarData));
            fPolygrid += _nBars*sizeof(BarData);//move pointer to start of _node data*/
            for (cnt = 0; cnt < _nBars; cnt++)
            {
                _bars[cnt].x1 = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].y1 = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].x2 = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].y2 = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].xmin = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].ymin = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].xmax = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].ymax = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].dx = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].dy = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _bars[cnt].co = (int)_resMan.ReadUInt32(fPolygrid.ToUInt32(fPolygridOff)); fPolygridOff += 4;
            }

            /*j = 1;// leave _node 0 for start _node
            do {
                memmove(&_node[j].x,fPolygrid,2*sizeof(int16));
                fPolygrid += 2*sizeof(int16);
                j ++;
            } while (j < _nNodes);//array starts at 0*/
            for (cnt = 1; cnt < _nNodes; cnt++)
            {
                _node[cnt].x = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
                _node[cnt].y = (short)_resMan.ReadUInt16(fPolygrid.ToUInt16(fPolygridOff)); fPolygridOff += 2;
            }

            //ResUnlock(walkGridResourceId);            // mouse wiggle
            //ResClose(walkGridResourceId);         // mouse wiggle
            _resMan.ResClose((uint)walkGridResourceId);


            // floor grid loaded

            // copy the mega structure into the local variables for use in all subroutines

            _startX = megaObject.xcoord;
            _startY = megaObject.ycoord;
            _startDir = megaObject.dir;
            _targetX = x;
            _targetY = y;
            _targetDir = dir;

            _scaleA = megaObject.scale_a;
            _scaleB = megaObject.scale_b;

            //ResOpen(megaObject.o_mega_resource);         // mouse wiggle
            //fMegaWalkData = ResLock(megaObject.o_mega_resource);         // mouse wiggle
            var fMegaWalkData = _resMan.OpenFetchRes((uint)megaObject.mega_resource);
            // Apparently this resource is in little endian in both the Mac and the PC version

            _nWalkFrames = fMegaWalkData[0];
            _nTurnFrames = fMegaWalkData[1];
            var fMegaWalkDataOff = 2;
            for (cnt = 0; cnt < NO_DIRECTIONS * (_nWalkFrames + 1 + _nTurnFrames); cnt++)
            {
                _dx[cnt] = (int)_resMan.ReadUInt32(fMegaWalkData.ToUInt32(fMegaWalkDataOff));
                fMegaWalkDataOff += 4;
            }
            for (cnt = 0; cnt < NO_DIRECTIONS * (_nWalkFrames + 1 + _nTurnFrames); cnt++)
            {
                _dy[cnt] = (int)_resMan.ReadUInt32(fMegaWalkData.ToUInt32(fMegaWalkDataOff));
                fMegaWalkDataOff += 4;
            }
            /*memmove(&_dx[0],fMegaWalkData,NO_DIRECTIONS*(_nWalkFrames+1+_nTurnFrames)*sizeof(int32));
            fMegaWalkData += NO_DIRECTIONS*(_nWalkFrames+1+_nTurnFrames)*sizeof(int32);
            memmove(&_dy[0],fMegaWalkData,NO_DIRECTIONS*(_nWalkFrames+1+_nTurnFrames)*sizeof(int32));
            fMegaWalkData += NO_DIRECTIONS*(_nWalkFrames+1+_nTurnFrames)*sizeof(int32);*/

            for (cntu = 0; cntu < NO_DIRECTIONS; cntu++)
            {
                _modX[cntu] = (int)_resMan.ReadUInt32(fMegaWalkData.ToUInt32(fMegaWalkDataOff));
                fMegaWalkDataOff += 4;
            }
            for (cntu = 0; cntu < NO_DIRECTIONS; cntu++)
            {
                _modY[cntu] = (int)_resMan.ReadUInt32(fMegaWalkData.ToUInt32(fMegaWalkDataOff));
                fMegaWalkDataOff += 4;
            }
            /*memmove(&_modX[0],fMegaWalkData,NO_DIRECTIONS*sizeof(int32));
            fMegaWalkData += NO_DIRECTIONS*sizeof(int32);
            memmove(&_modY[0],fMegaWalkData,NO_DIRECTIONS*sizeof(int32));
            fMegaWalkData += NO_DIRECTIONS*sizeof(int32);*/

            //ResUnlock(megaObject.o_mega_resource);           // mouse wiggle
            //ResClose(megaObject.o_mega_resource);            // mouse wiggle
            _resMan.ResClose((uint)megaObject.mega_resource);

            _diagonalx = _modX[3]; //36
            _diagonaly = _modY[3]; //8

            // mega data ready

            // finish setting grid by putting mega _node at begining
            // and target _node at end  and reset current values
            _node[0].x = (short)_startX;
            _node[0].y = (short)_startY;
            _node[0].level = 1;
            _node[0].prev = 0;
            _node[0].dist = 0;
            i = 1;
            do
            {
                _node[i].level = 0;
                _node[i].prev = 0;
                _node[i].dist = 9999;
                i = i + 1;
            } while (i < _nNodes);
            _node[_nNodes].x = (short)_targetX;
            _node[_nNodes].y = (short)_targetY;
            _node[_nNodes].level = 0;
            _node[_nNodes].prev = 0;
            _node[_nNodes].dist = 9999;

            return 1;
        }
Пример #60
0
 private int fnMouseOff(SwordObject cpt, int id, int c, int d, int e, int f, int z, int x)
 {
     cpt.status &= ~STAT_MOUSE;
     return SCRIPT_CONT;
 }