• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Cinema

Level 17
Joined
Dec 11, 2014
Messages
2,004
The system is yet unfinished, and has some weird and useless methods (Cinema.preload("meh") for example). I will change the code in the future hopefully.

Tell me if you encounter any bugs.

System code:

JASS:
library Cinema requires TimerUtils
    globals //Privates
        private integer FuncNum = 0
        private integer ActNum = 1
        private real TimeScale = 0
    endglobals
    
    globals //Globals
        location array ShapePoint
        real Time = 0
        boolean UseSoundDur = true
        boolean IsInFade
        string BlackFade =           "ReplaceableTextures\\CameraMasks\\Black_mask.blp"
        string WhiteFade =           "ReplaceableTextures\\CameraMasks\\White_mask.blp"
        string GroundFade =          "ReplaceableTextures\\CameraMasks\\GroundFog_mask.blp"
        string HazeFade =            "ReplaceableTextures\\CameraMasks\\HazeFilter_mask.blp"
        string HazeFogFade =         "ReplaceableTextures\\CameraMasks\\HazeAndFogFilter_Mask.blp"
        string DiagonalSlashFade =   "ReplaceableTextures\\CameraMasks\\DiagonalSlash_mask.blp"
        string DreamFade =           "ReplaceableTextures\\CameraMasks\\DreamFilter_Mask.blp"
        string ScopeFade =           "ReplaceableTextures\\CameraMasks\\Scope_Mask.blp"
        string PowFade =             "ReplaceableTextures\\CameraMasks\\SpecialPowMask.blp"
        string SplatFade =           "ReplaceableTextures\\CameraMasks\\SpecialSplatMask.blp"
        string PandaFade =           "ReplaceableTextures\\CameraMasks\\Panda-n-Cub.blp"
    endglobals
    
    //! textmacro Func takes ActIndex, FuncIndex, Wait
    function Act$ActIndex$F$FuncIndex$ takes nothing returns nothing
        local real WAIT = $Wait$
    //! endtextmacro
    
    //! textmacro EndFunc
        call Cinema.wait(WAIT)
    endfunction
    //! endtextmacro
    
    //! textmacro cam takes c, d
        call CameraSetupApplyForceDuration(gg_cam_Camera_$c$, true, $d$)
    //! endtextmacro

    struct Slide
        unit SlideUnit
        real SlideReal
    endstruct

    struct Wait
        conditionfunc codeRun
    endstruct

    struct Cinema extends array
        private static unit tempU

        implement Alloc

        static method changeAct takes integer act returns nothing
            set ActNum = act
            set FuncNum = 0
        endmethod
        
        private static method waitCall takes nothing returns nothing
            call DestroyTimer(GetExpiredTimer())
            set FuncNum = FuncNum + 1
            call ExecuteFunc("Act" + I2S(ActNum) + "F" + I2S(FuncNum))
        endmethod

        static method wait takes real sec returns nothing
            set Time = Time + sec
            call TimerStart(CreateTimer(), sec, false, function Cinema.waitCall)
        endmethod

        static method waitExCall takes nothing returns nothing
            local trigger tr = CreateTrigger()
            local timer t = GetExpiredTimer()
            local Wait w = thistype(GetTimerData(t))

            call TriggerAddCondition(tr, w.codeRun)
            call TriggerEvaluate(tr)

            call DestroyTimer(t)
            call DestroyTrigger(tr)
            call w.destroy()
            set t = null
            set tr = null
        endmethod

        static method waitEx takes real sec, code func returns nothing
            local Wait w = Wait.create()
            call TimerStart(NewTimerEx(integer(w)), sec, false, function Cinema.waitExCall)
            set w.codeRun = Condition(func)
        endmethod

        static method fade takes integer fadetype, real duration, string tex, real Red, real Green, real Blue, real Trans returns nothing
            local integer red = R2I(Red)
            local integer green = R2I(Green)
            local integer blue = R2I(Blue)
            local integer trans = R2I(Trans)

            if (bj_cineFadeContinueTimer != null) then
                call DestroyTimer(bj_cineFadeContinueTimer)
            endif

            if (bj_cineFadeFinishTimer != null) then
                call DestroyTimer(bj_cineFadeFinishTimer)
            endif

            call EnableUserUI(false)
            call SetCineFilterTexture(tex)
            call SetCineFilterBlendMode(BLEND_MODE_BLEND)
            call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
            call SetCineFilterStartUV(0, 0, 1, 1)
            call SetCineFilterEndUV(0, 0, 1, 1)
            call SetCineFilterStartColor(red, green, blue, 255-trans)
            call SetCineFilterEndColor(red, green, blue, 0)
            call SetCineFilterDuration(duration)
            call DisplayCineFilter(true)

            if (fadetype == 1) then
                set IsInFade = true
                call SetCineFilterStartColor(red, green, blue, 0)
                call SetCineFilterEndColor(red, green, blue, 255-trans)
            elseif (fadetype == 2) then
                set IsInFade = false
                call SetCineFilterStartColor(red, green, blue, 255-trans)
                call SetCineFilterEndColor(red, green, blue, 0)
                set bj_cineFadeFinishTimer = CreateTimer()
                call TimerStart(bj_cineFadeFinishTimer, duration, false, function FinishCinematicFadeBJ)
            endif
        endmethod
        
        static method clearMsg takes nothing returns nothing
            call DestroyTimer(GetExpiredTimer())
            call ClearTextMessages()
        endmethod

        static method talk takes string s, real dur, sound snd returns nothing
            local real x = 1 - (I2R(StringLength(s))*.004)
            local real y = (R2I(I2R(StringLength(s))/70) + 1)*.1

            if snd != null then
                call StartSound(snd)
                if UseSoundDur then
                    set dur = I2R(GetSoundDuration(snd))*.001
                endif
            endif

            call TimerStart(CreateTimer(), dur, false, function Cinema.clearMsg)
            call DisplayTimedTextToPlayer(Player(0), x, y, dur - 0.1, "\n\n\n\n\n\n" + s + "\n\n\n\n\n\n\n\n\n\n\n\n")
        endmethod
        
        private static method goDown takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local Slide s = thistype(GetTimerData(t))

            call SetUnitFlyHeight(s.SlideUnit, 0, (GetUnitFlyHeight(s.SlideUnit) / s.SlideReal))
            set s.SlideUnit = null
            set s.SlideReal = 0
            call s.destroy()
            call ReleaseTimer(t)

            set t = null
        endmethod

        static method slide takes unit u, real height, real dur, location where returns nothing
            local location l = GetUnitLoc(u)
            local real ddur = dur / 2
            local real dx = GetLocationX(where) - GetLocationX(l)
            local real dy = GetLocationY(where) - GetLocationY(l)
            local Slide s

            if height > 0 then
                if height != 0 then
                    set s = Slide.create()
                    set s.SlideUnit = u
                    set s.SlideReal = ddur
                    call SetUnitFlyHeight(u, height, height / ddur)
                    call TimerStart(NewTimerEx(integer(s)), ddur, false, function Cinema.goDown)
                endif

                set udg_Knockback2DAngle = bj_RADTODEG * Atan2(GetLocationY(where) - GetLocationY(l), GetLocationX(where) - GetLocationX(l))
                set udg_Knockback2DTime = dur
                set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
                set udg_Knockback2DUnit = u
                set udg_Knockback2DCollision = -1.00
                set udg_Knockback2DSimple = true
                call TriggerExecute(gg_trg_Knockback_2D)
            endif

            call RemoveLocation(l)
            set l = null
        endmethod

        static method createEqualShape takes location center, real radius, integer points returns nothing
            local real x
            local real y
            local integer i = 1
            loop
                exitwhen i > points
                set x = GetLocationX(center) + radius * Cos(360 / points * i * bj_DEGTORAD)
                set y = GetLocationY(center) + radius * Sin(360 / points * i * bj_DEGTORAD)
                set ShapePoint[i] = Location(x, y)
                set i = i + 1
            endloop
        endmethod

        static method look takes unit u, real startx, real starty, real startz, real endx, real endy, real endz, real dur returns nothing
            local location l = Location(startx, starty)
            local unit dum = CreateUnitAtLoc(Player(15), 'n000', l, 270)
            local real dx = endx - startx
            local real dy = endy - starty

            set udg_Knockback2DAngle = bj_RADTODEG * Atan2(dy, dx)
            set udg_Knockback2DTime = dur
            set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
            set udg_Knockback2DUnit = dum
            set udg_Knockback2DCollision = -1.00
            set udg_Knockback2DSimple = true
            call TriggerExecute(gg_trg_Knockback_2D)
            call SetUnitFlyHeight(dum, startz, 0)

            if dur == 0 then
                call SetUnitFlyHeight(dum, endz, 0)
            else
                call SetUnitFlyHeight(dum, endz, endz / dur)
            endif

            call SetUnitLookAt(u, "bone_head", dum, 0, 0, 0)
            call RemoveLocation(l)
            set l = null
            set dum = null
        endmethod

        static method walk takes unit u, real x, real y, real d returns nothing
            local real dx = x - GetUnitX(u)
            local real dy = y - GetUnitY(u)

            set udg_Knockback2DAngle = bj_RADTODEG * Atan2(dy, dx)
            set udg_Knockback2DTime = d
            set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
            set udg_Knockback2DUnit = u
            set udg_Knockback2DCollision = -1.00
            set udg_Knockback2DSimple = true
            call TriggerExecute(gg_trg_Knockback_2D)
        endmethod

        private static method slowMotionFG takes nothing returns nothing
            call SetUnitTimeScale(GetEnumUnit(), TimeScale)
        endmethod

        static method slowMotion takes real s returns nothing
            local group g = CreateGroup()

            call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
            set TimeScale = s
            call ForGroup(g, function Cinema.slowMotionFG)

            call DestroyGroup(g)
        endmethod

        static method startPreload takes nothing returns nothing
            set Cinema.tempU = CreateUnit(Player(0), 'n000', 0, 0, 0) 
        endmethod
        
        static method preload takes string path returns nothing
            call Preload(path)
        endmethod
        
        static method preloadAbility takes integer abil returns nothing
            call UnitAddAbility(Cinema.tempU, abil)
            call UnitRemoveAbility(Cinema.tempU, abil)
        endmethod
        
        static method endPreload takes nothing returns nothing
            call RemoveUnit(Cinema.tempU)
            set Cinema.tempU = null
        endmethod
        
        static method clearMusic takes boolean fade returns nothing
            call ClearMapMusic()
            call StopMusic(fade)
        endmethod
        
        static method startMusic takes string path, boolean fade returns nothing
            call ClearMapMusic()
            call StopMusic(fade)
            call PlayMusic(path)
        endmethod
    endstruct
endlibrary

//WARNING: Touch if you know what you're doing.
//Chaosy, here I know that you do :D
//Just change Anything-AnyFile.mp3 with your music path, and it will be played in the lobby.

//! inject config
    call SetPlayers(1)
   
    call DefineStartLocation(0, 704.0, - 832.0)

    call InitCustomPlayerSlots()

    call PlayMusic("Anything-AnyFile.mp3")
//! endinject

About the demo:

It is an unfinished demo, which template was made by Keiji (Saga).
It has an example of what you can do with it.

Attachments

  • Saga.w3x
    27.3 MB · Views: 2
Top