"use strict";
this.name = "Anarchies_Facelift";
this.author = "phkb";
this.copyright = "2026 phkb";
this.description = "Ship script for anarchy bounty hunters";
this.licence = "CC BY-NC-SA 3.0";

this._sentinelType = 0; // 0 = galcop, 1 = navy

this._aflConfig = {
	Name: this.name,
	Alias: expandMissionText("afl_config_alias"),
	Display: expandMissionText("afl_config_display"),
	Alive: "_aflConfig",
	Notify: "$changeSettings",
	SInt: {
		S0: { Name: "_sentinelType", Def: 0, Min: 0, Max: 1, Desc: expandMissionText("afl_sentineltype") },
		Info: expandMissionText("afl_config_sint_info")
	}
};

//----------------------------------------------------------------------------------------
this.$changeSettings = function() {
    var sentinels = system.shipsWithRole("afl_sentinel");
    if (sentinels.length > 0) {
        for (var i = 0; i < sentinels.length; i++) {
            this.shipSpawned(sentinels[i]);
        }
    }
}

//----------------------------------------------------------------------------------------
this.startUpComplete = function() {
    if (missionVariables.AnarchiesFacelift_SentinelType) {
        this._sentinelType = parseInt(missionVariables.AnarchiesFacelift_SentinelType);
    }
	if (worldScripts.Lib_Config) {
		var lib = worldScripts.Lib_Config;
		lib._registerSet(this._aflConfig);
    }
    if (worldScripts.WireframeShipImages) {
        var wsi = worldScripts.WireframeShipImages;
        wsi._gameShips["Hacker Outpost MkII"] = "hacker_mk2";
        wsi._gameShips["Salvage Gang MkII"] = "salvage_mk2";
    }
}

//----------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
	if (worldScripts.Lib_Config) {
        missionVariables.AnarchiesFacelift_SentinelType = this._sentinelType;
    }
}

//----------------------------------------------------------------------------------------
this.shipSpawned = function(ship) {
    if (ship.hasRole("afl_sentinel")) {
        if (this._sentinelType == 1) {
            ship.setMaterials({
                "sentinel_station1.png": {
                    diffuse_map: "aflnew_sentinel_station_diffuse2.png",
                    gloss: 0.7,
                    specular_map: "aflnew_sentinel_station_specular.png",
                    specular_color: [0.1, 0.1, 0.1],
                    emission_map: "aflnew_sentinel_station_emission.png",
                    emission_modulate_color: { green: 4000, red: 4000, blue: 0 },
                    normal_map: "aflnew_sentinel_station_normal.png"
                },
                "sentinel_station2.png": {
                    diffuse_map: "aflnew_sentinel_station_diffuse4.png",
                    gloss: 0.7,
                    specular_map: "aflnew_sentinel_station_specular3.png",
                    specular_color: [0.1, 0.1, 0.1],
                    emission_map: "aflnew_sentinel_station_emission3.png",
                    emission_modulate_color: { green: 4000, red: 4000, blue: 0 },
                    normal_map: "aflnew_sentinel_station_normal3.png"
                }
            });
        } else {
            ship.setMaterials({
                "sentinel_station1.png": {
                    diffuse_map: "aflnew_sentinel_station_diffuse1.png",
                    gloss: 0.7,
                    specular_map: "aflnew_sentinel_station_specular.png",
                    specular_color: [0.1, 0.1, 0.1],
                    emission_map: "aflnew_sentinel_station_emission.png",
                    emission_modulate_color: { green: 4000, red: 4000, blue: 0 },
                    normal_map: "aflnew_sentinel_station_normal.png"
                },
                "sentinel_station2.png": {
                    diffuse_map: "aflnew_sentinel_station_diffuse3.png",
                    gloss: 0.7,
                    specular_map: "aflnew_sentinel_station_specular3.png",
                    specular_color: [0.1, 0.1, 0.1],
                    emission_map: "aflnew_sentinel_station_emission3.png",
                    emission_modulate_color: { green: 4000, red: 4000, blue: 0 },
                    normal_map: "aflnew_sentinel_station_normal3.png"
                }
            });
        }
    }
}