#Only been playing factorio for a few
1 messages · Page 1 of 1 (latest)
Ideally normal lamps/lights would also negate the penalty if the enemy is illuminated, but that can be skipped if too hard.
Also, if I can include the player in the penalty/buff nightvision should also remove the range debuff from the player, too.
If Searchlight Assault gives a buff, then it's probably possible to give a debuff to things.
Just look into the code of Searchlight Assault to figure out how it does things, and then tweak it to basically do the inverse
I'm more wondering about things like
-
Can I easily trigger something happen based on "is it night?" or "level of light"
-
Will this need to be applied 1-by-one to each existing turret, or is there any easy 'main' 'turret range' stat I could asdjust
IDEALLY IDEALLY
Instead of just being binary "is day/night?" I can just use overall light level, which seems like what solar panels do?
[R] :: float
Amount of darkness at the current time, as a number in range [0, 1].
There's also a daytime for use in time of day if need be
And in regards to turrets, I don't actually know
My gut says you'll have to affect every single turret individually, but there's also team buffs from technology
Either way, you'd probably want to only affect the turrets on a single surface when that surface gets too dark
It may not matter as much right now with 1.0, but with SA using it, it'll probably actually matter
True
Looking through SLA it looks like it has each light, when it activates boost look for all nearby objects that contain ammo and swap the ammo out for a new "boosted" ammo, and then swap it back when the boost is over.
Seems pretty kludgy.
Has a lot of safety checks to make sure the player doesn't design a way to get boosted ammo out of the area before the light can un-boost it to keep boosted ammo permanently.
Honestly sounds about right..
Modifying anything that you would define in a prototype tends to be pretty complicated
So, if I wanted to do what I wanted, I'd probably need to do something like:
- onTick on each surface check light level
- find all ammo on that surface
- (if not wearing nightvision, or otherwise immune) swap all ammo out with new light-adjusted ammo
Then, to apply "target iluminated" bonuses, I'd need to check if anything is actively shooting (I don't see like, an "onShoot" or "onAttack" event) and
- find their target
- check if the target is within a certain radius of a light/lamp, or currently targeted by a searchlight
- if so - swap their ammo out for normal ammo
That has nasty possible problems like in SE being able to move ammo on/off surface to retain boost/unboost properties. 
This would be best if I could find some onShoot method and just check surface light, and target illumination directly before the shot is fired.
I think turrets have Triggers for making the little bullet casing particles
You can make a script trigger in that, but I'm pretty sure it happens with the shooting and not before it
And it wouldn't give any information like who it's shooting afaik so you couldn't fake it by just damaging the biter more
I did see turrets have a "shooting Target" member that' R/W, but again, I'd need to know when they want to shoot
I don't know exactly how inserters/turrets behave, but if you add an extra slot for ammo you might be able to get away with only transforming the ammo within the turret
The inserter could insert into the other slot when it's low and then you'd come along a few ticks later and notice some of the wrong ammo and convert it and merge it into the initial stack
IIRC SLA just checks any entity with an inventory 4 units away from any turret and sees if it has any boost ammo and swap it back for normal ammo
There's also find_nearest_enemy, but doing a find nearest on every turret and player on every surface every tick also seems crazy
I'm thinking more about how you would go about downgrading ammo in every turret but not downgrading literally every ammo piece
And with this method, you could just not downgrade it if it's in the range of a searchlight
But yeah, I wouldn't be surprised if no matter what you do, it'd be kinda ups expensive
If you're willing to go mult-surface unsafe, you can just enable/disable a hidden research to use the technology effects to do it
And just choose a downgrade that directly blocks the boost searchlight does
I think SLA gets around it by the fact that the light 'links' to SPECIFIC turrets and only boosts those.
I think if it did more, or if you built a ton of lights + a ton of turrets, it'd probably be hell on UPS
I think looking at what's exposed by the game, I don't see a 'good' way to accomplish what I want, sadly. There's possible some super kludgy UPS-murdering ways with that would be fragile and possibly exploitable... but that doesn't seem worth it.
Oh if you want to make the technology hack multi-surface safe
You can just change the force of players nvm remote view would probably counter-act that
Unless you can tell that the player is looking at another surface
Which you probably can. Especially as you can get which entity the player currently has selected (hovered with their mouse)
And I wouldn't be surprised if a api request is written for an event on switching surfaces in person or in remote view
There's on_player_changed_surface
I didn't see the way to detect the player's hovered entity though?
I see on_gui_hover? But that's only gui objects
I'm pretty sure it's just checking this field
https://lua-api.factorio.com/latest/classes/LuaControl.html#selected
And the only reason I think it's writable, is controller support
I could be wrong though
I haven't used it myself
Oh, does it? Based on reading it, it sounded like it was like.. when you click on something?
Like, selecting a train for example
That would be opened
The currently selected entity. Assigning an entity will select it if is selectable, otherwise the selection is cleared.
I think you may be right based on this one:
update_selected_entity(position)
Select an entity, as if by hovering the mouse above it.
I think it's talking about this
Oooh
Yeah, I think it's writable simply because controllers move by relation to their selected entity
What makes this extra fiddly to think about is stuff like the auto-targetting behavior of the SMG and pistol.
You don't have to even select an enemy
(Also ignore the biter corpses. I simply used the save I used to test a fix on exfret's biter memoirs)
So like, if you assume the player is standing with an enemy on the right and another on the left, and one is in the dark and the other in the light, the idea would be even if they're both the same distance away, the one in the dark might be out of range while the one in the light would be in range
I honestly don't see a way to do that with the current limitations
You could abstract it and base it on the PLAYER being in the light, but that's NOT what I want. 😦
I would really need some kind of on_pre_attack event.. and even then it'd probably be super bad for the AI.
Like, when the AI is picking which target to attack, it'd need to know which ones are valid based on range...which would be based on light.
I suppose instead of range, maybe you could approximate some 'inaccuracy' by giving enemies in the dark some level of damage mitigation?? 
So like... enemies in the dark take 25% less damage or something?
That might be easier... let me look into that
That sounds more impossible to me :/
Why? 
Modifying biter data :)
Yeah, looking for resistance only brings up the prototype items
Unless you want to heal the biters that get damaged in the dark
That.. that might work
I think it may be more easily kludgable though:
on_entity_damaged- check surface light level
- look for nearby lights
- undo some damage
yeah
That's smarter than I was thinking
And you can filter for the type of "unit" since that's what biters are
And I think what basically any entity with any sort of pathing Ai is
(I'm basing this off of biter memoirs which I did not write, but I have contributed to)
That is assuming the damage doesn't instantly kill the target before the end of tick.
My assumption is something like
- damage applied
on_entity_damagedsent- my script heals the target
- death is checked
but it might not happen in that order
I would assume that's a pretty safe bet
Simply because that's a thing many people would want to do and it would be api requested to hell and back if it wasn't
Looks like you can also set LuaEntityDamagedEventFilter so you only get on damage events from biters
Yeah, filter for the type "unit"
It'll be a little more broad, but it should also include aai tanks and such
This one is a little weird:
I might even be able to remove damage before it's actually taken?
I assume that's because the event data might get out of date if you apply your own damage to it in the middle of the event
And it was easy to expose since it already accumulates the damage before dealing it so it could process deaths separately
(all assumptions)
So, I should be able to
- get
on_damagedfiltered to units - check the source, if the source is immune to darkness (nightvision, etc), return
- check damage type, probably ignore flamethrowers and explosive
- check around the damaged unit for light sources
- create a damage 'rebate' based on the light level & damage type
- remove the damage rebate from 'damage_to_be_taken`
Confirming this creates invulnerable entities. So that part works.
Not sure what 'pending damage' does, it always seems to be 0, even when it's set. Might have to do with poison or something
hmm
Maybe I'm blind, but is there a quick/easy way to tell if a lamp is powered+on?
I'm not seeing it, but I did find https://lua-api.factorio.com/latest/classes/LuaControl.html#is_flashlight_enabled
I know lamps kind of turn on a little scattered so I wouldn't be surprised if it's just not exposed to lua
Since that to me sounds like shenanigans in the engine that make exposing it non-trivial
There are these on the Prototype though
I'm going to just assume that despite visuals any powered non-disabled lamp is 'on', but I need to check if it's disabled
There's a disabled but it mentiones disabled by circuit logic specifically
Not sure if there's other more generic disable checks
(since they get turned on at some point in that range)
looks like entity.get_control_behavior().disabled
disabled is in LuaGenericOnOffControlBehavior which lamp's controller inherits from
Going to hope that works as expected
then need to check power
That's very specifically from control Behavior, so I'd be shocked if it responds that it's off
I still think your best bet is to check the prototype and rely on it being darker than darkness_for_all_lamps_off as that should be when they start turning on
There might be some discontinuity, but I think biters getting hurt more than they should is a lot more fun than not getting hurt enough
(I need to go to bed now so have fun)
This seems to work