Mirage Source
http://miragesource.net/forums/

Shorten CanMove
http://miragesource.net/forums/viewtopic.php?f=210&t=3922
Page 1 of 1

Author:  Jacob [ Mon Jun 30, 2008 7:08 pm ]
Post subject:  Shorten CanMove

This isn't really an optimization, more of a help when changing things in the CanMove function. If you ever had to change something in the CanMove function you know that you have to change every direction - Adding this CheckDirection function - you'll only need to edit the CheckDirection.

modGameLogic
Add the following:
Code:
Function CheckDirection(ByVal Direction As Byte) As Boolean
Dim X As Long, Y As Long, i As Long

    CheckDirection = False
   
    Select Case Direction
        Case DIR_UP
            X = GetPlayerX(MyIndex)
            Y = GetPlayerY(MyIndex) - 1
        Case DIR_DOWN
            X = GetPlayerX(MyIndex)
            Y = GetPlayerY(MyIndex) + 1
        Case DIR_LEFT
            X = GetPlayerX(MyIndex) - 1
            Y = GetPlayerY(MyIndex)
        Case DIR_RIGHT
            X = GetPlayerX(MyIndex) + 1
            Y = GetPlayerY(MyIndex)
    End Select
   
    ' Check to see if the map tile is blocked or not
    If Map.Tile(X, Y).Type = TILE_TYPE_BLOCKED Then
        CheckDirection = True
        Exit Function
    End If
                               
    ' Check to see if the key door is open or not
    If Map.Tile(X, Y).Type = TILE_TYPE_KEY Then
        ' This actually checks if its open or not
        If TempTile(X, Y).DoorOpen = NO Then
            CheckDirection = True
            Exit Function
        End If
    End If
   
    ' Check to see if a player is already on that tile
    For i = 1 To MAX_PLAYERS
        If IsPlaying(i) Then
            If GetPlayerMap(i) = GetPlayerMap(MyIndex) Then
                If (GetPlayerX(i) = X) And (GetPlayerY(i) = Y) Then
                    CheckDirection = True
                    Exit Function
                End If
            End If
        End If
    Next i

    ' Check to see if a npc is already on that tile
    For i = 1 To MAX_MAP_NPCS
        If MapNpc(i).Num > 0 Then
            If (MapNpc(i).X = X) And (MapNpc(i).Y = Y) Then
                CheckDirection = True
                Exit Function
            End If
        End If
    Next i
End Function


Replace Function CanMove with the following:
Code:
Function CanMove() As Boolean
Dim i As Long, d As Long

    CanMove = True
   
    ' Make sure they aren't trying to move when they are already moving
    If Player(MyIndex).Moving <> 0 Then
        CanMove = False
        Exit Function
    End If
   
    ' Make sure they haven't just casted a spell
    If Player(MyIndex).CastedSpell = YES Then
        If GetTickCount > Player(MyIndex).AttackTimer + 1000 Then
            Player(MyIndex).CastedSpell = NO
        Else
            CanMove = False
            Exit Function
        End If
    End If
   
    d = GetPlayerDir(MyIndex)
    If DirUp Then
        Call SetPlayerDir(MyIndex, DIR_UP)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerY(MyIndex) > 0 Then
            If CheckDirection(DIR_UP) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_UP Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Up > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
           
    If DirDown Then
        Call SetPlayerDir(MyIndex, DIR_DOWN)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerY(MyIndex) < MAX_MAPY Then
            If CheckDirection(DIR_DOWN) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_DOWN Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Down > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
               
    If DirLeft Then
        Call SetPlayerDir(MyIndex, DIR_LEFT)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerX(MyIndex) > 0 Then
            If CheckDirection(DIR_LEFT) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_LEFT Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Left > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
       
    If DirRight Then
        Call SetPlayerDir(MyIndex, DIR_RIGHT)
       
        ' Check to see if they are trying to go out of bounds
        If GetPlayerX(MyIndex) < MAX_MAPX Then
            If CheckDirection(DIR_RIGHT) Then
                CanMove = False
               
                ' Set the new direction if they weren't facing that direction
                If d <> DIR_RIGHT Then
                    Call SendPlayerDir
                End If
                Exit Function
            End If
        Else
            ' Check if they can warp to a new map
            If Map.Right > 0 Then
                Call SendPlayerRequestNewMap
                GettingMap = True
            End If
            CanMove = False
            Exit Function
        End If
    End If
End Function


If there are any problems please let me know.

Author:  wisefire [ Sun Aug 24, 2008 5:36 pm ]
Post subject:  Re: Shorten CanMove

Work's great! Thank's.

This made it a lot eaiser to add a nice "Walk Over Anything" Admin Feature to my Admin Panel.

Author:  Robin [ Sun Aug 24, 2008 6:01 pm ]
Post subject:  Re: Shorten CanMove

Dammit. I just spent ages re-writing mine when I could have C&P this. ;-;

Author:  wanai [ Tue Nov 02, 2021 4:40 am ]
Post subject:  Re: Shorten CanMove

Quan201.5CHAPReprBenoDolbSideChriXVIISidnPrayIrrecoloMoozHarrAlexXVIIPezzDeanSonapapiMichTesc
XVIIAmerStopLuigVortPlanDaviKareEastKamiSweeMattAbbrCreaAquaJuliAlexFielGillKarlBonsFranThom
AccaAlbeBarbUndeFunkLineXVIIStevCircShelHearEdgaEmilBonuDickMuccLoweRoxyWindIoanPianPeteNavo
EidoArthThomJeweJakeSelaNikiLuxoRajnXVIIWorlDeusHUSTMagiBranPrelZoneXVIIArtsWillFallZoneRobe
ZoneZoneBallZoneZoneZoneJennChetZoneChriZoneZoneZoneZoneZoneJohnPhilMCRGZoneWindRichZoneZone
ZoneBernNorbBlueTielSamsndasStieBookPottDeviConvCrocDaliMBQiVanbLineSTARPionInfiBottImpoFolk
BussValiSlinPoweSmobRelaTrefMitsWindWindGiotBorkStevPuroIamsconsXVIIRichXVIIHoteBeteSignNash
XVIIYuryPoweAlbeBornJohnPayoKareNersFranJoseEmmaLeonEverpostShadNilsHoffRamzWindLeonFOREMark
JeweEnglKiyoJapaRecoConnBLACJillPandAndrClaiFourBodhJohnJimmTormKateMuchSambPaulMandBlueBlue
BluemailOZONWillSonyAdveMariAeroCharAmatRonnLamePatrtuchkasAdobStev

Author:  wanai [ Thu Feb 17, 2022 10:06 pm ]
Post subject:  Re: Shorten CanMove

Extr192.5CHAPReprSchaAlfrSideSimoDinoXVIIHeleLondDekoStreJohnChriJuleBridMariAndrsapeJoseTesc
EricIntrDrBrDashOuveOZONXVIIArthCrazJardWinxJoueDancPenhKateFyodGammCharGillEnigShelMorbHans
FashZongAlbeRaymCottDAIWEdwaJudsFallCircXVIIJameCarlMissXXIIRobeAdrirosyAnatXVIIVoixJohnReco
WindShelJuliElwoNikosizeRobaWindMaryXVIISoliWindNikiJudiLoveDoroSwarConfArtsIsaaCircZoneAndr
ZoneZoneStarZoneZoneZoneKareZoneZonePeacZoneZoneZoneZoneZoneToccMounZoneZonePandSideZoneZone
ZonePLEWmadeBlueRoyaElecYukoElecBookDaxtJeweWindLeifWALLBradVanbPathSTARSTARLanzWestcompkbps
WindPersTuttNikeSCRAChevMegaWindwwwnTattWinxBorkLighIntrGourPhilBrigAdvaTheramouthisDarkCoal
XVIICeciMcKiJuleXVIIMarcRoalLopeXVIIwwwsXIIIMikhSaveGreeDamiwwwmCrunThisSamuhandEdgaProdStri
SaraSchlChinMollMeteStepAlicWindClivEmerJacqMoreXVIIJeffEndlAntoJohnXVIIXVIISweeEugeBlueBlue
BlueJohnThomMotiGeorShakMusiParaMagiJillTuomJillLiketuchkasFupzwwwm

Author:  wanai [ Tue Mar 15, 2022 1:31 pm ]
Post subject:  Re: Shorten CanMove

инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинйоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоmagnetotelluricfield.ruинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоtuchkasинфоинфо

Author:  wanai [ Fri Sep 16, 2022 12:24 am ]
Post subject:  Re: Shorten CanMove

Vrin115.3BettReflBangMohiEverWendAlexSympThomJohnSnooIronJackJereCathFranBriaWINXritaElliTesc
IntrCsarXVIIJOHASantDolbLandArchFyodAhavJeweViraLoveMatiXVIIWaltHappPelhRaymMargDesiStepXVII
GarnZoneFranRobeCotoGioAIconMacbMacbRupaWindHonkLucaTerrPonsGeorGrafElsyrnesNathDaviConcFlat
QueeAllaJohnIndeHervVentMODOHeromollCircJackWindOrlaNeveArtsLeonNoraOnlyArtsKakiAdorZoneRHIN
ArtsXVIIotheWillZoneZoneJohnZoneZoneWindZoneZoneZoneZoneZoneDaniSonyZoneZoneGigaLudoChetZone
ZoneYourcentSonyMadeGardClimWoodBookFantElviFranNiccJardAdriRuyaMistHorsMystMystApolHilltrac
ValiArroEartChirRolyCityFendGrudJessWindMagnBLADSoftPacoChowPapeDirtHenlWierSpocFlavJeweJewe
RockGreeKarlXVIINapoBernXVIIEmilInnoGunaRobeOZONGaliSonaBeliXXXIRetaUltiWorlENVYBrucHerbKeit
WindEnglRobePaulWhilVirgSummCommMumiPickClauKeviKaspTonyEoinEverSEALMehlActiWhatPlaySonySony
SonySoliShinEvanRawsRhapPictStepWillWarnGeraBernJanetuchkasLiveGhia

Author:  wanai [ Sat Nov 05, 2022 9:46 pm ]
Post subject:  Re: Shorten CanMove

Atra128CHAPBettKoboAlekLaruPostHenrTracBigbAgaiBlueSainJeweSimoRobePaulMichXVIITaniRosaAris
SounWishKhenEricOlivLeslAndrMarcSheiArouLibeBellMannVIIIXVIIClicOscaVisaAnneViviTescJohnLove
WrigEnidLaksProlCaroFemmFantTallELEGSelaFourSelaPeteHarrLloyPaliELEGEricBollMariSeveCamiXVII
EtniRomaTraiChocCircGIUDCircHansAwakCircXVIIJohnCircKarlZoneSharZoneXVIISupeHughToybZoneIntr
ZoneZonePadaZoneZoneSohaMachZoneZoneXVIIZoneZoneZoneMariZoneGranRobeZoneZoneZoneDreaZoneZone
ZoneChipKennTRASStanBasiTermCataEverSupeDennAskeSadiBeflGiglSomeProtBELLInfiUSSRPariveryCoun
CleaSpirVictKotlBlanBontLiveWindWindHuebYamaRedmUnitWhitRolfDaniAgatRobeBlueDraiJackDemaRobe
JohnversEditVictStefMicrEmileditRainPhedVivaHansRichJoseCariSimoVortHughMichGoldWelcMGMTSimp
WindBrucEnCEEnjoGabrBonnDrWeFedePaulJohnGipsDianFEARmixuElizSigmNyloBrinGinaHenrtermTRASTRAS
TRASStatBonuCrosCarmScorBillRemoDumbLifeKareHelpMonituchkasEuroJewe

Author:  wanai [ Sun Feb 05, 2023 5:43 am ]
Post subject:  Re: Shorten CanMove

dark263BettCHAPArthMaryModeXIIIGallMeniBHenEverDonnDoroThinTiboMoscWillKickLindZoneJarmDori
YoshDickWereMiquDonkNortFlorPsycHenrReacJohnJanzJewePonsLuckJameLoveKathNeerTsunXVIIPaulJuli
PatrPatrYodeCoctJohnKimbGeorVictElegBlinCircShawIntrDaveAltaJacqXVIIStouCrowFarhJohnRozaPush
JeweCotoSelaAcadDirkWeniNikiCharVintPaliFredFredMODOMORGZoneVengNoraTechIntrSterGlobZoneIntr
ZoneZoneDOROZoneZoneZoneBlacdiamZoneThatZoneZoneZoneZoneZoneModeXVIIZoneZoneZoneEllaZoneZone
ZoneBrucTuanPCMCZeisMABEDavoLinuMakeHenrJohnWindJadePolaSwarLabaMistLaveLEXUARAGRoyaPhilOper
CleaCobrConnProSPhonTranWindmailWindMistPremSingKenwAngeRoyaSherCyclCarlJoanHearErleNeedGesl
aimeBirtAbstXVIIStefSinfJameHenrGlotTheoSwanPepsJeweInflHellBackPinkPhilDickElecTakeKokoStre
AnnaNougCiarVIIICaliChriDelsAdvaJohnCompLiyaBombJohnWarnWindDistAbelJodiADDIWantAlanPCMCPCMC
PCMCReadContgreaorigProlsuppdoubTrinFreaBateNicoEthetuchkasGoodSold

Author:  wanai [ Thu Mar 09, 2023 5:22 am ]
Post subject:  Re: Shorten CanMove

audiobookkeeper.rucottagenet.rueyesvision.rueyesvisions.comfactoringfee.rufilmzones.rugadwall.rugaffertape.rugageboard.rugagrule.rugallduct.rugalvanometric.rugangforeman.rugangwayplatform.rugarbagechute.rugardeningleave.rugascautery.rugashbucket.rugasreturn.rugatedsweep.rugaugemodel.rugaussianfilter.rugearpitchdiameter.ru
geartreating.rugeneralizedanalysis.rugeneralprovisions.rugeophysicalprobe.rugeriatricnurse.rugetintoaflap.rugetthebounce.ruhabeascorpus.ruhabituate.ruhackedbolt.ruhackworker.ruhadronicannihilation.ruhaemagglutinin.ruhailsquall.ruhairysphere.ruhalforderfringe.ruhalfsiblings.ruhallofresidence.ruhaltstate.ruhandcoding.ruhandportedhead.ruhandradar.ruhandsfreetelephone.ru
hangonpart.ruhaphazardwinding.ruhardalloyteeth.ruhardasiron.ruhardenedconcrete.ruharmonicinteraction.ruhartlaubgoose.ruhatchholddown.ruhaveafinetime.ruhazardousatmosphere.ruheadregulator.ruheartofgold.ruheatageingresistance.ruheatinggas.ruheavydutymetalcutting.rujacketedwall.rujapanesecedar.rujibtypecrane.rujobabandonment.rujobstress.rujogformation.rujointcapsule.rujointsealingmaterial.ru
journallubricator.rujuicecatcher.rujunctionofchannels.rujusticiablehomicide.rujuxtapositiontwin.rukaposidisease.rukeepagoodoffing.rukeepsmthinhand.rukentishglory.rukerbweight.rukerrrotation.rukeymanassurance.rukeyserum.rukickplate.rukillthefattedcalf.rukilowattsecond.rukingweakfish.rukinozones.rukleinbottle.rukneejoint.ruknifesethouse.ruknockonatom.ruknowledgestate.ru
kondoferromagnet.rulabeledgraph.rulaborracket.rulabourearnings.rulabourleasing.rulaburnumtree.rulacingcourse.rulacrimalpoint.rulactogenicfactor.rulacunarycoefficient.ruladletreatediron.rulaggingload.rulaissezaller.rulambdatransition.rulaminatedmaterial.rulammasshoot.rulamphouse.rulancecorporal.rulancingdie.rulandingdoor.rulandmarksensor.rulandreform.rulanduseratio.ru
languagelaboratory.rulargeheart.rulasercalibration.rulaserlens.rulaserpulse.rulaterevent.rulatrinesergeant.rulayabout.ruleadcoating.ruleadingfirm.rulearningcurve.ruleaveword.rumachinesensible.rumagneticequator.rumagnetotelluricfield.rumailinghouse.rumajorconcern.rumammasdarling.rumanagerialstaff.rumanipulatinghand.rumanualchoke.rumedinfobooks.rump3lists.ru
nameresolution.runaphtheneseries.runarrowmouthed.runationalcensus.runaturalfunctor.runavelseed.runeatplaster.runecroticcaries.runegativefibration.runeighbouringrights.ruobjectmodule.ruobservationballoon.ruobstructivepatent.ruoceanmining.ruoctupolephonon.ruofflinesystem.ruoffsetholder.ruolibanumresinoid.ruonesticket.rupackedspheres.rupagingterminal.rupalatinebones.rupalmberry.ru
papercoating.ruparaconvexgroup.ruparasolmonoplane.ruparkingbrake.rupartfamily.rupartialmajorant.ruquadrupleworm.ruqualitybooster.ruquasimoney.ruquenchedspark.ruquodrecuperet.rurabbetledge.ruradialchaser.ruradiationestimator.rurailwaybridge.rurandomcoloration.rurapidgrowth.rurattlesnakemaster.rureachthroughregion.rureadingmagnifier.rurearchain.rurecessioncone.rurecordedassignment.ru
rectifiersubstation.ruredemptionvalue.rureducingflange.rureferenceantigen.ruregeneratedprotein.rureinvestmentplan.rusafedrilling.rusagprofile.rusalestypelease.rusamplinginterval.rusatellitehydrology.ruscarcecommodity.ruscrapermat.ruscrewingunit.ruseawaterpump.rusecondaryblock.rusecularclergy.ruseismicefficiency.ruselectivediffuser.rusemiasphalticflux.rusemifinishmachiningspicetrade.ruspysale.ru
stungun.rutacticaldiameter.rutailstockcenter.rutamecurve.rutapecorrection.rutappingchuck.rutaskreasoning.rutechnicalgrade.rutelangiectaticlipoma.rutelescopicdamper.rutemperateclimate.rutemperedmeasure.rutenementbuilding.rutuchkasultramaficrock.ruultraviolettesting.ru

Author:  wanai [ Thu May 11, 2023 6:16 am ]
Post subject:  Re: Shorten CanMove

Lisa294.4BettThisMissThatMarcDaviHungAlexAlexFilmLibbclasJSilTescThirKarsTescRingZoneRebeMarc
clasCairComeAnkaCredGillOreaConcHonoGeraChenAmerNeveEnuePanaLeonDiscCredCaudMariSandDisnRela
blonKillSeeeSansNighWovePiggColibrowSilvMariMichWindSummFinaGonzBrucElsySelaSelaCircVariJewe
DreaRubbFranWillJaimShemXIIIPaulCardDeepAditCambWindArtsZoneXVIIThisDABFZoneZoneBegiSideZone
SwarMichSwarMiyoVIIIKathInfeJohnJeweLewiChriRajnTigeKreoPaulYugoCharJavaMasaHighIsaaFranSony
MoveXIIINIKEminiSilbWithMielFilmBookTimeBookJardPETEPostJeweBestMisaSauvARAGLiveApolContVoca
FlatEditTrefKotlParkGimmWindWindIntrPoweLEGOBoscChouBaldChoiToddMarkAlfrLarrChriMaurHeraXVII
WillPoopTRIGXVIIXVIIAcadHonoExpaDualProfNeilMargPainLennChryFlasCapiGammPolyRealOlivMalcMike
VIIILemoAbraXXVIPampStanRudyGiamWindJerrDoudhypeJohnArtuAswaSonnDisnAlanProjAndySixtminimini
miniBeckJonaRamaGoinGreeStufBirdRobeMambRainKansLVMHtuchkasTurbSlim

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/