]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
q3compat: add support for the target_print entity
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 17 Feb 2023 21:21:43 +0000 (22:21 +0100)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 17 Feb 2023 23:19:28 +0000 (00:19 +0100)
qcsrc/server/compat/quake3.qc

index 9333ebfed50973872e0c0111aba93b4886cde5eb..3dd651e49bd4c1eadcfa96f65102a1f4a8b68c3b 100644 (file)
@@ -272,6 +272,76 @@ spawnfunc(target_fragsFilter)
        this.use = fragsfilter_use;
 }
 
+#define PRINT_REDTEAM BIT(0) // Q3 only, not used in Q3DF
+#define PRINT_BLUETEAM BIT(1) // Q3 only, not used in Q3DF
+#define PRINT_PRIVATE BIT(2) // Q3 only, not used in Q3DF
+#define PRINT_BROADCAST BIT(3) // Q3DF only, default behavior in Q3
+
+void target_print_message(entity this, entity actor)
+{
+       centerprint(actor, this.message);
+       play2(actor, SND(TALK));
+}
+
+void target_print_use(entity this, entity actor, entity trigger)
+{
+       if(!IS_PLAYER(actor))
+               return;
+
+       if(this.message == "")
+               return;
+
+       bool priv, red, blue;
+       if(g_cts || g_race) // use Q3DF spawnflags in race game modes
+       {
+               priv = !boolean(this.spawnflags & PRINT_BROADCAST);
+               red = blue = false;
+       }
+       else // use vanilla Q3 spawnflags otherwise
+       {
+               priv = boolean(this.spawnflags & PRINT_PRIVATE);
+               red = boolean(this.spawnflags & PRINT_REDTEAM);
+               blue = boolean(this.spawnflags & PRINT_BLUETEAM);
+       }
+
+       if(priv)
+       {
+               target_print_message(this, actor);
+       }
+       else if(red || blue)
+       {
+               if(red)
+               {
+                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.team == NUM_TEAM_1, target_print_message(this, it));
+               }
+               if(blue)
+               {
+                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.team == NUM_TEAM_2, target_print_message(this, it));
+               }
+       }
+       else
+       {
+               FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), target_print_message(this, it));
+       }
+}
+
+/*
+ * ENTITY PARAMETERS:
+ *
+ *   message: text string to print on screen.
+ *   targetname: the activating trigger points to this.
+ */
+spawnfunc(target_print)
+{
+       this.use = target_print_use;
+}
+
+// target_smallprint, Q3DF only
+spawnfunc(target_smallprint)
+{
+       spawnfunc_target_print(this);
+}
+
 .bool notteam;
 .bool notsingle;
 .bool notfree;