Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do-build zones override no-build zones #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
Build
Source
Source
173 changes: 136 additions & 37 deletions BasicTerritories/scripts/3_Game/BasicTerritoriesConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class BasicTerritoriesConfig
protected static string DirPATH = "$profile:BasicTerritories";
protected static string ConfigPATH = DirPATH + "\\settings.json";
protected static string RaidPATH = DirPATH + "\\RaidHandlers.json";
string ConfigVersion = "2";
string ConfigVersion = "3";
ref TStringArray WhiteList = {
"Trap",
"Paper",
Expand All @@ -27,7 +27,8 @@ class BasicTerritoriesConfig
int Notifications = 0; //0 Chat | 1 Notifications Mod

ref array< ref BasicTerritoriesNoBuildZones> NoBuildZones = new array< ref BasicTerritoriesNoBuildZones>;

ref array< ref BasicTerritoriesDoBuildZones> DoBuildZones = new array< ref BasicTerritoriesDoBuildZones>;

string NoBuildZoneMessage = " You can't build here, you are trying to build in a designated no build zone";
string TerritoryConflictMessage = " Sorry you can't build a territory this close to another territory";
string WithinTerritoryWarning = " Sorry you can't build this close to an enemy territory";
Expand All @@ -51,59 +52,83 @@ class BasicTerritoriesConfig
[NonSerialized()]
int m_disableBaseDamage = 0;

void Load(){
void Load()
{
Print("[BasicTerritories] Loading Config");
if (GetGame().IsServer()){
if (FileExist(ConfigPATH)){ //If config exist load File
if (GetGame().IsServer())
{
if (FileExist(ConfigPATH))
{ //If config exist load File
JsonFileLoader<BasicTerritoriesConfig>.JsonLoadFile(ConfigPATH, this);
if (ConfigVersion != "2"){
ConfigVersion = "2";
if (ConfigVersion != "3")
{
ConfigVersion = "3";
DoBuildZones.Insert(new BasicTerritoriesDoBuildZones(3685, 5982, 20));
Save();
}
}else{ //File does not exist create file
if (!FileExist(DirPATH)){
}
else
{ //File does not exist create file
if (!FileExist(DirPATH))
{
MakeDirectory(DirPATH);
}
NoBuildZones.Insert(new BasicTerritoriesNoBuildZones(3703.5, 5985.11, 100));
NoBuildZones.Insert(new BasicTerritoriesNoBuildZones(8345.61, 5985.93, 100));

DoBuildZones.Insert(new BasicTerritoriesDoBuildZones(3685, 5982, 20));

FlagRefreshFrequency = GetCEApi().GetCEGlobalInt("FlagRefreshFrequency");
if (FlagRefreshFrequency <= 0){

if (FlagRefreshFrequency <= 0)
{
FlagRefreshFrequency = GameConstants.REFRESHER_FREQUENCY_DEFAULT;
}

KitLifeTimes.Insert("fencekit", 3888000);
KitLifeTimes.Insert("watchtowerkit", 3888000);
KitLifeTimes.Insert("msp_", 3888000);
KitLifeTimes.Insert("bbp_", 3888000);

Save();
}
m_disableBaseDamage = GetGame().ServerConfigGetInt("disableBaseDamage");
if( m_disableBaseDamage < 1){
if( m_disableBaseDamage < 1)
{
Print("[BasicTerritories] BaseDamage [Enabled]");
if (FileExist(RaidPATH)){
if (FileExist(RaidPATH))
{
LoadRaidHandler();
} else {
}
else
{
m_BasicTerritoriesRaidHandlers = new array<ref BasicRaidHandler>;
m_BasicTerritoriesRaidHandlers.Insert(new BasicRaidHandler("fence"));
m_BasicTerritoriesRaidHandlers.Insert(new BasicRaidHandler("watchtower"));
m_BasicTerritoriesRaidHandlers.Insert(new BasicRaidHandler("*",false));
m_RaidHandlerLoaded = true;
SaveRaidHandler();
}
} else {
}
else
{
Print("[BasicTerritories] BaseDamage [Disabled]");
}
}
}

void Save(){
void Save()
{
JsonFileLoader<BasicTerritoriesConfig>.JsonSaveFile(ConfigPATH, this);
}

int disableBaseDamage(){
int disableBaseDamage()
{
return m_disableBaseDamage;
}

void LoadRaidHandler(){
void LoadRaidHandler()
{
if (!FileExist(RaidPATH)) {
Print("[BasicTerritories] File At" + RaidPATH + " could not be found");
return;
Expand Down Expand Up @@ -135,28 +160,35 @@ class BasicTerritoriesConfig
}
}

void SaveRaidHandler(){
void SaveRaidHandler()
{
JsonFileLoader<array<ref BasicRaidHandler>>.JsonSaveFile(RaidPATH, m_BasicTerritoriesRaidHandlers);
}

bool IsInWhiteList(string item){
if (WhiteList && WhiteList.Count() > 0){
for (int i = 0; i < WhiteList.Count(); i++){
bool IsInWhiteList(string item)
{
if (WhiteList && WhiteList.Count() > 0)
{
for (int i = 0; i < WhiteList.Count(); i++)
{
item.ToLower();
string wItem = WhiteList.Get(i);
wItem.ToLower();
if (item.Contains(wItem)){
if (item.Contains(wItem))
{
return true;
}
}
}
return false;
}

bool CanWarnPlayer(string message = ""){
bool CanWarnPlayer(string message = "")
{
message.ToLower();
int curTime = GetGame().GetTime();
if ( curTime > m_BlockWarnPlayer || m_BlockLastMessage != message){
if ( curTime > m_BlockWarnPlayer || m_BlockLastMessage != message)
{
m_BlockLastMessage = message;
m_BlockWarnPlayer = curTime + 6000;
return true;
Expand All @@ -165,35 +197,58 @@ class BasicTerritoriesConfig
}


int PublicPermission(){
int PublicPermission()
{
return PublicPermissions;
}

int MemberPermission(){
int MemberPermission()
{
return MemberPermissions;
}

void SendNotification(string text, string icon = "BasicTerritories/images/NoBuild.paa"){
if (GetGame().IsClient() && CanWarnPlayer(text)){
if (Notifications == 0){
void SendNotification(string text, string icon = "BasicTerritories/images/NoBuild.paa")
{
if (GetGame().IsClient() && CanWarnPlayer(text))
{
if (Notifications == 0)
{
GetGame().Chat(text,"");
}
#ifdef NOTIFICATIONS
else if (Notifications == 1){
else if (Notifications == 1)
{
NotificationSystem.SimpleNoticiation(text, "Territory", icon, ARGB(230, 209, 60, 60), 8, NULL);
}
#endif
}
}


bool CanBuildHere(vector pos, string item = ""){
if (IsInWhiteList(item)){
bool CanBuildHere(vector pos, string item = "")
{
int i;

if (IsInWhiteList(item))
{
return true;
}
if (NoBuildZones){
for (int i = 0; i < NoBuildZones.Count(); i++){
if (NoBuildZones.Get(i) && NoBuildZones.Get(i).Check(pos) ){
if (DoBuildZones)
{
for (i = 0; i < DoBuildZones.Count(); i++)
{
if (DoBuildZones.Get(i) && DoBuildZones.Get(i).Check(pos) )
{
return true;
}
}
}
if (NoBuildZones)
{
for (i = 0; i < NoBuildZones.Count(); i++)
{
if (NoBuildZones.Get(i) && NoBuildZones.Get(i).Check(pos) )
{
return false;
}
}
Expand Down Expand Up @@ -258,6 +313,16 @@ class BasicTerritoriesConfig
}
return 0;
}

string GetConfigVersion()
{
return ConfigVersion;
}

void SetConfigVersion(string version)
{
ConfigVersion = version;
}
}


Expand Down Expand Up @@ -285,13 +350,47 @@ class BasicTerritoriesNoBuildZones{
return false;
}

vector GetPos(){
vector GetPos()
{
return Vector(X, GetGame().SurfaceY(X,Z),Z);
}

}


class BasicTerritoriesDoBuildZones
{
string Name = "";
float X;
float Z;
float R;
bool DrawOnMap = false;

void BasicTerritoriesDoBuildZones(float x, float z, float r){
X = x;
Z = z;
R = r;
}

//Returns True If is in zone
bool Check(vector checkPos){
if (checkPos){
vector ZeroedHeightPos = Vector(checkPos[0], 0,checkPos[2]);
if (vector.Distance(ZeroedHeightPos, Vector(X, 0, Z)) <= R){
return true;
}
}
return false;
}

vector GetPos()
{
return Vector(X, GetGame().SurfaceY(X,Z),Z);
}

}


ref BasicTerritoriesConfig m_BasicTerritoriesConfig;

ref array<ref BasicRaidHandler> m_BasicTerritoriesRaidHandlers = new array<ref BasicRaidHandler>;
Expand All @@ -314,4 +413,4 @@ static BasicTerritoriesConfig GetBasicTerritoriesConfig()
static array<ref BasicRaidHandler> GetRaidHandlers()
{
return m_BasicTerritoriesRaidHandlers;
};
};
55 changes: 46 additions & 9 deletions BasicTerritories/scripts/5_Mission/mission/MissionGameplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,69 @@ modded class MissionGameplay extends MissionBase
}


void RPCBasicTerritoriesModSettings( CallType type, ParamsReadContext ctx, PlayerIdentity sender, Object target ) {
Param1< BasicTerritoriesConfig > data;
void RPCBasicTerritoriesModSettings( CallType type, ParamsReadContext ctx, PlayerIdentity sender, Object target )
{
Param1< BasicTerritoriesConfig > data;

if ( !ctx.Read( data ) ) return;

Print("[BASICT][Client] Received Config From Server");

m_BasicTerritoriesConfig = data.param1;

#ifdef BASICMAP
if (GetBasicTerritoriesConfig().NoBuildZones ){

int i;

if (GetBasicTerritoriesConfig().NoBuildZones )
{
BasicMap().ClearMarkers("TerritoryNoBuildZones");
bool SomeZonesOnTheMap = false;
for (int i = 0; i < GetBasicTerritoriesConfig().NoBuildZones.Count(); i++){
if (GetBasicTerritoriesConfig().NoBuildZones.Get(i) && GetBasicTerritoriesConfig().NoBuildZones.Get(i).DrawOnMap){

bool SomeNoBuildZonesOnTheMap = false;

for (i = 0; i < GetBasicTerritoriesConfig().NoBuildZones.Count(); i++)
{
if (GetBasicTerritoriesConfig().NoBuildZones.Get(i) && GetBasicTerritoriesConfig().NoBuildZones.Get(i).DrawOnMap)
{
BasicMapCircleMarker tmpMarker = new BasicMapCircleMarker("", GetBasicTerritoriesConfig().NoBuildZones.Get(i).GetPos(), "BasicTerritories\\images\\NoBuild.paa", {189, 38, 78},150);
tmpMarker.SetRadius(GetBasicTerritoriesConfig().NoBuildZones.Get(i).R);
tmpMarker.SetShowCenterMarker(true);
tmpMarker.SetHideIntersects(true);
tmpMarker.SetCanEdit(false);
tmpMarker.SetGroup("TerritoryNoBuildZones");
BasicMap().AddMarker("TerritoryNoBuildZones",tmpMarker);
SomeZonesOnTheMap = true;
SomeNoBuildZonesOnTheMap = true;
}
}
if (SomeZonesOnTheMap){

if (SomeNoBuildZonesOnTheMap)
{
BasicMap().RegisterGroup("TerritoryNoBuildZones", new BasicMapGroupMetaData("TerritoryNoBuildZones", "No Build Areas"),NULL);
}

bool SomeDoBuildZonesOnTheMap = false;

for (i = 0; i < GetBasicTerritoriesConfig().DoBuildZones.Count(); i++)
{
if (GetBasicTerritoriesConfig().DoBuildZones.Get(i) && GetBasicTerritoriesConfig().DoBuildZones.Get(i).DrawOnMap)
{
BasicMapCircleMarker tmpMarker2 = new BasicMapCircleMarker("", GetBasicTerritoriesConfig().DoBuildZones.Get(i).GetPos(), "BasicTerritories\\images\\Build.paa", {212, 175, 55},180);
tmpMarker2.SetRadius(GetBasicTerritoriesConfig().DoBuildZones.Get(i).R);
tmpMarker2.SetShowCenterMarker(true);
tmpMarker2.SetHideIntersects(true);
tmpMarker2.SetCanEdit(false);
tmpMarker2.SetGroup("TerritoryDoBuildZones");
BasicMap().AddMarker("TerritoryDoBuildZones",tmpMarker2);
SomeDoBuildZonesOnTheMap = true;
}
}

if (SomeDoBuildZonesOnTheMap)
{
BasicMap().RegisterGroup("TerritoryDoBuildZones", new BasicMapGroupMetaData("TerritoryDoBuildZones", "No Build Areas"),NULL);
}

}
#endif
}
}
}