Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "tile_base.h"
- #include "GameFramework/Actor.h"
- #include "Map_Controller.generated.h"
- class Atile_base;
- USTRUCT(BlueprintType)
- struct Fneighbour
- {
- GENERATED_USTRUCT_BODY()
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int instance_index;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int ISM_index;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int matrix_position_x;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int matrix_position_y;
- Fneighbour()
- {
- this->ISM_index = 0;
- this->instance_index = 0;
- this->matrix_position_x = 0;
- this->matrix_position_y = 0;
- };
- Fneighbour(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
- {
- this->ISM_index = ISM_index;
- this->instance_index = instance_index;
- this->matrix_position_x = matrix_position_x;
- this->matrix_position_y = matrix_position_y;
- };
- };
- USTRUCT(BlueprintType)
- struct Ftile_indexer
- {
- GENERATED_USTRUCT_BODY()
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int instance_index;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int ISM_index;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int matrix_position_x;
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Indexer")
- int matrix_position_y;
- TArray<Fneighbour> neighbours;
- Ftile_indexer()
- {
- this->ISM_index = 0;
- this->instance_index = 0;
- this->matrix_position_x = 0;
- this->matrix_position_y = 0;
- };
- Ftile_indexer(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
- {
- this->ISM_index = ISM_index;
- this->instance_index = instance_index;
- this->matrix_position_x = matrix_position_x;
- this->matrix_position_y = matrix_position_y;
- this->neighbours = TArray<Fneighbour>();
- };
- void add_neighbour(int ISM_index, int instance_index, int matrix_position_x, int matrix_position_y)
- {
- neighbours.Add(Fneighbour(ISM_index, instance_index, matrix_position_x, matrix_position_y));
- GEngine->AddOnScreenDebugMessage(-1, 2, FColor::Red, FString::FromInt(neighbours[neighbours.Num() - 1].instance_index));
- };
- TArray<Fneighbour> get_neighbours()
- {
- return neighbours;
- };
- };
- UCLASS()
- class ATHENA_API AMap_Controller : public AActor
- {
- GENERATED_BODY()
- public:
- AMap_Controller();
- virtual void BeginPlay() override;
- virtual void Tick( float DeltaSeconds ) override;
- void deselect_previous_tile(Atile_base* tile_selected);
- void generate_hex_grid();
- void generate_graph();
- void generate_cellular_automata();
- FVector2D find_tile_matrix_coordinate_from_index(int ISM_index, int instance_index);
- Ftile_indexer find_tile_index_from_matrix_coordinate(int matrix_position_x, int matrix_position_y);
- void debug_neighbours(int ISM_index, int instance_index);
- TArray<Fneighbour> find_tile_index_neighbours(int ISM_index, int instance_index);
- Atile_base* spawn(UClass* object_class, FVector location, int tile_coordinate_x, int tile_coordinate_y);
- void replace_tile(Atile_base* tile, int type_index);
- Atile_base* get_tile_from_map(int _x, int _y);
- bool tiles_are_same_type(FString tile_type1, FString tile_type2);
- public:
- USceneComponent* game_controller_root;
- UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* grass_ISM;
- UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* water_ISM;
- UPROPERTY(VisibleAnywhere) UInstancedStaticMeshComponent* dirt_ISM;
- UPROPERTY(VisibleAnywhere) TArray<UInstancedStaticMeshComponent*> tiles_ISM;
- UPROPERTY(VisibleAnywhere) TArray<Ftile_indexer> tile_indexer;
- UPROPERTY(EditAnywhere) int map_max_row_count = 13;
- UPROPERTY(EditAnywhere) int map_tile_radius = 102;
- UPROPERTY(EditAnywhere) int map_cellular_automata_max_depth = 5;
- private:
- //Tile blueprints
- TArray<TSubclassOf<AStaticMeshActor>> map_tile_classes;
- int map_row_height = abs(map_max_row_count / 2);
- //Array to store generated tiles
- TArray<Atile_base*> map_tiles;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement