mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Mission units destroyed are stored in a json file being written mission runtime. (First step that will remove the need to save the debriefing manually after mission)
Using Mist framework to do this in the mission script env.
This commit is contained in:
parent
ba0b3adf71
commit
82bb608fd3
@ -191,3 +191,18 @@ class Operation:
|
||||
# visuals
|
||||
self.visualgen.generate()
|
||||
|
||||
# Scripts
|
||||
load_mist = TriggerStart(comment="Load Mist Lua Framework")
|
||||
with open(os.path.abspath("./resources/scripts/mist_4_3_74.lua")) as f:
|
||||
load_mist.add_action(DoScript(String(f.read())))
|
||||
self.current_mission.triggerrules.triggers.append(load_mist)
|
||||
|
||||
load_dcs_libe = TriggerStart(comment="Load DCS Liberation Script")
|
||||
with open(os.path.abspath("./resources/scripts/dcs_liberation.lua")) as f:
|
||||
script = f.read()
|
||||
script = script.replace("{{json_file_abs_location}}", "'"+os.path.abspath("./resources/scripts/json.lua"+"'"))
|
||||
load_dcs_libe.add_action(DoScript(String(script)))
|
||||
self.current_mission.triggerrules.triggers.append(load_dcs_libe)
|
||||
|
||||
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ from dcs.country import *
|
||||
SPREAD_DISTANCE_FACTOR = 0.1, 0.3
|
||||
SPREAD_DISTANCE_SIZE_FACTOR = 0.1
|
||||
|
||||
FRONTLINE_CAS_FIGHTS_COUNT = 4, 8
|
||||
FRONTLINE_CAS_FIGHTS_COUNT = 16, 24
|
||||
FRONTLINE_CAS_GROUP_MIN = 1, 2
|
||||
FRONTLINE_CAS_PADDING = 12000
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from shutil import copyfile
|
||||
from time import sleep
|
||||
|
||||
import dcs
|
||||
from PySide2.QtGui import QPixmap
|
||||
from PySide2.QtWidgets import QApplication, QLabel, QSplashScreen
|
||||
from dcs import installation
|
||||
|
||||
from qt_ui import uiconstants
|
||||
from qt_ui.windows.GameUpdateSignal import GameUpdateSignal
|
||||
@ -40,11 +42,19 @@ if __name__ == "__main__":
|
||||
with open("./resources/stylesheets/style.css") as stylesheet:
|
||||
css = stylesheet.read()
|
||||
|
||||
# Replace DCS Mission scripting file to allow DCS Liberation to work
|
||||
print("Replace : " + installation.get_dcs_install_directory() + os.path.sep + "Scripts/MissionScripting.lua")
|
||||
copyfile("./resources/scripts/MissionScripting.lua", installation.get_dcs_install_directory() + os.path.sep + "Scripts/MissionScripting.lua")
|
||||
app.processEvents()
|
||||
|
||||
# Uncomment to apply CSS (need works)
|
||||
app.setStyleSheet(css)
|
||||
# Create DCS Liberation script folder
|
||||
script_dir = installation.get_dcs_saved_games_directory() + os.sep + "Scripts" + os.sep + "DCSLiberation"
|
||||
if not os.path.exists(script_dir):
|
||||
os.makedirs(script_dir)
|
||||
copyfile("./resources/scripts/json.lua", script_dir + os.path.sep + "json.lua")
|
||||
|
||||
# Apply CSS (need works)
|
||||
app.setStyleSheet(css)
|
||||
GameUpdateSignal()
|
||||
|
||||
# Start window
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from PySide2.QtCore import QPoint, QRect, QPointF
|
||||
from PySide2.QtGui import QPainter
|
||||
from PySide2.QtWidgets import QGraphicsRectItem
|
||||
from PySide2.QtWidgets import QGraphicsRectItem, QGraphicsItem
|
||||
|
||||
import qt_ui.uiconstants as CONST
|
||||
from game import db
|
||||
@ -16,6 +16,7 @@ class QMapGroundObject(QGraphicsRectItem):
|
||||
self.parent = parent
|
||||
self.setAcceptHoverEvents(True)
|
||||
self.setZValue(2)
|
||||
#self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
|
||||
|
||||
if len(self.model.groups) > 0:
|
||||
units = {}
|
||||
|
||||
21
resources/scripts/MissionScripting.lua
Normal file
21
resources/scripts/MissionScripting.lua
Normal file
@ -0,0 +1,21 @@
|
||||
--Initialization script for the Mission lua Environment (SSE)
|
||||
|
||||
dofile('Scripts/ScriptingSystem.lua')
|
||||
|
||||
--Sanitize Mission Scripting environment
|
||||
--This makes unavailable some unsecure functions.
|
||||
--Mission downloaded from server to client may contain potentialy harmful lua code that may use these functions.
|
||||
--You can remove the code below and make availble these functions at your own risk.
|
||||
|
||||
-- local function sanitizeModule(name)
|
||||
-- _G[name] = nil
|
||||
-- package.loaded[name] = nil
|
||||
-- end
|
||||
--
|
||||
-- do
|
||||
-- sanitizeModule('os')
|
||||
-- sanitizeModule('io')
|
||||
-- sanitizeModule('lfs')
|
||||
-- require = nil
|
||||
-- loadlib = nil
|
||||
-- end
|
||||
50
resources/scripts/dcs_liberation.lua
Normal file
50
resources/scripts/dcs_liberation.lua
Normal file
@ -0,0 +1,50 @@
|
||||
local jsonlib = lfs.writedir() .. "Scripts\\DCSLiberation\\json.lua"
|
||||
json = loadfile(jsonlib)()
|
||||
|
||||
killed_aircrafts = {};
|
||||
killed_ground_units = {};
|
||||
weapons_fired = {}
|
||||
|
||||
local function messageAll(message)
|
||||
local msg = {}
|
||||
msg.text = message
|
||||
msg.displayTime = 25
|
||||
msg.msgFor = {coa = {'all'}}
|
||||
mist.message.add(msg)
|
||||
end
|
||||
|
||||
write_state = function()
|
||||
log("Writing DCS Liberation State...")
|
||||
local stateFile = lfs.writedir()..[[Scripts\DCSLiberation\state.json]]
|
||||
local fp = io.open(stateFile, 'w')
|
||||
local game_state = {
|
||||
["killed_aircrafts"] = killed_aircrafts,
|
||||
["killed_ground_units"] = killed_ground_units,
|
||||
["weapons_fired"] = weapons_fired,
|
||||
}
|
||||
fp:write(json:encode(game_state))
|
||||
fp:close()
|
||||
log("Done writing DCS Liberation state.")
|
||||
end
|
||||
|
||||
mist.scheduleFunction(write_state, {}, timer.getTime() + 10, 60, timer.getTime() + 3600)
|
||||
|
||||
activeWeapons = {}
|
||||
local function onCrash(event)
|
||||
if event.id == world.event.S_EVENT_CRASH and event.initiator then
|
||||
messageAll("Crash :" .. event.initiator.getName(event.initiator))
|
||||
killed_aircrafts[#killed_aircrafts + 1] = event.initiator.getName(event.initiator)
|
||||
end
|
||||
|
||||
if event.id == world.event.S_EVENT_DEAD and event.initiator then
|
||||
killed_ground_units[#killed_ground_units + 1] = event.initiator.getName(event.initiator)
|
||||
end
|
||||
|
||||
if event.id == world.event.S_EVENT_SHOT and event.weapon then
|
||||
weapons_fired[#weapons_fired + 1] = event.weapon.getTypeName(event.weapon)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
mist.addEventHandler(onCrash)
|
||||
1054
resources/scripts/json.lua
Normal file
1054
resources/scripts/json.lua
Normal file
File diff suppressed because it is too large
Load Diff
6822
resources/scripts/mist_4_3_74.lua
Normal file
6822
resources/scripts/mist_4_3_74.lua
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user