mirror of
https://github.com/s1lentq/ReGameDLL_CS.git
synced 2025-01-13 23:28:04 +03:00
Implemented point entities: point_clientcommand, point_servercommand
This commit is contained in:
parent
45fbb042f8
commit
eed7b19798
90
regamedll/dlls/addons/point_command.cpp
Normal file
90
regamedll/dlls/addons/point_command.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
void CPointBaseCommand::KeyValue(KeyValueData *pkvd)
|
||||
{
|
||||
// add this field to the command list
|
||||
if (m_uiCommandsCount < MAX_POINT_CMDS)
|
||||
{
|
||||
char command[128];
|
||||
if (pkvd->szValue[0] != '\0' && Q_strcmp(pkvd->szValue, "-") != 0)
|
||||
{
|
||||
Q_snprintf(command, sizeof(command), "%s \"%s\"", pkvd->szKeyName, pkvd->szValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_strlcpy(command, pkvd->szKeyName);
|
||||
}
|
||||
|
||||
m_iszCommands[m_uiCommandsCount++] = ALLOC_STRING(command);
|
||||
pkvd->fHandled = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
CPointEntity::KeyValue(pkvd);
|
||||
}
|
||||
|
||||
LINK_ENTITY_TO_CLASS(point_clientcommand, CPointClientCommand, CCSPointClientCommand)
|
||||
|
||||
void CPointClientCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
||||
{
|
||||
edict_t *pClient = nullptr;
|
||||
if (gpGlobals->maxClients == 1)
|
||||
{
|
||||
pClient = INDEXENT(1);
|
||||
}
|
||||
else if (pActivator &&
|
||||
pActivator->IsPlayer() &&
|
||||
pActivator->IsNetClient() &&
|
||||
!pActivator->IsDormant())
|
||||
{
|
||||
// In multiplayer, send it back to the activator
|
||||
pClient = pActivator->edict();
|
||||
}
|
||||
|
||||
if (pClient)
|
||||
{
|
||||
for (size_t cmd = 0; cmd < m_uiCommandsCount; cmd++) {
|
||||
CLIENT_COMMAND(pClient, UTIL_VarArgs("%s\n", m_iszCommands[cmd].str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LINK_ENTITY_TO_CLASS(point_servercommand, CPointServerCommand, CCSPointServerCommand)
|
||||
|
||||
void CPointServerCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
|
||||
{
|
||||
for (size_t cmd = 0; cmd < m_uiCommandsCount; cmd++) {
|
||||
Execute(m_iszCommands[cmd]);
|
||||
}
|
||||
}
|
||||
|
||||
void CPointServerCommand::Execute(const char *command)
|
||||
{
|
||||
if (!IS_DEDICATED_SERVER())
|
||||
{
|
||||
// potentially dangerous for untrusted maps
|
||||
// so try to use it for passing through filtered svc_stufftext
|
||||
CLIENT_COMMAND(INDEXENT(1), UTIL_VarArgs("%s\n", command));
|
||||
return;
|
||||
}
|
||||
|
||||
SERVER_COMMAND(UTIL_VarArgs("%s\n", command));
|
||||
}
|
49
regamedll/dlls/addons/point_command.h
Normal file
49
regamedll/dlls/addons/point_command.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
const int MAX_POINT_CMDS = 16; // maximum number of commands a single point_[server/client]command entity may be assigned
|
||||
|
||||
class CPointBaseCommand: public CPointEntity {
|
||||
public:
|
||||
virtual void KeyValue(KeyValueData *pkvd);
|
||||
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) = 0;
|
||||
|
||||
protected:
|
||||
size_t m_uiCommandsCount;
|
||||
string_t m_iszCommands[MAX_POINT_CMDS];
|
||||
};
|
||||
|
||||
// It issues commands to the client console
|
||||
class CPointClientCommand: public CPointBaseCommand {
|
||||
public:
|
||||
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
|
||||
private:
|
||||
void Execute(edict_t *pEdict, const char *command);
|
||||
};
|
||||
|
||||
// It issues commands to the server console
|
||||
class CPointServerCommand: public CPointBaseCommand {
|
||||
public:
|
||||
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
|
||||
|
||||
private:
|
||||
void Execute(const char *command);
|
||||
};
|
@ -3026,3 +3026,15 @@
|
||||
sprite_scale(string) : "Sprite scale" : "1.0"
|
||||
sprite_framerate(string) : "Sprite framerate" : "10"
|
||||
]
|
||||
|
||||
@BaseClass base(Targetname) = BaseCommand
|
||||
[
|
||||
]
|
||||
|
||||
@PointClass base(BaseCommand) size(-8 -8 -8, 8 8 8) = point_servercommand : "It issues commands to the server console"
|
||||
[
|
||||
]
|
||||
|
||||
@PointClass base(BaseCommand) size(-8 -8 -8, 8 8 8) = point_clientcommand : "It issues commands to the client console"
|
||||
[
|
||||
]
|
||||
|
@ -24,6 +24,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\dlls\addons\item_airbox.cpp" />
|
||||
<ClCompile Include="..\dlls\addons\point_command.cpp" />
|
||||
<ClCompile Include="..\dlls\addons\trigger_random.cpp" />
|
||||
<ClCompile Include="..\dlls\addons\trigger_setorigin.cpp" />
|
||||
<ClCompile Include="..\dlls\airtank.cpp" />
|
||||
@ -602,6 +603,7 @@
|
||||
<ClInclude Include="..\common\winsani_out.h" />
|
||||
<ClInclude Include="..\dlls\activity.h" />
|
||||
<ClInclude Include="..\dlls\addons\item_airbox.h" />
|
||||
<ClInclude Include="..\dlls\addons\point_command.h" />
|
||||
<ClInclude Include="..\dlls\addons\trigger_random.h" />
|
||||
<ClInclude Include="..\dlls\addons\trigger_setorigin.h" />
|
||||
<ClInclude Include="..\dlls\airtank.h" />
|
||||
|
@ -553,6 +553,9 @@
|
||||
<ClCompile Include="..\dlls\addons\trigger_random.cpp">
|
||||
<Filter>dlls\addons</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\dlls\addons\point_command.cpp">
|
||||
<Filter>dlls\addons</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\version\version.h">
|
||||
@ -1047,6 +1050,9 @@
|
||||
<ClInclude Include="..\dlls\addons\trigger_random.h">
|
||||
<Filter>dlls\addons</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\dlls\addons\point_command.h">
|
||||
<Filter>dlls\addons</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\linux\appversion.sh">
|
||||
|
@ -228,3 +228,6 @@ class CCSClientFog: public CCSEntity {};
|
||||
class CCSTriggerSetOrigin: public CCSDelay {};
|
||||
class CCSTriggerRandom: public CCSDelay {};
|
||||
class CCSItemAirBox: public CCSArmoury {};
|
||||
class CCSPointBaseCommand: public CCSPointEntity {};
|
||||
class CCSPointClientCommand: public CCSPointBaseCommand {};
|
||||
class CCSPointServerCommand: public CCSPointBaseCommand {};
|
||||
|
@ -133,6 +133,7 @@ using FloatRef = float;
|
||||
#include "addons/item_airbox.h"
|
||||
#include "addons/trigger_setorigin.h"
|
||||
#include "addons/trigger_random.h"
|
||||
#include "addons/point_command.h"
|
||||
|
||||
// Tutor
|
||||
#include "tutor.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user