public static int elegirImgUnit(Unit_Lib_Entry unit) { if (unit.offset_img<=2490){ return 1; } else{ return 2; } }
/* ==================================================================== CreateAction a unit by passing a Unit struct with the following stuff set: x, y, str, entr, exp, delay, orient, nation, player. This function will use the passed values to create a Unit struct with all values set then. ==================================================================== */ public static Unit CreateUnit(Unit_Lib_Entry prop, Unit_Lib_Entry trsp_prop, Unit unit_base) { Unit unit; if (prop == null) return null; unit = new Unit(); /* shallow copy of properties */ unit.prop = prop; unit.sel_prop = unit.prop; unit.embark = UnitEmbarkTypes.EMBARK_NONE; /* assign the passed transporter without any check */ if (trsp_prop != null && (prop.flags & UnitFlags.FLYING) != UnitFlags.FLYING && (prop.flags & UnitFlags.SWIMMING) != UnitFlags.SWIMMING) { unit.trsp_prop = trsp_prop; /* a sea/air ground transporter is active per default */ if ((trsp_prop.flags & UnitFlags.SWIMMING) == UnitFlags.SWIMMING) { unit.embark = UnitEmbarkTypes.EMBARK_SEA; unit.sel_prop = unit.trsp_prop; } if ((trsp_prop.flags & UnitFlags.FLYING) == UnitFlags.FLYING) { unit.embark = UnitEmbarkTypes.EMBARK_AIR; unit.sel_prop = unit.trsp_prop; } } /* copy the base values */ unit.delay = unit_base.delay; unit.x = unit_base.x; unit.y = unit_base.y; unit.str = unit_base.str; unit.entr = unit_base.entr; unit.player = unit_base.player; unit.nation = unit_base.nation; unit.name = unit_base.name; unit.AddExperience(unit_base.exp_level * 100); unit.orient = unit_base.orient; unit.AdjustIcon(); unit.unused = true; unit.supply_level = 100; unit.cur_ammo = unit.prop.ammo; unit.cur_fuel = unit.prop.fuel; if ((unit.cur_fuel == 0) && (unit.trsp_prop != null) && (!string.IsNullOrEmpty(unit.trsp_prop.id)) && unit.trsp_prop.fuel > 0) unit.cur_fuel = unit.trsp_prop.fuel; unit.tag = unit_base.tag; /* update life bar properties */ update_bar(unit); /* allocate backup mem */ unit.backup = new Unit(); return unit; }
public void Unmount() { if (this.embark != UnitEmbarkTypes.EMBARK_GROUND) return; /* set prop pointer */ this.sel_prop = this.prop; this.embark = UnitEmbarkTypes.EMBARK_NONE; /* adjust pic offset */ this.AdjustIcon(); /* no entrenchment when mounting */ this.entr = 0; }
/* ==================================================================== Mount/unmount unit to ground transporter. ==================================================================== */ public void Mount() { if (this.trsp_prop == null || string.IsNullOrEmpty(this.trsp_prop.id) || this.embark != UnitEmbarkTypes.EMBARK_NONE) return; /* set prop pointer */ this.sel_prop = this.trsp_prop; this.embark = UnitEmbarkTypes.EMBARK_GROUND; /* adjust pic offset */ this.AdjustIcon(); /* no entrenchment when mounting */ this.entr = 0; }
/* ==================================================================== Evaluate the unit. This score will become a relative one whereas the best rating will be 1000. Each operational region ground/sea/air will have its own reference. This evaluation is PG specific. ==================================================================== */ void unit_lib_eval_unit(Unit_Lib_Entry unit) { int attack = 0, defense = 0, misc = 0; /* The score is computed by dividing the unit's properties into categories. The subscores are added with different weights. */ /* The first category covers the attack skills. */ if ((unit.flags & UnitFlags.FLYING) == UnitFlags.FLYING) { attack = unit.atks [0] + unit.atks [1] + /* ground */ 2 * Math.Max (unit.atks [2], Math.Abs (unit.atks [2]) / 2) + /* air */ unit.atks [3]; /* sea */ } else { if ((unit.flags & UnitFlags.SWIMMING) == UnitFlags.SWIMMING) { attack = unit.atks [0] + unit.atks [1] + /* ground */ unit.atks [2] + /* air */ 2 * unit.atks [3]; /* sea */ } else { attack = 2 * Math.Max (unit.atks [0], Math.Abs (unit.atks [0]) / 2) + /* soft */ 2 * Math.Max (unit.atks [1], Math.Abs (unit.atks [1]) / 2) + /* hard */ Math.Max (unit.atks [2], Math.Abs (unit.atks [2]) / 2) + /* air */ unit.atks [3]; /* sea */ } } attack += unit.ini; attack += 2 * unit.rng; /* The second category covers defensive skills. */ if ((unit.flags & UnitFlags.FLYING) == UnitFlags.FLYING) defense = unit.def_grnd + 2 * unit.def_air; else { defense = 2 * unit.def_grnd + unit.def_air; if ((unit.flags & UnitFlags.INFANTRY) == UnitFlags.INFANTRY) /* hype infantry a bit as it doesn't need the close defense value */ defense += 5; else defense += unit.def_cls; } /* The third category covers miscellany skills. */ if ((unit.flags & UnitFlags.FLYING) == UnitFlags.FLYING) misc = Math.Min (12, unit.ammo) + Math.Min (unit.fuel, 80) / 5 + unit.mov / 2; else misc = Math.Min (12, unit.ammo) + Math.Min (unit.fuel, 60) / 4 + unit.mov; /* summarize */ unit.eval_score = (2 * attack + 2 * defense + misc) / 5; }
/* ==================================================================== Delete unit library entry. ==================================================================== */ static void unit_lib_delete_entry(Unit_Lib_Entry ptr) { Unit_Lib_Entry entry = ptr; if (entry == null) return; if (string.IsNullOrEmpty(entry.id)) entry.id = null; if (string.IsNullOrEmpty(entry.name)) entry.name = null; if (entry.icon != null) SDL_FreeSurface(entry.icon); if (entry.icon_tiny != null) SDL_FreeSurface(entry.icon_tiny); #if WITH_SOUND if ( entry.wav_alloc && entry.wav_move ) wav_free( entry.wav_move ); #endif entry = null; }