NScumm.Sword1.Logic.fnAnim C# (CSharp) Method

fnAnim() private method

private fnAnim ( SwordObject cpt, int id, int cdt, int spr, int e, int f, int z, int x ) : int
cpt SwordObject
id int
cdt int
spr int
e int
f int
z int
x int
return int
        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;
        }