mourne_rcpp_fw/Mourne-CI/application/models/unit_model.php

173 lines
4.4 KiB
PHP
Raw Normal View History

2021-10-30 19:02:07 +02:00
<?php
class Unit_model extends MO_Model
{
public function __construct()
{
parent::__construct();
}
public function get_village_units($villageid)
{
$sql = "SELECT users.username,units.*,village_units.userid,village_units.unitcount
2021-10-30 19:02:07 +02:00
FROM village_units
LEFT JOIN users ON village_units.userid=users.id
LEFT JOIN units ON village_units.unitid=units.id
WHERE villageid='$villageid'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
//TODO order it!
2021-10-30 19:02:07 +02:00
return $q->result_array();
}
2021-10-30 19:02:07 +02:00
public function get_unit($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
return $q->row_array();
}
2021-10-30 19:02:07 +02:00
//calculates how many units can be created (by lookin at events)
//nothing gets queried
public function calc_max_unit_ev($unit_max, $unit_res, $event)
2021-10-30 19:02:07 +02:00
{
$in_progress = 0;
2021-10-30 19:02:07 +02:00
if ($event) {
foreach ($event as $row) {
$in_progress += $row['data2'];
}
}
2021-10-30 19:02:07 +02:00
//if more are in progress that the building can make
if ($in_progress >= $unit_max) {
return 0;
}
2021-10-30 19:02:07 +02:00
//calc how many can be made overall
$max = $unit_max - $in_progress;
2021-10-30 19:02:07 +02:00
//if less can be made because of events than the resources allow
if ($max <= $unit_res) {
return $max;
}
2021-10-30 19:02:07 +02:00
//if events allow more than resources
if ($max > $unit_res) {
return $unit_res;
}
2021-10-30 19:02:07 +02:00
return $max;
}
2021-10-30 19:02:07 +02:00
public function list_create_mod_drop_admin()
{
//STUB
return array('0' => 'Nothing');
}
2021-10-30 19:02:07 +02:00
public function list_units_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
return $q->result_array();
}
2021-10-30 19:02:07 +02:00
public function get_unit_list_dropdown_admin()
{
$sql = "SELECT * FROM units";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
$res = $q->result_array();
2021-10-30 19:02:07 +02:00
$data[0] = 'Nothing';
2021-10-30 19:02:07 +02:00
foreach ($res as $row) {
$data[$row['id']] = $row['name'];
}
return $data;
}
2021-10-30 19:02:07 +02:00
public function add_unit_admin($data)
{
$sql = "INSERT INTO units
2021-10-30 19:02:07 +02:00
VALUES(default,
'" . $data['type'] . "',
'" . $data['name'] . "',
'" . $data['icon'] . "',
'" . $data['score'] . "',
'" . $data['can_defend'] . "',
'" . $data['defense'] . "',
'" . $data['attack'] . "',
'" . $data['weak_against'] . "',
'" . $data['strong_against'] . "',
'" . $data['turn'] . "',
'" . $data['ability'] . "',
'" . $data['time_to_create'] . "',
'" . $data['cost_unit'] . "',
'" . $data['cost_num_unit'] . "',
'" . $data['cost_food'] . "',
'" . $data['cost_wood'] . "',
'" . $data['cost_stone'] . "',
'" . $data['cost_iron'] . "',
'" . $data['cost_mana'] . "',
'" . $data['mod_rate_food'] . "',
'" . $data['mod_rate_wood'] . "',
'" . $data['mod_rate_stone'] . "',
'" . $data['mod_rate_iron'] . "',
'" . $data['mod_rate_mana'] . "')";
$this->db->query($sql);
2021-10-30 19:02:07 +02:00
$this->_create_sql($sql);
}
2021-10-30 19:02:07 +02:00
public function get_unit_admin($id)
{
$sql = "SELECT * FROM units WHERE id='$id'";
$q = $this->db->query($sql);
2021-10-30 19:02:07 +02:00
return $q->row_array();
}
2021-10-30 19:02:07 +02:00
public function edit_unit_admin($data)
{
$sql = "UPDATE units
2021-10-30 19:02:07 +02:00
SET type='" . $data['type'] . "',
name='" . $data['name'] . "',
icon='" . $data['icon'] . "',
score='" . $data['score'] . "',
can_defend='" . $data['can_defend'] . "',
defense='" . $data['defense'] . "',
attack='" . $data['attack'] . "',
weak_against='" . $data['weak_against'] . "',
strong_against='" . $data['strong_against'] . "',
turn='" . $data['turn'] . "',
ability='" . $data['ability'] . "',
time_to_create='" . $data['time_to_create'] . "',
cost_unit='" . $data['cost_unit'] . "',
cost_num_unit='" . $data['cost_num_unit'] . "',
cost_food='" . $data['cost_food'] . "',
cost_wood='" . $data['cost_wood'] . "',
cost_stone='" . $data['cost_stone'] . "',
cost_iron='" . $data['cost_iron'] . "',
cost_mana='" . $data['cost_mana'] . "',
mod_rate_food='" . $data['mod_rate_food'] . "',
mod_rate_wood='" . $data['mod_rate_wood'] . "',
mod_rate_stone='" . $data['mod_rate_stone'] . "',
mod_rate_iron='" . $data['mod_rate_iron'] . "',
mod_rate_mana='" . $data['mod_rate_mana'] . "'
WHERE id='" . $data['id'] . "'";
$this->db->query($sql);
2021-10-30 19:02:07 +02:00
$this->_create_sql($sql);
}
2021-10-30 19:02:07 +02:00
}
//nowhitesp