MCPcopy Create free account
hub / github.com/NetHack/NetHack / compare_blstats

Function compare_blstats

src/botl.c:1808–1883  ·  view source on GitHub ↗

* This compares the previous stat with the current stat, * and returns one of the following results based on that: * * if prev_value < new_value (stat went up, increased) * return 1 * * if prev_value > new_value (stat went down, decreased) * return -1 * * if prev_value == new_value (stat stayed the same) * return 0 * * Special cases: * - for bitmasks, 0 = s

Source from the content-addressed store, hash-verified

1806 *
1807 */
1808staticfn int
1809compare_blstats(struct istat_s *bl1, struct istat_s *bl2)
1810{
1811 anything *a1, *a2;
1812 boolean use_rawval;
1813 int anytype, fld, result = 0;
1814
1815 if (!bl1 || !bl2) {
1816 panic("compare_blstat: bad istat pointer %s, %s",
1817 fmt_ptr((genericptr_t) bl1), fmt_ptr((genericptr_t) bl2));
1818 }
1819
1820 anytype = bl1->anytype;
1821 if ((!bl1->a.a_void || !bl2->a.a_void)
1822 && (anytype == ANY_IPTR || anytype == ANY_UPTR
1823 || anytype == ANY_LPTR || anytype == ANY_ULPTR)) {
1824 panic("compare_blstat: invalid pointer %s, %s",
1825 fmt_ptr((genericptr_t) bl1->a.a_void),
1826 fmt_ptr((genericptr_t) bl2->a.a_void));
1827 }
1828 /* cheat; terrain is highlighted as a string but we have a handy int
1829 reflecting its value to use when checking for changes */
1830 if (bl1->fld == BL_TERRAIN)
1831 anytype = ANY_INT;
1832
1833 fld = bl1->fld;
1834 use_rawval = (fld == BL_HP || fld == BL_HPMAX
1835 || fld == BL_ENE || fld == BL_ENEMAX
1836 || fld == BL_GOLD);
1837 a1 = use_rawval ? &bl1->rawval : &bl1->a;
1838 a2 = use_rawval ? &bl2->rawval : &bl2->a;
1839
1840 switch (anytype) {
1841 case ANY_INT:
1842 result = (a1->a_int < a2->a_int) ? 1
1843 : (a1->a_int > a2->a_int) ? -1 : 0;
1844 break;
1845 case ANY_IPTR:
1846 result = (*a1->a_iptr < *a2->a_iptr) ? 1
1847 : (*a1->a_iptr > *a2->a_iptr) ? -1 : 0;
1848 break;
1849 case ANY_LONG:
1850 result = (a1->a_long < a2->a_long) ? 1
1851 : (a1->a_long > a2->a_long) ? -1 : 0;
1852 break;
1853 case ANY_LPTR:
1854 result = (*a1->a_lptr < *a2->a_lptr) ? 1
1855 : (*a1->a_lptr > *a2->a_lptr) ? -1 : 0;
1856 break;
1857 case ANY_UINT:
1858 result = (a1->a_uint < a2->a_uint) ? 1
1859 : (a1->a_uint > a2->a_uint) ? -1 : 0;
1860 break;
1861 case ANY_UPTR:
1862 result = (*a1->a_uptr < *a2->a_uptr) ? 1
1863 : (*a1->a_uptr > *a2->a_uptr) ? -1 : 0;
1864 break;
1865 case ANY_ULONG:

Callers 1

Calls 3

fmt_ptrFunction · 0.85
sgnFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected