Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Afforess committed May 9, 2016
0 parents commit bc08869
Show file tree
Hide file tree
Showing 175 changed files with 1,806 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
build/*
factorio_mods
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright (c) 2016, Afforess

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
PACKAGE_NAME := Big_Brother
VERSION_STRING := 0.1.0

OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING)
OUTPUT_DIR := build/$(OUTPUT_NAME)

PKG_COPY := $(wildcard *.md) graphics locale

SED_FILES := $(shell find . -iname '*.json' -type f -not -path "./build/*") $(shell find . -iname '*.lua' -type f -not -path "./build/*")
OUT_FILES := $(SED_FILES:%=$(OUTPUT_DIR)/%)

SED_EXPRS := -e 's/{{MOD_NAME}}/$(PACKAGE_NAME)/g'
SED_EXPRS += -e 's/{{VERSION}}/$(VERSION_STRING)/g'

all: clean package install_mod

package-copy: $(PKG_DIRS) $(PKG_FILES)
mkdir -p $(OUTPUT_DIR)
ifneq ($(PKG_COPY),)
cp -r $(PKG_COPY) build/$(OUTPUT_NAME)
endif

$(OUTPUT_DIR)/%.lua: %.lua
@mkdir -p $(@D)
@sed $(SED_EXPRS) $< > $@
luac -p $@

$(OUTPUT_DIR)/%: %
mkdir -p $(@D)
sed $(SED_EXPRS) $< > $@

package: package-copy $(OUT_FILES)
cd build && zip -r $(OUTPUT_NAME).zip $(OUTPUT_NAME)

clean:
rm -rf build/

install_mod:
if [ -L factorio_mods ] ; \
then \
cp -R build/$(OUTPUT_NAME) factorio_mods ; \
fi;
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Repository for the Factorio Concrete Logistics mod.

Description
===========

Mod compatibility
=================
Requires color-coding factorio mod.

Contributing
============
Contributions are welcome.
263 changes: 263 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
require 'defines'
require 'stdlib/string'
require 'stdlib/surface'
require 'stdlib/table'
require 'stdlib/event/event'
require 'stdlib/log/logger'
require 'stdlib/area/position'
require 'stdlib/entity/entity'

LOGGER = Logger.new('Big_Brother', 'main', true)
MAX_SURVEILLANCE_DISTANCE = 25000
MAX_SURVEILLANCE_DISTANCE_SQUARED = MAX_SURVEILLANCE_DISTANCE * MAX_SURVEILLANCE_DISTANCE

Event.register({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
local entity = event.created_entity
local name = entity.name
if name == 'radar' then
track_entity('radars', entity)
upgrade_radars(entity.force)
elseif name == 'big-electric-pole' then
track_entity('power_poles', entity)
if entity.force.technologies['surveillance-2'].researched then
update_surveillance(entity, false)
end
elseif entity.type == 'car' then
track_entity('vehicles', entity)
update_surveillance(entity, true)
elseif entity.type == 'locomotive' then
track_entity('trains', entity)
update_surveillance(entity, true)
elseif entity.name == 'big_brother-surveillance-center' then
entity.backer_name = ''
track_entity('surveillance_centers', entity)
if global.vehicles then
for _, vehicle in pairs(global.vehicles) do
update_surveillance(vehicle, true)
end
end
if global.trains then
for _, train in pairs(global.trains) do
update_surveillance(train, true)
end
end
end
end)

-- Scan the map once if the mod has never been loaded (then deregister on_tick)
Event.register(defines.events.on_tick, function(event)
if not global.scanned_map then
if not global.map_scan_countdown then global.map_scan_countdown = 120 end
global.map_scan_countdown = global.map_scan_countdown - 1
if global.map_scan_countdown <= 0 then
Event.remove(defines.events.on_tick, event._handler)
-- track all radars
local radars = Surface.find_all_entities({name = 'radar'})
for i = 1, #radars do
track_entity('radars', radars[i])
end
for _, force in pairs(game.forces) do
upgrade_radars(force)
end

-- track all vehicles
local vehicles = Surface.find_all_entities({type = 'car'})
for i = 1, #vehicles do
track_entity('vehicles', vehicles[i])
end

-- track all trains
local trains = Surface.find_all_entities({type = 'locomotive'})
LOGGER.log("Locomotives found: " .. #trains)
for i = 1, #trains do
track_entity('trains', trains[i])
end

-- track all big-electric-poles
local power_poles = Surface.find_all_entities({name = 'big-electric-pole'})
for i = 1, #power_poles do
track_entity('power_poles', power_poles[i])
end

global.map_scan_countdown = nil
global.scanned_map = true
end
end
end)

Event.register(defines.events.on_research_finished, function(event)
local tech_name = event.research.name
if tech_name:starts_with('radar-amplifier') or tech_name:starts_with('radar-efficiency') then
-- update radars in 1 tick
local force = event.research.force
Event.register(defines.events.on_tick, function(event)
upgrade_radars(force)

Event.remove(defines.events.on_tick, event._handler)
end)
elseif tech_name == 'surveillance-2' then
if global.power_poles and global.surveillance_centers then
local power_poles = global.power_poles
for i = #power_poles, 1, -1 do
local entity = power_poles[i]
if entity.valid then
update_surveillance(entity, false)
else
table.remove(power_poles, i)
end
end
end
end
end)

Event.register(defines.events.on_sector_scanned, function(event)
if not global.following then return end
if event.radar.name == 'big_brother-surveillance-center' then
for i = #global.following, 1, -1 do
local entity = global.following[i]
if not entity.valid then
table.remove(global.following, i)
else
if entity.type == 'locomotive' then
local train = entity.train
local speed = train.speed
if math.abs(speed) > 0.05 then
chart_locomotive(entity, speed)
else
for _, wagon in pairs(train.cargo_wagons) do
entity.force.chart(entity.surface, Position.expand_to_area(wagon.position, 1))
end
end
else
entity.force.chart(entity.surface, Position.expand_to_area(pos, 1))
end
end
end
end
end)

function chart_locomotive(entity, speed)
local pos = entity.position

local x = pos.x + 16 * math.sin(2 * math.pi * entity.orientation)
local y = pos.y - 16 * math.cos(2 * math.pi * entity.orientation)
local area = {{x = x, y = y}, pos}
if pos.x < x then
area[1].x = pos.x
area[2].x = x
end
if pos.y < y then
area[1].y = pos.y
area[2].y = y
end
entity.force.chart(entity.surface, area)
end

function upgrade_radars(force)
if not global.radars then return end

local radar_efficiency_level = calculate_tech_level(force, 'radar-efficiency', 9)
local radar_amplifier_level = calculate_tech_level(force, 'radar-amplifier', 9)
local radar_name = 'big_brother-radar_ra-' .. radar_amplifier_level .. '_re-' .. radar_efficiency_level
LOGGER.log("Upgrading " .. force.name .. "'s radars to " .. radar_name)
for i = #global.radars, 1, -1 do
local radar = global.radars[i]
if not radar.valid then
table.remove(global.radars, i)
elseif radar.force == force then
local pos = radar.position
local direction = radar.direction
local health = radar.health
local surface = radar.surface

LOGGER.log("Upgrading radar {" .. radar.name .. "} at " .. serpent.line(pos, {comment=false}))

radar.destroy()
local new_radar = surface.create_entity({ name = radar_name, position = pos, direction = direction, force = force})
new_radar.health = health

global.radars[i] = new_radar
end
end
end

function calculate_tech_level(force, tech_name, max_levels)
for i = max_levels, 1, -1 do
local full_tech_name = tech_name
if i > 1 then
full_tech_name = tech_name .. '-' .. i
end

if force.technologies[full_tech_name].researched then
return i
end
end
return 0
end

function update_surveillance(entity, follow)
local surv_center = get_nearest_surveillance_center(entity.position, entity.surface, entity.force)
if surv_center then
local data = Entity.get_data(entity)
if not data then
if not follow then
local surveillance = entity.surface.create_entity({name = 'big_brother-surveillance-small', position = entity.position, force = entity.force})
surveillance.destructible = false
surveillance.operable = false
surveillance.minable = false
data = { surveillance = surveillance }
Entity.set_data(entity, data)
else
track_entity('following', entity)
end
end
else
if follow then
if not global.following then return end
for i = #global.following, 1, -1 do
local data = global.following[i]
if data.entity == entity then
table.remove(global.following, i)
end
end
else
local data = Entity.get_data(entity)
if data and data.surveillance and data.surveillance.valid then
data.surveillance.destroy()
Entity.set_data(entity, nil)
end
end
end
end

function get_nearest_surveillance_center(position, surface, force)
if global.surveillance_centers then
global.surveillance_centers = table.filter(global.surveillance_centers, Game.VALID_FILTER)
local list = table.filter(global.surveillance_centers, function(entity)
return entity.surface == surface and entity.force == force
end)
table.sort(list, function(a, b)
return Position.distance_squared(a.position, position) < Position.distance_squared(b.position, position)
end)
local nearest = table.first(list)
if nearest and Position.distance_squared(nearest.position, position) < MAX_SURVEILLANCE_DISTANCE_SQUARED then
return nearest
end
end
end

function track_entity(category, entity)
if not global[category] then global[category] = {} end
local entity_list = global[category]
for i = #entity_list, 1, -1 do
local e = entity_list[i]
if not e.valid then
table.remove(entity_list, i)
elseif e == entity then
return false
end
end

table.insert(entity_list, entity)
return true
end
Empty file added data-updates.lua
Empty file.
5 changes: 5 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("prototypes.technology.radar")
require("prototypes.item.surveillance")
require("prototypes.recipe.surveillance")
require("prototypes.entity.radar")
require("prototypes.entity.surveillance")
Binary file added graphics/entity/radar/radar1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/radar9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions graphics/entity/radar/split.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
files=(*.png)
count=64
for ((i=${#files[@]}-1; i >= 0; i--)); do
convert -crop 306x262 "${files[$i]}" tile_%d.png
for j in {0..3}; do
mv "tile_$((3-${j})).png" "tile_${count}.png"
echo "Moving tile_$((3-${j})).png to tile_${count}.png"
count=$((count-1))
done
done

Binary file added graphics/entity/radar/tile_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added graphics/entity/radar/tile_18.png
Binary file added graphics/entity/radar/tile_19.png
Binary file added graphics/entity/radar/tile_2.png
Binary file added graphics/entity/radar/tile_20.png
Binary file added graphics/entity/radar/tile_21.png
Binary file added graphics/entity/radar/tile_22.png
Binary file added graphics/entity/radar/tile_23.png
Binary file added graphics/entity/radar/tile_24.png
Binary file added graphics/entity/radar/tile_25.png
Binary file added graphics/entity/radar/tile_26.png
Binary file added graphics/entity/radar/tile_27.png
Binary file added graphics/entity/radar/tile_28.png
Binary file added graphics/entity/radar/tile_29.png
Binary file added graphics/entity/radar/tile_3.png
Binary file added graphics/entity/radar/tile_30.png
Binary file added graphics/entity/radar/tile_31.png
Binary file added graphics/entity/radar/tile_32.png
Binary file added graphics/entity/radar/tile_33.png
Binary file added graphics/entity/radar/tile_34.png
Binary file added graphics/entity/radar/tile_35.png
Binary file added graphics/entity/radar/tile_36.png
Binary file added graphics/entity/radar/tile_37.png
Binary file added graphics/entity/radar/tile_38.png
Binary file added graphics/entity/radar/tile_39.png
Binary file added graphics/entity/radar/tile_4.png
Binary file added graphics/entity/radar/tile_40.png
Binary file added graphics/entity/radar/tile_41.png
Binary file added graphics/entity/radar/tile_42.png
Binary file added graphics/entity/radar/tile_43.png
Binary file added graphics/entity/radar/tile_44.png
Binary file added graphics/entity/radar/tile_45.png
Binary file added graphics/entity/radar/tile_46.png
Binary file added graphics/entity/radar/tile_47.png
Binary file added graphics/entity/radar/tile_48.png
Binary file added graphics/entity/radar/tile_49.png
Binary file added graphics/entity/radar/tile_5.png
Binary file added graphics/entity/radar/tile_50.png
Binary file added graphics/entity/radar/tile_51.png
Binary file added graphics/entity/radar/tile_52.png
Binary file added graphics/entity/radar/tile_53.png
Binary file added graphics/entity/radar/tile_54.png
Binary file added graphics/entity/radar/tile_55.png
Binary file added graphics/entity/radar/tile_56.png
Binary file added graphics/entity/radar/tile_57.png
Binary file added graphics/entity/radar/tile_58.png
Binary file added graphics/entity/radar/tile_59.png
Binary file added graphics/entity/radar/tile_6.png
Binary file added graphics/entity/radar/tile_60.png
Binary file added graphics/entity/radar/tile_61.png
Binary file added graphics/entity/radar/tile_62.png
Binary file added graphics/entity/radar/tile_63.png
Binary file added graphics/entity/radar/tile_64.png
Binary file added graphics/entity/radar/tile_7.png
Binary file added graphics/entity/radar/tile_8.png
Binary file added graphics/entity/radar/tile_9.png
Binary file added graphics/entity/surveillance/surveillance.png
Binary file added graphics/entity/surveillance/tile-0.png
Binary file added graphics/entity/surveillance/tile-1.png
Binary file added graphics/entity/surveillance/tile-10.png
Binary file added graphics/entity/surveillance/tile-11.png
Binary file added graphics/entity/surveillance/tile-12.png
Binary file added graphics/entity/surveillance/tile-13.png
Binary file added graphics/entity/surveillance/tile-14.png
Binary file added graphics/entity/surveillance/tile-15.png
Binary file added graphics/entity/surveillance/tile-16.png
Binary file added graphics/entity/surveillance/tile-17.png
Binary file added graphics/entity/surveillance/tile-18.png
Binary file added graphics/entity/surveillance/tile-19.png
Binary file added graphics/entity/surveillance/tile-2.png
Binary file added graphics/entity/surveillance/tile-20.png
Binary file added graphics/entity/surveillance/tile-21.png
Binary file added graphics/entity/surveillance/tile-22.png
Binary file added graphics/entity/surveillance/tile-23.png
Binary file added graphics/entity/surveillance/tile-24.png
Binary file added graphics/entity/surveillance/tile-25.png
Binary file added graphics/entity/surveillance/tile-26.png
Binary file added graphics/entity/surveillance/tile-27.png
Binary file added graphics/entity/surveillance/tile-28.png
Binary file added graphics/entity/surveillance/tile-29.png
Binary file added graphics/entity/surveillance/tile-3.png
Binary file added graphics/entity/surveillance/tile-30.png
Binary file added graphics/entity/surveillance/tile-31.png
Binary file added graphics/entity/surveillance/tile-32.png
Binary file added graphics/entity/surveillance/tile-33.png
Binary file added graphics/entity/surveillance/tile-34.png
Binary file added graphics/entity/surveillance/tile-35.png
Binary file added graphics/entity/surveillance/tile-36.png
Binary file added graphics/entity/surveillance/tile-37.png
Binary file added graphics/entity/surveillance/tile-38.png
Binary file added graphics/entity/surveillance/tile-39.png
Binary file added graphics/entity/surveillance/tile-4.png
Binary file added graphics/entity/surveillance/tile-40.png
Binary file added graphics/entity/surveillance/tile-41.png
Binary file added graphics/entity/surveillance/tile-42.png
Binary file added graphics/entity/surveillance/tile-43.png
Binary file added graphics/entity/surveillance/tile-44.png
Binary file added graphics/entity/surveillance/tile-45.png
Binary file added graphics/entity/surveillance/tile-46.png
Binary file added graphics/entity/surveillance/tile-47.png
Binary file added graphics/entity/surveillance/tile-48.png
Binary file added graphics/entity/surveillance/tile-49.png
Binary file added graphics/entity/surveillance/tile-5.png
Binary file added graphics/entity/surveillance/tile-50.png
Binary file added graphics/entity/surveillance/tile-51.png
Binary file added graphics/entity/surveillance/tile-52.png
Binary file added graphics/entity/surveillance/tile-53.png
Binary file added graphics/entity/surveillance/tile-54.png
Binary file added graphics/entity/surveillance/tile-55.png
Binary file added graphics/entity/surveillance/tile-56.png
Binary file added graphics/entity/surveillance/tile-57.png
Binary file added graphics/entity/surveillance/tile-58.png
Binary file added graphics/entity/surveillance/tile-59.png
Binary file added graphics/entity/surveillance/tile-6.png
Binary file added graphics/entity/surveillance/tile-60.png
Binary file added graphics/entity/surveillance/tile-61.png
Binary file added graphics/entity/surveillance/tile-62.png
Binary file added graphics/entity/surveillance/tile-63.png
Binary file added graphics/entity/surveillance/tile-7.png
Binary file added graphics/entity/surveillance/tile-8.png
Binary file added graphics/entity/surveillance/tile-9.png
Binary file added graphics/icons/radar-amplifier.png
Binary file added graphics/icons/radar-efficiency.png
Binary file added graphics/icons/surveillance.png
Binary file added graphics/icons/tech_surveillance.png
9 changes: 9 additions & 0 deletions info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Big_Brother",
"version": "{{VERSION}}",
"title": "Big Brother",
"author": "Afforess",
"homepage": "http://afforess.com",
"description": "Proudly building the perfect surveillance state",
"dependencies": ["base >= 0.12.31"]
}
Loading

0 comments on commit bc08869

Please sign in to comment.