Skip to content

Commit

Permalink
- Crane scriptification WIP
Browse files Browse the repository at this point in the history
Still a lot of stuff to do.
  • Loading branch information
coelckers committed Feb 19, 2022
1 parent 4d13408 commit 03bf964
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 23 deletions.
4 changes: 4 additions & 0 deletions source/core/coreactor.h
Expand Up @@ -156,6 +156,10 @@ class DCoreActor : public DObject
return spr.sectp ? ::sector.IndexOf(spr.sectp) : -1;
}

auto spriteset() const
{
return static_cast<PClassActor*>(GetClass())->ActorInfo()->SpriteSet;
}

};

Expand Down
4 changes: 3 additions & 1 deletion source/games/duke/src/spawn_d.cpp
Expand Up @@ -45,7 +45,9 @@ DDukeActor* spawninit_d(DDukeActor* actj, DDukeActor* act, TArray<DDukeActor*>*
{
if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
CallOnSpawn(act);
auto sset = act->spriteset();
if (sset.Size() > 0) act->spr.picnum = sset[0];
CallInitialize(act);
return act;
}
auto sectp = act->sector();
Expand Down
2 changes: 2 additions & 0 deletions source/games/duke/src/spawn_r.cpp
Expand Up @@ -39,6 +39,8 @@ DDukeActor* spawninit_r(DDukeActor* actj, DDukeActor* act, TArray<DDukeActor*>*
{
if (act->GetClass() != RUNTIME_CLASS(DDukeActor))
{
auto sset = act->spriteset();
if (sset.Size() > 0) act->spr.picnum = sset[0];
CallInitialize(act);
return act;
}
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript.txt
Expand Up @@ -46,7 +46,7 @@ version "4.3"
#include "zscript/games/duke/ui/screens.zs"
#include "zscript/games/duke/ui/cutscenes.zs"
#include "zscript/games/duke/ui/menu.zs"
#include "zscript/games/duke/actors/dukeactor.zs"
#include "zscript/games/duke/actors/crane.zs"

#include "zscript/games/blood/bloodgame.zs"
#include "zscript/games/blood/ui/menu.zs"
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/zscript/coreactor.zs
Expand Up @@ -33,6 +33,7 @@ class CoreActor native
native uint8 renderflags;
native float alpha;

native readonly sectortype sector
native readonly int16 spritesetpic;
native readonly int spawnindex;

Expand Down
16 changes: 0 additions & 16 deletions wadsrc/static/zscript/games/duke/actors/DukeActor.zs

This file was deleted.

249 changes: 249 additions & 0 deletions wadsrc/static/zscript/games/duke/actors/crane.zs
@@ -0,0 +1,249 @@

class DukeCrane : DukeActor
{
default
{
spriteset "CRANE", "CRANE1", "CRANE2";
statnum STAT_STANDABLE;
}

enum EPic
{
PIC_DEFAULT = 0,
PIC_OPEN = 1,
PIC_CLOSED = 2,
}

Vector3 cranepos;
Vector2 polepos;
DukeCranePole poleactor;

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

override void Initialize()
{
let sect = sector;
cstat |= CSTAT_SPRITE_BLOCK_ALL | CSTAT_SPRITE_ONE_SIDE;

setspritepic(PIC_CLOSED);
SetZ(sect.ceilingz + 48);

cranepos = act.pos;
poleactor = null;

let it = DukeLevel.CreateStatIterator(STAT_DEFAULT);
for(DukeActor actk; actk = it.Next();)
{
if (hitag == hitag && actk is "DukeCranePole")
{
poleactor = actk;

temp_sect = actk.sector;

actk.xrepeat = 48;
actk.yrepeat = 128;
actk.shade = shade;

polepos = actk.xy();
actk.copypos(self);
break;
}
}

ownerActor = null;
extra = 8;
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

override void Tick()
{
int x;
let pos = self.pos();

//temp_data[0] = state
//temp_data[1] = checking sector number

if (xvel) getglobalz();

if (temp_data[0] == 0) //Waiting to check the sector
{
let it = DukeLevel.CreateSectIterator(temp_sect);
for(DukeActor a2; a2 = it.Next();)
{
switch (a2.statnum)
{
case STAT_ACTOR:
case STAT_ZOMBIEACTOR:
case STAT_STANDABLE:
case STAT_PLAYER:
ang = getangle(polepos.X - pos.X, polepos.Y - pos.Y);
a2.SetPosition(( polepos.X, polepos.Y, a2.Z() ));
temp_data[0]++;
return;
}
}
}

else if (temp_data[0] == 1)
{
if (xvel < 184)
{
setSpritePic(PIC_OPEN);
xvel += 8;
}
//IFMOVING; // JBF 20040825: see my rant above about this
ssp(CLIPMASK0);
if (sector == temp_sect)
temp_data[0]++;
}
else if (temp_data[0] == 2 || temp_data[0] == 7)
{
addZ(4 + 2);

if (temp_data[0] == 2)
{
if ((sector.floorz() - pos.Z) < 64)
if (spritesetpic > 0) setspritepic(spritesetpic - 1);

if ((sector.floorz() - pos.Z) < (16 + 4))
temp_data[0]++;
}
if (temp_data[0] == 7)
{
if ((sector.floorz() - pos.Z) < 64)
{
if (spritesetpic > 0) setspritepic(spritesetpic - 1);
else
{
if (IsActiveCrane())
{
int p = findplayer(actor);
ps[p].actor.PlayActorSound(isRR() ? 390 : DUKE_GRUNT);
if (ps[p].on_crane == actor)
ps[p].on_crane = null;
}
temp_data[0]++;
SetActiveCrane(false);
}
}
}
}
else if (temp_data[0] == 3)
{
setspritepic(spritesetpic + 1);
if (spritesetpic == 2)
{
int p = checkcursectnums(temp_sect);
if (p >= 0 && ps[p].on_ground)
{
SetActiveCrane(true);
ps[p].on_crane = actor;
ps[p].actor.PlayActorSound(isRR() ? 390 : DUKE_GRUNT);
ps[p].angle.settarget(ang + 1024);
}
else
{
let it = DukeLevel.CreateSectIterator(temp_sect);
for(DukeActor a2; a2 = it.Next();)
{
switch (a2.statnum)
{
case 1:
case 6:
SetOwner(a2);
break;
}
}
}

temp_data[0]++;//Grabbed the sprite
temp_data[2] = 0;
return;
}
}
else if (temp_data[0] == 4) //Delay before going up
{
temp_data[2]++;
if (temp_data[2] > 10)
temp_data[0]++;
}
else if (temp_data[0] == 5 || temp_data[0] == 8)
{
if (temp_data[0] == 8 && spritesetpic < 2)
if ((sector.floorz - pos.Z) > 32)
setspritepic(spritesetpic + 1);

if (pos.Z < cranepos.Z)
{
temp_data[0]++;
xvel = 0;
}
else
addZ(4 + 2);
}
else if (temp_data[0] == 6)
{
if (xvel < 192)
xvel += 8;
ang = getangle(cranepos.X - pos.X, cranepos.Y - pos.Y);
ssp(actor, CLIPMASK0);
if (((pos.X - cranepos.X) * (pos.X - cranepos.X) + (pos.Y - cranepos.Y) * (pos.Y - cranepos.Y)) < (0.5 * 0.5))
temp_data[0]++;
}

else if (temp_data[0] == 9)
temp_data[0] = 0;

if (poleactor)
poleactor.SetActor(poleactor, (pos.X, pos.Y, pos.Z - 34));

if (Owner != null || IsActiveCrane())
{
int p = findplayer(actor);

int j = ifhitbyweapon();
if (j >= 0)
{
if (IsActiveCrane())
if (ps[p].on_crane == actor)
ps[p].on_crane = null;
SetActiveCrane(false);
setspritepic(0);
return;
}

if (Owner != null)
{
SetActor(Owner, pos);
Owner.backuppos();
zvel = 0;
}
else if (IsActiveCrane())
{
let ang = ps[p].angleAsBuild(); // temporary hack
ps[p].backuppos();
let newpos = (pos.X - bcos(ang, -6), pos.Y - bsin(ang, -6), pos.Z + 2);
ps[p].setposition(newpos);
ps[p].actor.SetPosition(newpos);
ps[p].cursector = ps[p].actor.sectp;
}
}
}
}

class DukeCranePole : DukeActor
{
default
{
spriteset "CRANEPOLE";
}
}
5 changes: 3 additions & 2 deletions wadsrc/static/zscript/games/duke/dukeactor.zs
Expand Up @@ -67,8 +67,9 @@ class DukeActor : CoreActor native


virtual void BeginPlay() {}
virtual bool Tick() { return false; }

virtual void Initialize() {}
virtual void Tick() {}
virtual void RunState() {} // this is the CON function.
}

extend struct _
Expand Down
3 changes: 0 additions & 3 deletions wadsrc/static/zscript/razebase.zs
Expand Up @@ -230,6 +230,3 @@ class RazeMenuDelegate : MenuDelegateBase
native override void MenuDismissed();

}
class CoreActor native
{
}

0 comments on commit 03bf964

Please sign in to comment.