diff options
Diffstat (limited to 'src/scenes')
| -rw-r--r-- | src/scenes/place_detail.c | 8 | ||||
| -rw-r--r-- | src/scenes/save_state_select.c | 213 |
2 files changed, 219 insertions, 2 deletions
diff --git a/src/scenes/place_detail.c b/src/scenes/place_detail.c index 49973a4..f214347 100644 --- a/src/scenes/place_detail.c +++ b/src/scenes/place_detail.c @@ -984,18 +984,22 @@ static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_jo if (scheduled_time.day == SUNDAY) highlight_y = TILE_Y(MONDAY);
if (overflow_to_next_day > 0) {
- int extra_days = overflow_to_next_day / TIME_SLOTS_PER_DAY;
+ int extra_days = ceil(overflow_to_next_day / (float)TIME_SLOTS_PER_DAY);
int curr_day = scheduled_time.day;
+ //printf("%d %d %d\n", extra_days, duration_of_job_measured_in_timeslots_max, overflow_to_next_day);
for (int xx = 0; xx < extra_days; xx++) {
s32 overflow = overflow_to_next_day % TIME_SLOTS_PER_DAY;
if (xx != extra_days-1) overflow = TIME_SLOTS_PER_DAY;
+ else if (overflow == 0) {
+ overflow = TIME_SLOTS_PER_DAY;
+ }
if (curr_day == SUNDAY) {
curr_day = MONDAY;
highlight_y = TILE_Y(MONDAY);
}
- printf("%d %d %d\n", overflow_to_next_day, extra_days, overflow);
+ //printf("%d %d %d\n", overflow_to_next_day, extra_days, overflow);
renderer->render_rectangle(TILE_X(0), highlight_y, timeslot_w*overflow, timeslot_h, tile_color_bg);
overflow_to_next_day -= TIME_SLOTS_PER_DAY;
highlight_y += timeslot_h;
diff --git a/src/scenes/save_state_select.c b/src/scenes/save_state_select.c index eea022d..af2abe6 100644 --- a/src/scenes/save_state_select.c +++ b/src/scenes/save_state_select.c @@ -567,8 +567,220 @@ static void load_save_file(s32 index) array_push(&existing_loc->schedule.jobs, &existing_job);
}
+
+ GET_PROP(insights, location_iter, "insights");
+ cJSON* insight_iter;
+ cJSON_ArrayForEach(insight_iter, insights)
+ {
+ money_data_collection year_data;
+ memset(&year_data, 0, sizeof(money_data_collection));
+
+ for (int i = 0; i < MONTHS_IN_YEAR; i++)
+ {
+ year_data.months[i].total_income = NAN;
+ }
+
+ GET_PROP(months, insight_iter, "months");
+ cJSON* month_iter;
+ cJSON_ArrayForEach(month_iter, months)
+ {
+ money_data month;
+
+ GET_PROP(total_income, month_iter, "total_income");
+ month.total_income = (float)total_income->valuedouble;
+
+ GET_PROP(total_expenses, month_iter, "total_expenses");
+ month.total_expenses = (float)total_expenses->valuedouble;
+
+ GET_PROP(total_profit, month_iter, "total_profit");
+ month.total_profit = (float)total_profit->valuedouble;
+
+ GET_PROP(income_from_trips, month_iter, "income_from_trips");
+ month.income_from_trips = (float)income_from_trips->valuedouble;
+
+ GET_PROP(expenses_from_trucks, month_iter, "expenses_from_trucks");
+ month.expenses_from_trucks = (float)expenses_from_trucks->valuedouble;
+
+ GET_PROP(expenses_from_utility, month_iter, "expenses_from_utility");
+ month.expenses_from_utility = (float)expenses_from_utility->valuedouble;
+
+ GET_PROP(expenses_from_loans, month_iter, "expenses_from_loans");
+ month.expenses_from_loans = (float)expenses_from_loans->valuedouble;
+
+ GET_PROP(expenses_from_healthcare, month_iter, "expenses_from_healthcare");
+ month.expenses_from_healthcare = (float)expenses_from_healthcare->valuedouble;
+
+ GET_PROP(expenses_from_repairs, month_iter, "expenses_from_repairs");
+ month.expenses_from_repairs = (float)expenses_from_repairs->valuedouble;
+
+ GET_PROP(expenses_from_fuel, month_iter, "expenses_from_fuel");
+ month.expenses_from_fuel = (float)expenses_from_fuel->valuedouble;
+
+ GET_PROP(expenses_from_employees, month_iter, "expenses_from_employees");
+ month.expenses_from_employees = (float)expenses_from_employees->valuedouble;
+
+ GET_PROP(index, month_iter, "index");
+ year_data.months[index->valueint] = month;
+ }
+
+ array_push(&existing_loc->insights, &year_data);
+ }
+ }
+
+ GET_PROP(insights, json_object, "insights");
+ cJSON* insight_iter;
+ cJSON_ArrayForEach(insight_iter, insights)
+ {
+ money_data_collection year_data;
+ memset(&year_data, 0, sizeof(money_data_collection));
+
+ for (int i = 0; i < MONTHS_IN_YEAR; i++)
+ {
+ year_data.months[i].total_income = NAN;
+ }
+
+ GET_PROP(months, insight_iter, "months");
+ cJSON* month_iter;
+ cJSON_ArrayForEach(month_iter, months)
+ {
+ money_data month;
+
+ GET_PROP(total_income, month_iter, "total_income");
+ month.total_income = (float)total_income->valuedouble;
+
+ GET_PROP(total_expenses, month_iter, "total_expenses");
+ month.total_expenses = (float)total_expenses->valuedouble;
+
+ GET_PROP(total_profit, month_iter, "total_profit");
+ month.total_profit = (float)total_profit->valuedouble;
+
+ GET_PROP(income_from_trips, month_iter, "income_from_trips");
+ month.income_from_trips = (float)income_from_trips->valuedouble;
+
+ GET_PROP(expenses_from_trucks, month_iter, "expenses_from_trucks");
+ month.expenses_from_trucks = (float)expenses_from_trucks->valuedouble;
+
+ GET_PROP(expenses_from_utility, month_iter, "expenses_from_utility");
+ month.expenses_from_utility = (float)expenses_from_utility->valuedouble;
+
+ GET_PROP(expenses_from_loans, month_iter, "expenses_from_loans");
+ month.expenses_from_loans = (float)expenses_from_loans->valuedouble;
+
+ GET_PROP(expenses_from_healthcare, month_iter, "expenses_from_healthcare");
+ month.expenses_from_healthcare = (float)expenses_from_healthcare->valuedouble;
+
+ GET_PROP(expenses_from_repairs, month_iter, "expenses_from_repairs");
+ month.expenses_from_repairs = (float)expenses_from_repairs->valuedouble;
+
+ GET_PROP(expenses_from_fuel, month_iter, "expenses_from_fuel");
+ month.expenses_from_fuel = (float)expenses_from_fuel->valuedouble;
+
+ GET_PROP(expenses_from_employees, month_iter, "expenses_from_employees");
+ month.expenses_from_employees = (float)expenses_from_employees->valuedouble;
+
+ GET_PROP(index, month_iter, "index");
+ year_data.months[index->valueint] = month;
+ }
+
+ array_push(&new_world->insights, &year_data);
}
+ GET_PROP(active_jobs, json_object, "active_jobs");
+ cJSON* active_job_iter;
+ cJSON_ArrayForEach(active_job_iter, active_jobs)
+ {
+ active_job aj;
+
+ GET_PROP(day, active_job_iter, "day");
+ aj.day = (s16)day->valueint;
+
+ GET_PROP(timeslot, active_job_iter, "timeslot");
+ aj.timeslot = (s16)timeslot->valueint;
+
+ GET_PROP(stay_at_destination, active_job_iter, "stay_at_destination");
+ aj.stay_at_destination = (bool)stay_at_destination->valueint;
+
+ GET_PROP(duration_sec, active_job_iter, "duration_sec");
+ aj.duration_sec = (time_t)duration_sec->valuedouble;
+
+ GET_PROP(left_at, active_job_iter, "left_at");
+ aj.left_at = (time_t)left_at->valuedouble;
+
+ GET_PROP(done_at, active_job_iter, "done_at");
+ aj.done_at = (time_t)done_at->valuedouble;
+
+ GET_PROP(reversed, active_job_iter, "reversed");
+ aj.reversed = (bool)reversed->valueint;
+
+ GET_PROP(assignee_id, active_job_iter, "assignee_id");
+ u32 emp_id = (u32)assignee_id->valuedouble;
+ aj.assignee = *get_employee_by_id_global(new_world, emp_id);
+
+ GET_PROP(truck_id, active_job_iter, "truck_id");
+ u32 tr_id = (u32)truck_id->valuedouble;
+ aj.assigned_truck = *get_truck_by_id(new_world, tr_id);
+
+ GET_PROP(offer, active_job_iter, "offer");
+ { // Load job offer of existing job.
+ job_offer new_offer;
+ new_offer.connections = array_create(sizeof(world_location*));
+
+ GET_PROP(id, offer, "id");
+ new_offer.id = id->valueint;
+
+ GET_PROP(expire_date, offer, "expire_date");
+ new_offer.expire_date = (s64)expire_date->valuedouble;
+
+ GET_PROP(company_id, offer, "company_id");
+ new_offer.company = world_get_company_by_name(new_world, company_id->valuestring);
+
+ GET_PROP(prod, offer, "product");
+ new_offer.product = world_get_product_by_name(new_world, prod->valuestring);
+
+ GET_PROP(shipday_count, offer, "shipday_count");
+ new_offer.shipday_count = (s32)shipday_count->valueint;
+
+ GET_PROP(reward, offer, "reward");
+ new_offer.reward = (u32)reward->valueint;
+
+ GET_PROP(total_distance, offer, "total_distance");
+ new_offer.total_distance = (float)total_distance->valuedouble;
+
+ GET_PROP(boat_distance, offer, "boat_distance");
+ new_offer.boat_distance = (float)boat_distance->valuedouble;
+
+ GET_PROP(duration_sec_min, offer, "duration_sec_min");
+ new_offer.duration_sec_min = (time_t)duration_sec_min->valuedouble;
+
+ GET_PROP(duration_sec_max, offer, "duration_sec_max");
+ new_offer.duration_sec_max = (time_t)duration_sec_max->valuedouble;
+
+ GET_PROP(duration_sec_min_excluding_boat, offer, "duration_sec_min_excluding_boat");
+ new_offer.duration_sec_min_excluding_boat = (time_t)duration_sec_min_excluding_boat->valuedouble;
+
+ GET_PROP(shipdays, offer, "shipdays");
+ cJSON* shipday_iter;
+ int shipday_index = 0;
+ cJSON_ArrayForEach(shipday_iter, shipdays)
+ {
+ new_offer.shipdays[shipday_index] = (weekday)shipday_iter->valueint;
+ shipday_index++;
+ }
+
+ GET_PROP(connections, offer, "connections");
+ cJSON* connection_iter;
+ cJSON_ArrayForEach(connection_iter, connections)
+ {
+ u64 id = (u32)connection_iter->valuedouble;
+ world_location* loc = get_world_location_by_id(new_world, id);
+ if (loc) array_push(&new_offer.connections, &loc);
+ }
+
+ aj.offer = new_offer;
+
+ array_push(&new_world->active_jobs, &aj);
+ }
+ }
world_map_set_active_world(new_world);
enable_insights_for_current_month(new_world);
@@ -977,6 +1189,7 @@ static void write_save_file(s32 index) {
cJSON_AddItemToObject(offer, "id", cJSON_CreateNumber(aj->offer.id));
cJSON_AddItemToObject(offer, "expire_date", cJSON_CreateNumber(aj->offer.expire_date));
+ cJSON_AddItemToObject(offer, "reward", cJSON_CreateNumber(aj->offer.reward));
cJSON_AddItemToObject(offer, "company_id", cJSON_CreateString(aj->offer.company->name));
cJSON_AddItemToObject(offer, "product", cJSON_CreateString(aj->offer.product->name));
cJSON_AddItemToObject(offer, "shipday_count", cJSON_CreateNumber(aj->offer.shipday_count));
|
