Skip to content

Commit

Permalink
- NextDay currently broken!
Browse files Browse the repository at this point in the history
- Fixes #74
- Massive update to jobs
  • Loading branch information
XelaPy committed Aug 19, 2015
1 parent c54bd05 commit 9a0ada5
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 61 deletions.
87 changes: 72 additions & 15 deletions game/library/businesses&buildings/classes - core buildings.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,30 @@ init -9 python:

self.clients = set()

def run_nd(self):
tl.timer("Temp Jobs Loop")
# Setup and start the simulation
self.clients = nd_clients
for up in self._upgrades:
up.run_nd()

self.log("\n\n")
self.log(set_font_color("===================", "lawngreen"))
self.log("{}".format(set_font_color("Starting the simulation:", "lawngreen")))
self.log("{}".format(set_font_color("Testing a Brothel with two rooms:", "lawngreen")))
# random.seed(RANDOM_SEED) # This helps reproducing the results

# Create an environment and start the setup process
self.env = simpy.Environment()
self.env.process(self.setup(end=100))
self.env.run(until=100)
self.log("{}".format(set_font_color("Ending the First Stage:", "red")))
env.run(until=110)
self.log("{}".format(set_font_color("Ending the simulation:", "red")))
self.log("{}".format(set_font_color("===================", "red")))
self.log("\n\n")
tl.timer("Temp Jobs Loop")

def log(self, item):
# Logs the text to log...
self.nd_events_report.append(item)
Expand Down Expand Up @@ -486,38 +510,71 @@ init -9 python:
"""
temp = "There is not much for the {} to do...".format(client.name)
self.log(temp)
yield self.env.timeout(1)
# yield self.env.timeout(1)
temp = "So {} leaves the hotel cursing...".format(client.name)
self.log(temp)

def setup(env, end=40):
def setup(self, end=40):
upgrades = list(up for up in self._upgrades if up.workable)
i = 0
while self.clients:
if self.env.now + 5 <= end: # This is a bit off... should we decide which action should be taken first?
if i > 4:
yield self.env.timeout(random.randint(1, 3))
i += 1
store.client = self.pop()
store.client = self.clients.pop()
store.client.name = "Client {}".format(i)

# Register the fact that client arrived at the building:
temp = '{} arrives at the {} at {}.'.format(client.name, self.name, self.env.now)
self.log(temp)

# Take an action!
whores = list(i for i in store.nd_chars if "SIW" in i.occupations)
strippers = list(i for i in store.nd_chars if traits["Stripper"] in i.occupations)
servers = list(i for i in store.nd_chars if "Server" in i.occupations)
# whores = list(i for i in store.nd_chars if "SIW" in i.occupations)
# strippers = list(i for i in store.nd_chars if traits["Stripper"] in i.occupations)
# servers = list(i for i in store.nd_chars if "Server" in i.occupations)

for upgrade in upgrades: # This assumes that job requires clients at the moment.
# STOPPED HERE!
if upgrade.res.count < upgrade.capacity and upgrade.has_worker:
env.process(upgrade.brothel_client_dispatcher(env, store.client))
elif upgrade.sc.res.count < upgrade.sc.cap:
env.process(upgrade.sc_client_dispatcher(env, store.client))
else:
env.process(upgrade.kick_client(client))
# Take an action!
for upgrade in upgrades:
if upgrade.res.count < upgrade.capacity and upgrade.has_workers():
# Assumes a single worker at this stage... This part if for upgrades like Brothel.
if upgrade.requires_workers():
store.char = None
while store.nd_chars:

# Here we should attempt to find the best match for the client!
store.char = upgrade.get_workers()

# First check is the char is still well and ready:
if not check_char(store.char):
if store.char in store.nd_chars:
store.nd_chars.remove(store.char)
temp = set_font_color('{} is done with this job for the day.'.format(store.char.name), "aliceblue")
self.log(temp)
continue

# We to make sure that the girl is willing to do the job:
temp = store.char.action.id
if not store.char.action.check_occupation(store.char):
if store.char in store.nd_chars:
store.nd_chars.remove(store.char)
temp = set_font_color('{} is not willing to do {}.'.format(store.char.name, temp), "red")
self.log(temp)
continue
break # Breaks the while loop.

if store.char:
store.client = client
self.env.process(upgrade.request(env, client))
break
else:
continue
# Jobs like the Club:
else:
self.env.process(upgrade.request(env, client))
break

else: # If nothing was found, kick the client:
self.env.process(self.kick_client(client))
else:
break

43 changes: 22 additions & 21 deletions game/library/businesses&buildings/classes - jobs.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -1280,33 +1280,34 @@
self.apply_stats()
self.finish_job()

def clients_relays(self):
"""
Gets the clients that the girl strips for.
"""
total_clients = len(store.clients)
clients = len(self.clients)
c_cnt = plural("client", clients)

# Get proper text for the amount of clients
if clients > int(total_clients * 0.7):
self.txt.append('%d %s came to see her strip and dance in the club! It is a most impressive feat for one girl to attract so many! \n '%(clients, c_cnt))
elif int(total_clients * 0.5) <= clients <= int(total_clients * 0.7):
self.txt.append('%d %s came to see her strip and dance in the club! This is a very respectable amount of fans for one girl to have! \n '%(clients, c_cnt))
elif int(total_clients * 0.25) <= clients <= int(total_clients * 0.5):
self.txt.append('%d %s came to see her strip and dance in the club! Not bad at all considering the size of the brothel! \n'%(clients, c_cnt))
elif int(total_clients * 0.1) <= clients <= int(total_clients * 0.25):
self.txt.append("%d %s came to see her strip, not the most impressive amount, but everyone has to start somewhere. \n"%(clients, c_cnt))
else:
self.txt.append("Just a couple of clients came to check your girl out, very poor result indeed. ")
# def clients_relays(self):
# """
# Gets the clients that the girl strips for.
# """
# total_clients = len(store.clients)
# clients = len(self.clients)
# c_cnt = plural("client", clients)
# # Get proper text for the amount of clients
# if clients > int(total_clients * 0.7):
# self.txt.append('%d %s came to see her strip and dance in the club! It is a most impressive feat for one girl to attract so many! \n '%(clients, c_cnt))
# elif int(total_clients * 0.5) <= clients <= int(total_clients * 0.7):
# self.txt.append('%d %s came to see her strip and dance in the club! This is a very respectable amount of fans for one girl to have! \n '%(clients, c_cnt))
# elif int(total_clients * 0.25) <= clients <= int(total_clients * 0.5):
# self.txt.append('%d %s came to see her strip and dance in the club! Not bad at all considering the size of the brothel! \n'%(clients, c_cnt))
# elif int(total_clients * 0.1) <= clients <= int(total_clients * 0.25):
# self.txt.append("%d %s came to see her strip, not the most impressive amount, but everyone has to start somewhere. \n"%(clients, c_cnt))
# else:
# self.txt.append("Just a couple of clients came to check your girl out, very poor result indeed. ")

def strip(self):
"""
Solves the main job logic.
Applies effects to the girl, runs at the end of the job.
"""

tippayout = 0
len_clients = len(self.clients)
# tippayout = 0
# len_clients = len(self.clients)

# Upgrades
# scbu = self.loc.get_upgrade_mod("stipclub")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ init -9 python:
self.cost = cost # Price in gold.

self.jobs = set() # Jobs this upgrade can add. *We add job instances here!
self.workers = set() # List of on duty characters.

self.habitable = False
self.workable = False
Expand All @@ -34,15 +35,33 @@ init -9 python:
# Logs the text to log...
self.instance.nd_events_report.append(item)

def has_worker(self):
# Checks if there is a worker availible.
def has_workers(self, amount=1):
# Checks if there is a worker(s) availible.
return False

def get_workers(self, amount=1):
# Finds a best match for workers and returns them...
return None

def requires_workers(self, amount=1):
"""
Returns True if this upgrade requires a Worker to run this job.
Example: Brothel
Strip Club on the other hand may nor require one or one would be requested later.
It may be a better bet to come up with request_worker method that evaluates the same ealier, we'll see.
"""
return False

def run_nd(self):
# Runs at the very start of execusion of SimPy loop during the next day.
return

@property
def all_occs(self):
s = set()
for i in self.jobs:
s = s | i.all_occs
return s


class MainUpgrade(BuildingUpgrade):
Expand All @@ -64,9 +83,41 @@ init -9 python:
self.res = None # Restored before every job...
self.time = 5 # Same

def has_worker(self):
def has_workers(self):
return list(i for i in store.nd_chars if self.all_occs & i.occupations)

def requires_workers(self, amount=1):
return True

def get_workers(self, amount=1):
"""
This is quite possibly an overkill for this stage of the game development.
"""
workers = list()

# First gets the workers assigned directly to this upgrade as a priority.
priority = list(i for i in store.nd_chars if i.workplace == self and self.all_occs & i.occupations)
for i in range(amount):
try:
workers.append(priority.pop())
except:
break
if len(workers) < amount:
# Next try to get anyone availible:
anyw = list(i for i in store.nd_chars if self.all_occs & i.occupations)
for i in range(amount-len(workers)):
try:
workers.append(priority.pop())
except:
break
if len(workers) == amount:
if len(workers) == 1:
return workers.pop()
# When we'll have jobs that require moar than one worker, we'll add moar code here.

def run_nd(self):
self.res = simpy.Resource(self.env, self.capacity)

def request(self, client):
with self.res.request() as request:
yield request
Expand Down Expand Up @@ -102,7 +153,7 @@ init -9 python:
class StripClub(MainUpgrade):
def __init__(self, name="Strip Club", instance=None, desc="Exotic Dancers go here!", img="content/buildings/upgrades/strip_club.jpg", build_effort=0, materials=None, in_slots=5, cost=500, **kwargs):
super(StripClub, self).__init__(name=name, instance=instance, desc=desc, img=img, build_effort=build_effort, materials=materials, cost=cost, **kwargs)
self.jobs = set(["Stripper"])
self.jobs = set([simple_jobs["Striptease Job"]])
self.workable = True

self.capacity = in_slots
Expand All @@ -114,6 +165,9 @@ init -9 python:

self.earned_cash = 0

def run_nd(self):
self.res = simpy.Resource(self.env, self.capacity)

def request(self, client):
with self.res.request() as request:
yield request
Expand All @@ -122,7 +176,7 @@ init -9 python:
temp = "{} enters the Strip Club at {}".format(client.name, self.env.now)
self.log(temp)

yield self.env.process(self.run_sc_job(client, store.char))
yield self.env.process(self.run_job(client, store.char))

temp = "{} leaves the Club at {}".format(client.name, self.env.now)
self.log(temp)
Expand Down
2 changes: 1 addition & 1 deletion game/library/characters/classes - characters.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ init -9 python:

@property
def workplace(self):
return self._workpace
return self._workplace

@workplace.setter
def workplace(self, value):
Expand Down
83 changes: 77 additions & 6 deletions game/library/custom-screens.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ init: # PyTFall:
screen poly_matrix(in_file, show_exit_button=False):
# If a tuple with coordinates is provided instead of False for show_exit_button, exit button will be placed there.

default tooltip = False

on "hide":
action SetField(config, "mouse", None)

Expand All @@ -927,17 +929,86 @@ init: # PyTFall:

$ func = renpy.curry(point_in_poly)
for i in matrix:
button:
background Null()
focus_mask func(i["xy"]) # Function(point_in_poly, mp[0], mp[1], i["xy"])
action Return(i["id"])
hovered SetField(config, "mouse", {"default": [("content/gfx/interface/icons/zoom_32x32.png", 0, 0)]})
unhovered SetField(config, "mouse", None)
if "tooltip" in i:
if "align" in i:
python:
align = tuple(i["align"])
pos = ()
anchor = ()
else:
python:
align = ()
# Get a proper placement:
allx, ally = list(), list()
# maxx, minx, maxy, miny = 0, 0, 0, 0

for t in i["xy"]:
allx.append(t[0])
ally.append(t[1])

maxx = max(allx)
maxy = max(ally)
minx = min(allx)
miny = min(ally)

w, h = config.screen_width, config.screen_height

side = i.get("place", "left")

if side == "left":
pos = (minx - 20, sum(ally)/len(ally))
anchor = (1.0, 0.5)
elif side == "right":
pos = (maxx + 20, sum(ally)/len(ally))
anchor = (0.0, 0.5)
elif side == "bottom":
pos = (sum(allx)/len(allx), maxy + 20)
anchor = (0.5, 0.0)
elif side == "top":
pos = (sum(allx)/len(allx), miny - 20)
anchor = (0.5, 1.0)

button:
background Null()
focus_mask func(i["xy"]) # Function(point_in_poly, mp[0], mp[1], i["xy"])
action Return(i["id"])
hovered [SetField(config, "mouse", {"default": [("content/gfx/interface/icons/zoom_32x32.png", 0, 0)]}),
Show("show_poly_matrix_tt", pos=pos, anchor=anchor, align=align, text=i["tooltip"]), With(dissolve)]
# SetScreenVariable("tooltip", (i["tooltip"], align, pos))]
unhovered [SetField(config, "mouse", None),
Hide("show_poly_matrix_tt"), With(dissolve)]
# SetScreenVariable("tooltip", False)]
else:
button:
background Null()
focus_mask func(i["xy"]) # Function(point_in_poly, mp[0], mp[1], i["xy"])
action Return(i["id"])
hovered SetField(config, "mouse", {"default": [("content/gfx/interface/icons/zoom_32x32.png", 0, 0)]})
unhovered SetField(config, "mouse", None)

if show_exit_button:
textbutton "All Done":
align show_exit_button
action Return(False)

# if tooltip:
# frame:
# if tooltip[2]:
# pos tooltip[2]
# anchor tooltip[3]
# elif tooltip[1]:
# align tooltip[1]
# text tooltip[0] + ", ".join(str(i) for i in tooltip[2])

screen show_poly_matrix_tt(pos=(), anchor=(), align=(), text=""):
zorder 1
frame:
if align:
align align
if pos:
pos pos
anchor anchor
text text # + "pos".join(str(i) for i in pos) + "align".join(str(i) for i in align)

##############################################################################
screen notify:
Expand Down

0 comments on commit 9a0ada5

Please sign in to comment.