Skip to content

Commit

Permalink
Make complexDroneCount() not stupid. (stonepillars/goon-flock#300)
Browse files Browse the repository at this point in the history
* associative lists, as anything, length()

* Update code/datums/flock/flock.dm

Co-authored-by: Ryan <53062374+FlameArrow57@users.noreply.github.com>

* i cant merge if i had a gun pointed to my brain

Co-authored-by: Ryan <53062374+FlameArrow57@users.noreply.github.com>
Co-authored-by: stonepillars <65367576+stonepillars@users.noreply.github.com>
  • Loading branch information
3 people authored May 21, 2022
1 parent 5db8888 commit 7366b9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
49 changes: 27 additions & 22 deletions code/datums/flock/flock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
var/list/trace_minds = list()
/// Store the mind of the current flockmind
var/datum/mind/flockmind_mind = null
/// Stores associative lists of type => list(units) - do not edit directly, use removeDrone() and registerUnit()
var/list/units = list()
var/list/enemies = list()
///Associative list of objects to an associative list of their annotation names to images
Expand All @@ -40,6 +41,7 @@
src.unlockableStructures += new DT(src)
if (!annotation_imgs)
annotation_imgs = build_annotation_imgs()
src.units[/mob/living/critter/flock/drone] = list() //this one needs initialising

/datum/flock/ui_status(mob/user)
// only flockminds and admins allowed
Expand Down Expand Up @@ -113,7 +115,7 @@

// DESCRIBE DRONES
var/list/dronelist = list()
for(var/mob/living/critter/flock/drone/F in src.units)
for(var/mob/living/critter/flock/drone/F as anything in src.units[/mob/living/critter/flock/drone])
dronelist += list(F.describe_state())
state["drones"] = dronelist

Expand Down Expand Up @@ -154,18 +156,19 @@
/datum/flock/proc/total_health_percentage()
var/hp = 0
var/max_hp = 0
for(var/mob/living/critter/flock/F as anything in src.units)
F.count_healths()
hp += F.health
max_hp += F.max_health
for(var/pathkey in src.units)
for(var/mob/living/critter/flock/F as anything in src.units[pathkey])
F.count_healths()
hp += F.health
max_hp += F.max_health
if(max_hp != 0)
return hp/max_hp
else
return 0

/datum/flock/proc/total_resources()
. = 0
for(var/mob/living/critter/flock/F as anything in src.units)
for(var/mob/living/critter/flock/drone/F as anything in src.units[/mob/living/critter/flock/drone])
. += F.resources


Expand All @@ -174,10 +177,11 @@
var/comp_provided = 0
if (src.hasAchieved("infinite_compute"))
return 1000000
for(var/mob/living/critter/flock/F as anything in src.units)
comp_provided = F.compute_provided()
if(comp_provided>0)
. += comp_provided
for(var/pathkey in src.units)
for(var/mob/living/critter/flock/F as anything in src.units[pathkey])
comp_provided = F.compute_provided()
if(comp_provided>0)
. += comp_provided

for(var/obj/flock_structure/S as anything in src.structures)
comp_provided = S.compute_provided()
Expand All @@ -188,10 +192,11 @@
/datum/flock/proc/used_compute()
. = 0
var/comp_provided = 0
for(var/mob/living/critter/flock/F as anything in src.units)
comp_provided = F.compute_provided()
if(comp_provided<0)
. += abs(comp_provided)
for(var/pathkey in src.units)
for(var/mob/living/critter/flock/F as anything in src.units[pathkey])
comp_provided = F.compute_provided()
if(comp_provided<0)
. += abs(comp_provided)

for(var/obj/flock_structure/S as anything in src.structures)
comp_provided = S.compute_provided()
Expand Down Expand Up @@ -409,14 +414,16 @@

/datum/flock/proc/registerUnit(var/atom/movable/D)
if(isflock(D))
src.units |= D
if(!src.units[D.type])
src.units[D.type] = list()
src.units[D.type] |= D
D.AddComponent(/datum/component/flock_interest, src)
var/datum/abilityHolder/flockmind/aH = src.flockmind.abilityHolder
aH.updateCompute()

/datum/flock/proc/removeDrone(var/atom/movable/D)
if(isflock(D))
src.units -= D
src.units[D.type] -= D
D.GetComponent(/datum/component/flock_interest)?.RemoveComponent(/datum/component/flock_interest)
if(D:real_name && busy_tiles[D:real_name])
src.unreserveTurf(D:real_name)
Expand Down Expand Up @@ -463,10 +470,7 @@
aH.updateCompute()

/datum/flock/proc/getComplexDroneCount()
var/count = 0
for(var/mob/living/critter/flock/drone/D in src.units)
count++
return count
return length(src.units[/mob/living/critter/flock/drone/])

/datum/flock/proc/toggleDeconstructionFlag(var/atom/target)
toggleAnnotation(target, FLOCK_ANNOTATION_DECONSTRUCT)
Expand Down Expand Up @@ -517,8 +521,9 @@
hideAnnotations(src.flockmind)
for(var/mob/living/intangible/flock/trace/T as anything in src.traces)
T.death()
for(var/mob/living/critter/flock/F as anything in src.units)
F.dormantize()
for(var/pathkey in src.units)
for(var/mob/living/critter/flock/F as anything in src.units[pathkey])
F.dormantize()
for(var/obj/flock_structure/S as anything in src.structures)
src.removeStructure(S)
qdel(get_image_group(src))
Expand Down
2 changes: 1 addition & 1 deletion code/mob/living/critter/flock/flockdrone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@

/mob/living/critter/flock/drone/proc/move_controller_to_station()
if (src.flock?.getComplexDroneCount() > 1)
for (var/mob/living/critter/flock/drone/F in src.flock.units)
for (var/mob/living/critter/flock/drone/F as anything in src.flock.units[/mob/living/critter/flock/drone])
if (istype(F) && F != src)
src.controller.set_loc(get_turf(F))
break
Expand Down

0 comments on commit 7366b9d

Please sign in to comment.