Porting HUDMessageOnActor to ZScript...

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Porting HUDMessageOnActor to ZScript...

Post by Major Cooke »

So I'm starting to port over this...

Code: Select all

function void HUDMessageOnActor(int tid, int range, str text, int zoffset, int colour)
{
   int dist, ang, vang, pitch, x, y;
   int HUDX = 370;
   int HUDY = 290;
   int offset = 0;
   int scale=1;
   int d4, d3, d2;
   int no_hud=0;
   
   x = getactorx(tid) - getactorx(1000);
   y = getactory(tid) - getactory(1000);

   vang = vectorangle(x,y);
   ang = (vang - GetActorAngle(1000) + 1.0) % 1.0;

   if(((vang+0.125)%0.5) > 0.25) dist = fixeddiv(y, sin(vang));
   else dist = fixeddiv(x, cos(vang));

   scale=(dist/(range*2));

   scale=scale+1.0;

   //print (f: scale);

   HUDX=FixedMul (HUDX, scale);
   HUDY=FixedMul (HUDY, scale);

   sethudsize(HUDX, HUDY, 1);

   setFont("SMALLFONT");
 
   if ((ang < 0.2 || ang > 0.8) && dist < range * 65536)
   {
      pitch = vectorangle(dist, getactorz(tid) - (getactorz(1000) + (41.0 - zoffset)));
      pitch = (pitch + GetActorPitch(1000) + 1.0) % 1.0;

      x = HUDX/2 - ((HUDX/2) * sin(ang) / cos(ang));
      y = HUDY/2 - ((HUDX/2) * sin(pitch) / cos(pitch));

      if (no_hud==0 && tid!=0 && GetActorProperty(tid,APROP_Health)>0) {hudmessage(s:text; HUDMSG_FadeOut | HUDMSG_NOTWITHFULLMAP, 900+tid, colour, (x<<16)+offset, (y<<16)+offset, 0.05);}
      if (no_hud==1 || tid==0) {hudmessage(s:""; HUDMSG_PLAIN, 900+tid, colour, (x<<16)+offset, (y<<16)+offset, 0.05);}
   }
   else
      hudmessage(s:" "; HUDMSG_PLAIN, 900, colour, 0, 0, 0);

}
...to ZScript.
(A big thank you to Isle for making this, and Caligari + Hotwax for adjustments and making this a possibility.)

The only big problem I anticipate here is de-ACS-ifying everything when it comes to doubles/floats. Haven't messed with that in a while... Is it as simple as just removing the bit shifts and * 65536 or is there more to it? That's all I really need to know, I can handle converting everything else.

(Just doing a direct port and using pointers instead of TID with a toggleable boolean to revert. No other enhancements have been planned yet.)
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Porting HUDMessageOnActor to ZScript...

Post by Caligari87 »

Unrelated sidebar: I feel should briefly mention that I did not make the original function, though just today I discovered I've apparently been credited for it at least a few times since 2008 or so. That credit should go to Isle and Hotwax, to the best of my knowledge. I mostly just put it on the wiki.

8-)
User avatar
Rachael
Posts: 13530
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Porting HUDMessageOnActor to ZScript...

Post by Rachael »

Major Cooke wrote:The only big problem I anticipate here is de-ACS-ifying everything when it comes to doubles/floats. Haven't messed with that in a while... Is it as simple as just removing the bit shifts and * 65536 or is there more to it? That's all I really need to know, I can handle converting everything else.
Almost.

Remember to use doubles (I think ZScript supports them, right?) to store the final values. As you no doubt know, fractionals in ACS are fixed precision and are simply (xxxx.xxxx * 65536) when stored as its final value.

Don't use float because you will lose some precision. Floats can no doubt store the value, yes, but they do a terrible job of it.
Post Reply

Return to “Scripting”