Files
SibIntel1/Source/MasharovDev/cppGI.cpp
T
2024-04-16 19:52:04 +05:00

195 lines
5.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "cppGI.h"
#include "Kismet/GameplayStatics.h"
#include "Misc/paths.h"
#include "commands_model.h"
#include "Engine/levelstreamingdynamic.h"
CSocket* soc;
/*for working tarray::Contains*/
bool operator==(const Fcppcoords& c1, const Fcppcoords& c2) {
return c1.flat == c2.flat &&
c1.floor == c2.floor &&
c1.house == c2.house &&
c1.section == c2.section &&
c1.type == c2.type &&
c1.zone == c2.zone;
}
void UcppGI::cppLvlManage(UObject* WorldContextObject, Fcppcoords currentCoords, uint8 currentState, TArray<ULevelStreaming*>& Levelss)
{
bool loadthis = false;
int32 temp1[5] = { currentCoords.flat,currentCoords.zone,currentCoords.house,currentCoords.section,currentCoords.floor };
/*complete lvls for loading*/
for (auto& lvl : cpplvlsForLoading) {
int32* temp[5] = { &lvl.flat,&lvl.zone,&lvl.house,&lvl.section,&lvl.floor };
int8 n = 0;
for (auto i : temp) {
if (*i == -2) *i = temp1[n];
n++;
}
}
cpplvlsForLoading.AddUnique(currentCoords);
for (FcppLevelStruct& lvl : cpplevelLIst) {
FString tt = lvl.path;
if (currentCoords.floor == 100);
else {
loadthis = false;
for (Fcppcoords& lvl1 : cpplvlsForLoading) {
bool ceq[7];
cppCoordsEq(lvl1, lvl.coords,true,false, ceq[0], ceq[1], ceq[2], ceq[3], ceq[4], ceq[5], ceq[6]);
if (
(
(lvl.coords.flat == -1) || ceq[0] ||
((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0))
)
&& ceq[2]
&& ceq[3]
&& ceq[4]
&& (ceq[5] || ((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0) && (currentState == 11/*3d tour*/)) ||
((lvl1.flat == lvl.anotherLvl) && (lvl.anotherLvl >= 0) && ((currentState == 9) || (currentState == 10)/*sel or view plan*/) && (lvl1.flat > lvl.coords.flat))
)
) loadthis = true;
}
}
TArray<FString> blya;
blya.Add(FString::FromInt(lvl.coords.flat));
blya.Add(FString::FromInt(lvl.coords.zone));
blya.Add(FString::FromInt(lvl.coords.house));
blya.Add(FString::FromInt(lvl.coords.section));
blya.Add(FString::FromInt(lvl.coords.floor));
blya.Add(FString::FromInt(lvl.Z));
FString instanceStr = FString::Join(blya, L"_");
instanceStr.Append(L"_").Append(FPaths::GetCleanFilename(lvl.path));
FName instanceName = FName(instanceStr);
if (loadthis) {
if (cppdynamicLvls.Contains(instanceName)) {
ULevelStreaming* lvl1 = UGameplayStatics::GetStreamingLevel(WorldContextObject, instanceName);
lvl1->bShouldBlockOnLoad = (currentState != 11) && lvl.dontUnload;
lvl1->SetShouldBeLoaded(true);
lvl1->SetShouldBeVisible(true);
Levelss.Add(lvl1);
}
else {
bool b;
if (ULevelStreamingDynamic* newlvl = ULevelStreamingDynamic::LoadLevelInstance(WorldContextObject, lvl.path, FVector(0, 0, lvl.Z), FRotator(), b, instanceStr)) {
newlvl->SetPriority(lvl.coords.flat == -1 ? 1 : 0);
newlvl->bShouldBlockOnLoad = lvl.dontUnload;
cppdynamicLvls.Add(instanceName);
Levelss.Add(newlvl);
}
}
}
else {
if (cppdynamicLvls.Contains(instanceName)) UGameplayStatics::GetStreamingLevel(WorldContextObject, instanceName)->SetShouldBeLoaded(false);
}
}
cpplvlsForLoading.Empty();
return;
}
void UcppGI::cppCoordsEq(Fcppcoords coords, Fcppcoords coords1, bool relevantMinus2, bool fastEq, bool& flat_, bool& type_, bool& zone_, bool& house_, bool& section_, bool& floor_, bool& fullEq)
{
bool* outLvl[6] = { &flat_, &type_, &zone_, &house_, &section_, &floor_ };
int32 c1[6] = { coords.flat,coords.type, coords.zone, coords.house, coords.section, coords.floor };
int32 c2[6] = { coords1.flat,coords1.type, coords1.zone, coords1.house, coords1.section, coords1.floor };
int32 mins[6] = { 0,0,1,1,1,0 };
if (fastEq) {
for (int32 i = 0; i < 6; i++)
{
*outLvl[i] = (c1[i] == c2[i]);
}
}
else {
for (int32 i = 0; i < 6; i++) {
*outLvl[i] = ((c1[i] < mins[i]) && (c2[i] < mins[i])) || (c1[i] == c2[i]) || (c1[i] == -2) || ((c2[i] == -2) && relevantMinus2);
}
}
fullEq = true;
for (const auto var : outLvl)
{
if (!*var)fullEq = false;
}
}
void UcppGI::avoidAutoState()
{
if (!soc)return;
DECLARE_CMD(CMD_NOP, cmd);
sendCommand(*soc, cmd);
}
void UcppGI::makeSocket(FString ip, int port)
{
char* ipc=NULL;
wcstombs(ipc, *ip, ip.Len());
soc = new CSocket(ipc, port);
}
void UcppGI::setColor(uint8 code, FColor color)
{
if (!soc)return;
DECLARE_CMD(CMD_SET_COLOR, cmd);
cmd.code = code;
cmd.r = color.R, cmd.g=color.G, cmd.b=color.B;
sendCommand(*soc, cmd);
}
void UcppGI::setLight(int house, int floor, int strip, uint8 state)
{
if (!soc)return;
if (strip < 0) {
if (floor < 0) {
if (house < 0) {
DECLARE_CMD(CMD_SET_ALL_STATE, cmd);
cmd.state = state;
sendCommand(*soc, cmd);
return;
}
DECLARE_CMD(CMD_SET_BUILDING_STATE, cmd);
cmd.state = state;
cmd.building = house;
sendCommand(*soc, cmd);
return;
}
DECLARE_CMD(CMD_SET_FLOOR_STATE, cmd);
cmd.state = state;
cmd.building = house;
cmd.floor = floor;
sendCommand(*soc, cmd);
return;
}
DECLARE_CMD(CMD_SET_ROOM_STATE, cmd);
cmd.state = state;
cmd.building = house;
cmd.floor = floor;
cmd.strip = strip;
sendCommand(*soc, cmd);
}
void UcppGI::setPartState(uint8 part, uint8 state)
{
if (!soc)return;
DECLARE_CMD(CMD_SET_PART_MODE, cmd);
cmd.mode = state;
cmd.part = part;
sendCommand(*soc, cmd);
}