public byte tval; /* Item type for book this spell is in */ #endregion Fields #region Methods /** * Adjust damage according to resistance or vulnerability. * * \param type is the attack type we are checking. * \param dam is the unadjusted damage. * \param dam_aspect is the calc we want (min, avg, max, random). * \param resist is the degree of resistance (-1 = vuln, 3 = immune). */ public static int adjust_dam(Player.Player p, GF type, int dam, aspect dam_aspect, int resist) { GF gf_ptr = type; int i, denom; if (resist == 3) /* immune */ return 0; /* Hack - acid damage is halved by armour, holy orb is halved */ if ((type == GF.ACID && minus_ac(p)) || type == GF.HOLY_ORB) dam = (dam + 1) / 2; if (resist == -1) /* vulnerable */ return (dam * 4 / 3); /* Variable resists vary the denominator, so we need to invert the logic * of dam_aspect. (m_bonus is unused) */ switch (dam_aspect) { case aspect.MINIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MAXIMISE); break; case aspect.MAXIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MINIMISE); break; default: denom = Random.randcalc(gf_ptr.denom, 0, dam_aspect); break; } for (i = resist; i > 0; i--) if (denom != 0) dam = dam * gf_ptr.num / denom; return dam; }
/** * Calculation helper function for random_value structs. */ public static int randcalc(random_value v, int level, aspect rand_aspect) { if (rand_aspect == aspect.EXTREMIFY) { int min = randcalc(v, level, aspect.MINIMISE); int max = randcalc(v, level, aspect.MAXIMISE); return(Math.Abs(min) > Math.Abs(max) ? min : max); } else { int dmg = damcalc(v.dice, v.sides, rand_aspect); int bonus = m_bonus_calc(v.m_bonus, level, rand_aspect); return(v.Base + dmg + bonus); } }
/** * Calculation helper function for damroll */ public static int damcalc(int num, int sides, aspect dam_aspect) { switch (dam_aspect) { case aspect.MAXIMISE: case aspect.EXTREMIFY: return num * sides; case aspect.RANDOMISE: return damroll(num, sides); case aspect.MINIMISE: return num; case aspect.AVERAGE: return num * (sides + 1) / 2; } return 0; }
/** * Adjust damage according to resistance or vulnerability. * * \param type is the attack type we are checking. * \param dam is the unadjusted damage. * \param dam_aspect is the calc we want (min, avg, max, random). * \param resist is the degree of resistance (-1 = vuln, 3 = immune). */ public static int adjust_dam(Player.Player p, GF type, int dam, aspect dam_aspect, int resist) { GF gf_ptr = type; int i, denom; if (resist == 3) /* immune */ { return(0); } /* Hack - acid damage is halved by armour, holy orb is halved */ if ((type == GF.ACID && minus_ac(p)) || type == GF.HOLY_ORB) { dam = (dam + 1) / 2; } if (resist == -1) /* vulnerable */ { return(dam * 4 / 3); } /* Variable resists vary the denominator, so we need to invert the logic * of dam_aspect. (m_bonus is unused) */ switch (dam_aspect) { case aspect.MINIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MAXIMISE); break; case aspect.MAXIMISE: denom = Random.randcalc(gf_ptr.denom, 0, aspect.MINIMISE); break; default: denom = Random.randcalc(gf_ptr.denom, 0, dam_aspect); break; } for (i = resist; i > 0; i--) { if (denom != 0) { dam = dam * gf_ptr.num / denom; } } return(dam); }
/** * Calculation helper function for m_bonus. */ public static int m_bonus_calc(int max, int level, aspect bonus_aspect) { switch (bonus_aspect) { case aspect.EXTREMIFY: case aspect.MAXIMISE: return(max); case aspect.RANDOMISE: return(m_bonus(max, level)); case aspect.MINIMISE: return(0); case aspect.AVERAGE: return(max * level / Misc.MAX_DEPTH); } return(0); }
/** * Calculation helper function for damroll */ public static int damcalc(int num, int sides, aspect dam_aspect) { switch (dam_aspect) { case aspect.MAXIMISE: case aspect.EXTREMIFY: return(num * sides); case aspect.RANDOMISE: return(damroll(num, sides)); case aspect.MINIMISE: return(num); case aspect.AVERAGE: return(num * (sides + 1) / 2); } return(0); }
GetRowsAndColumns ( ICollection <IVertex> oVerticesToLayOut, LayoutContext oLayoutContext, out Int32 iRows, out Int32 iColumns ) { Debug.Assert(oVerticesToLayOut != null); Debug.Assert(oLayoutContext != null); AssertValid(); #if false Some definitions: W = rectangle width H = rectangle height A = rectangle aspect ratio = W / H V = number of vertices in graph Vrow = number of vertices per row Vcol = number of vertices per column R = number of grid rows = Vcol + 1 C = number of grid columns = Vrow + 1 First simulataneous equation, allowing Vrow and Vcol to be fractional for now: Vrow * Vcol = V Second simulataneous equation: C / R = A Combining these equations yield this quadratic equation: 2 C + [(-A - 1) * C] +[A * (1 - V)] = 0
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit; if (hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0f)) { if (hit.collider.tag == "Hex") { Hex h = hit.collider.gameObject.transform.GetComponent(typeof(Hex)) as Hex; aspect aspc; if (aspect_scroll.GetComponent <AspectScroll> ().selected_aspect == "NULL") { aspc = new aspect(); aspc.name = "NULL"; } else { aspc = aspect_dictionary [aspect_scroll.GetComponent <AspectScroll> ().selected_aspect]; } h.aspect = aspc; h.aspect_update(true); } } } if (Input.GetMouseButtonDown(1)) { RaycastHit2D hit; if (hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0f)) { if (hit.collider.tag == "Hex") { Hex h = hit.collider.gameObject.transform.GetComponent(typeof(Hex)) as Hex; aspect aspc; aspc = new aspect(); aspc.name = "NULL"; h.aspect = aspc; h.aspect_update(true); } } } }
/** * Calculate hp for a monster. This function assumes that the Rand_normal * function has limits of +/- 4x std_dev. If that changes, this function * will become inaccurate. * * \param r_ptr is the race of the monster in question. * \param hp_aspect is the hp calc we want (min, max, avg, random). */ public static int mon_hp(Monster_Race r_ptr, aspect hp_aspect) { int std_dev = (((r_ptr.avg_hp * 10) / 8) + 5) / 10; if (r_ptr.avg_hp > 1) std_dev++; switch (hp_aspect) { case aspect.MINIMISE: return (r_ptr.avg_hp - (4 * std_dev)); case aspect.MAXIMISE: case aspect.EXTREMIFY: return (r_ptr.avg_hp + (4 * std_dev)); case aspect.AVERAGE: return r_ptr.avg_hp; default: return Random.Rand_normal(r_ptr.avg_hp, std_dev); } }
/** * Wipe an object clean and make it a standard object of the specified kind. * Was previous "object_prep", is now a constructor for Object */ public void prep(Object_Kind k, int lev, aspect rand_aspect) { int flag, x; Bitflag flags = new Bitflag(Object_Flag.SIZE); // Assign the kind and copy across data this.kind = k; this.tval = k.tval; this.sval = k.sval; this.ac = k.ac; this.dd = k.dd; this.ds = k.ds; this.weight = k.weight; // Default number this.number = 1; for(int i = 0; i < pval_flags.Length; i++) { pval_flags[i] = new Bitflag(Object_Flag.SIZE); } // Apply pvals and then copy flags for (int i = 0; i < k.num_pvals; i++) { flags.copy(k.pval_flags[i]); flags.copy(k.pval_flags[i]); x = Random.randcalc(k.pval[i], lev, rand_aspect); for (flag = flags.next(Bitflag.FLAG_START); flag != Bitflag.FLAG_null; flag = flags.next(flag + 1)) add_pval(x, flag); } if(k.Base != null) { flags.copy(k.Base.flags); } flags.union(k.flags); // Assign charges (wands/staves only) if (tval == TVal.TV_WAND || tval == TVal.TV_STAFF) pval[Misc.DEFAULT_PVAL] = (short)Random.randcalc(k.charge, lev, rand_aspect); // Assign flagless pval for food or oil if (tval == TVal.TV_FOOD || tval == TVal.TV_POTION || tval == TVal.TV_FLASK) pval[Misc.DEFAULT_PVAL] = (short)Random.randcalc(k.pval[Misc.DEFAULT_PVAL], lev, rand_aspect); // Default fuel for lamps if (tval == TVal.TV_LIGHT) { if(sval == SVal.SV_LIGHT_TORCH) timeout = Misc.DEFAULT_TORCH; else if(sval == SVal.SV_LIGHT_LANTERN) timeout = Misc.DEFAULT_LAMP; } // Default magic to_h = (short)Random.randcalc(k.to_h, lev, rand_aspect); to_d = (short)Random.randcalc(k.to_d, lev, rand_aspect); to_a = (short)Random.randcalc(k.to_a, lev, rand_aspect); }
// Use this for initialization void Start() { grid.set_size(9); draw_hex_from_hexes(4, ref grid); XmlDocument aspect_list_doc = new XmlDocument(); aspect_list_doc.LoadXml(aspect_list.text); XmlNodeList aspects_list = aspect_list_doc.GetElementsByTagName("aspect"); foreach (XmlNode aspect in aspects_list) { XmlNodeList aspect_data = aspect.ChildNodes; string name = "NULL"; aspect asp = new aspect(); foreach (XmlNode aspect_child in aspect_data) { if (aspect_child.Name == "keywords") { asp.keywords = aspect_child.InnerText; } else if (aspect_child.Name == "isPrimal") { if (aspect_child.InnerText == "true") { asp.primal = true; } else { asp.primal = false; } } else if (aspect_child.Name == "name") { name = aspect_child.InnerText; aspect_option_list.Add(name); asp.name = name; Texture2D tex = null; byte[] fileData; string file_name = Application.persistentDataPath + "/Aspect_Textures/" + name.ToLower() + ".png"; if (File.Exists(file_name)) { fileData = File.ReadAllBytes(file_name); asp.texture = new Texture2D(32, 32); asp.texture.LoadImage(fileData); //..this will auto-resize the texture dimensions. asp.texture.filterMode = FilterMode.Point; } else { Debug.Log("Failed to load texture for: " + name + ", at path: " + file_name); } } else if (aspect_child.Name == "component1") { asp.component1 = aspect_child.InnerText; } else if (aspect_child.Name == "component2") { asp.component2 = aspect_child.InnerText; } } aspect_dictionary.Add(name, asp); } aspect_scroll.GetComponent <AspectScroll> ().aspects = aspect_dictionary; build_reverse_recipe_table(); populate_scrollable_aspect_list(); }
/** * Calculation helper function for random_value structs. */ public static int randcalc(random_value v, int level, aspect rand_aspect) { if (rand_aspect == aspect.EXTREMIFY) { int min = randcalc(v, level, aspect.MINIMISE); int max = randcalc(v, level, aspect.MAXIMISE); return Math.Abs(min) > Math.Abs(max) ? min : max; } else { int dmg = damcalc(v.dice, v.sides, rand_aspect); int bonus = m_bonus_calc(v.m_bonus, level, rand_aspect); return v.Base + dmg + bonus; } }
/** * Calculation helper function for m_bonus. */ public static int m_bonus_calc(int max, int level, aspect bonus_aspect) { switch (bonus_aspect) { case aspect.EXTREMIFY: case aspect.MAXIMISE: return max; case aspect.RANDOMISE: return m_bonus(max, level); case aspect.MINIMISE: return 0; case aspect.AVERAGE: return max * level / Misc.MAX_DEPTH; } return 0; }
GetRowsAndColumns ( ICollection <IVertex> oVerticesToLayOut, LayoutContext oLayoutContext, out Int32 iRows, out Int32 iColumns ) { Debug.Assert(oVerticesToLayOut != null); Debug.Assert(oLayoutContext != null); AssertValid(); #if false Some definitions: W = rectangle width H = rectangle height A = rectangle aspect ratio = W / H V = number of vertices in graph R = number of grid rows C = number of grid columns First simulataneous equation, allowing R and C to be fractional for now: R * C = V Second simulataneous equation: C / R = A Combining these equations yields: 1 / 2 C = (V * A) #endif Int32 V = oVerticesToLayOut.Count; // Compute the aspect ratio. RectangleF oRectangleF = oLayoutContext.GraphRectangle; Debug.Assert(oRectangleF.Height != 0); Double A = oRectangleF.Width / oRectangleF.Height; Double C = Math.Sqrt(V * A); Debug.Assert(A != 0); Double R = C / A; // Try the floor/ceiling combinations. // C floor, R floor iColumns = (Int32)Math.Floor(C); iRows = (Int32)Math.Floor(R); if (RowsAndColumnsAreSufficient(iRows, iColumns, V)) { return; } // C floor, R ceiling iRows++; if (RowsAndColumnsAreSufficient(iRows, iColumns, V)) { return; } // C ceiling, R floor iColumns = (Int32)Math.Ceiling(C); iRows = (Int32)Math.Floor(R); if (RowsAndColumnsAreSufficient(iRows, iColumns, V)) { return; } // C ceiling, R ceiling iRows++; Debug.Assert(RowsAndColumnsAreSufficient(iRows, iColumns, V)); }