AlterTest: Unterschied zwischen den Versionen

Aus Almada Wiki
Zur Navigation springen Zur Suche springen
neu erstellt
 
Keine Bearbeitungszusammenfassung
 
Zeile 180: Zeile 180:
end
end
if boronstag_belegt then
if boronstag_belegt then
suffix = '[[Kategorie:Person (historisch)]]'
suffix = suffix .. '[[Kategorie:Person (historisch)]]'
else
else
suffix = '[[Kategorie:Person (lebend)]]'
suffix = suffix .. '[[Kategorie:Person (lebend)]]'
end
end
if tsatag_genau ~= true or boronstag_genau ~= true then
if tsatag_genau ~= true or boronstag_genau ~= true then

Aktuelle Version vom 13. Mai 2025, 10:08 Uhr

Die Dokumentation für dieses Modul kann unter Modul:AlterTest/Doku erstellt werden

local p = {} --p stands for package

function p.Berechnen( frame )
	tsatag = frame:getParent().args['Tsatag']
	boronstag = frame:getParent().args['Boronstag']
	spezies = frame:getParent().args['Spezies']
	if spezies == nil then
		spezies = 'Mensch' -- größtenteils Menschen
	end
	if tsatag == nil then
		return 'Parameter Tsatag fehlt in der Vorlage Person auf dieser Seite. Bitte nachtragen! [[Kategorie:Person mit unvollständiger Vorlage]]'
	end
	if boronstag == nil then
		return 'Parameter Boronstag fehlt in der Vorlage Person auf dieser Seite. Bitte nachtragen! [[Kategorie:Person mit unvollständiger Vorlage]]'
	end
	if string.len(spezies) > 0 then
		le = {}
		le[1] = 'Goblin'
		le[2] = 'Ork'
		le[3] = 'Shingwa'
		le[4] = 'Neristu'
		le[5] = 'Trollzacker'
		le[6] = 'Leonir'
		le[7] = 'Mensch'
		le[8] = 'Halbelf'
		le[9] = 'Nives'
		le[10] = 'Achaz'
		le[11] = 'Perldrach'
		le[12] = 'Gargyl'
		le[13] = 'Yeti'
		le[14] = 'Finsterkamm-Zwerg'
		le[15] = 'Zwerg'
		le[16] = 'Höhlendrach'
		le[17] = 'Troll'
		le[18] = 'Shakagra'
		le[19] = 'Elf'
		le[20] = 'Riesenlind'
		le[21] = 'Purpur'
		le[22] = 'Kaiserdrach'
		leAlter = {}
		leAlter[1] = 35
		leAlter[2] = 40
		leAlter[3] = 50
		leAlter[4] = 60
		leAlter[5] = 60
		leAlter[6] = 70
		leAlter[7] = 80
		leAlter[8] = 90
		leAlter[9] = 90
		leAlter[10] = 130
		leAlter[11] = 250
		leAlter[12] = 300
		leAlter[13] = 300
		leAlter[14] = 400
		leAlter[15] = 400
		leAlter[16] = 2000
		leAlter[17] = 2000
		leAlter[18] = 2000
		leAlter[19] = 2000
		leAlter[20] = 2500
		leAlter[21] = 3000
		leAlter[22] = 3000
		i = 1
		lebenserwartung_belegt = false
		while (i <= 22) do
			if string.match(spezies, le[i]) ~= nil then
				lebenserwartung = leAlter[i]
			end
			i = i + 1
		end
	else
		lebenserwartung = 20000000000 -- lebt per Definition noch
	end
	if string.len(tsatag) > 0 then
		tsatag_string = string.sub(tsatag, 30, 43)
		test_tsatag = tonumber(tsatag_string)
		if test_tsatag ~= nil then
			tsatag_jahr = tonumber(string.sub(tsatag_string, 1, 10)) - 2000000000
			tsatag_monat = tonumber(string.sub(tsatag_string, 11, 12))
			tsatag_tag = tonumber(string.sub(tsatag_string, 13, 14))
			tsatag_tagimjahr = (tsatag_monat - 1) * 30 + tsatag_tag
			tsatag_belegt = true
			if tsatag_monat < 1 then
				tsatag_genau = false
			else
				if tsatag_tag < 1 then
					tsatag_genau = false
				else
					tsatag_genau = true
				end
			end
		else
			return 'Fehlerhafte Eingabe beim Tsatag. Keine Berechnung möglich. [[Kategorie:Person mit falschem Tsatag]]'
		end
	else
		tsatag_belegt = false
	end
	if string.len(boronstag) > 0 then
		if string.match(boronstag, 'unbekannt') ~= nil then
			return frame:expandTemplate{ title = 'BOR' } .. ' in unbekanntem Alter'
		else
			boronstag_string = string.sub(boronstag, 30, 43)
			test_boronstag = tonumber(boronstag_string)
			if test_boronstag ~= nil then
				boronstag_jahr = tonumber(string.sub(boronstag_string, 1, 10)) - 2000000000
				boronstag_monat = tonumber(string.sub(boronstag_string, 11, 12))
				boronstag_tag = tonumber(string.sub(boronstag_string, 13, 14))
				boronstag_tagimjahr = (boronstag_monat - 1) * 30 + boronstag_tag
				boronstag_belegt = true
				if boronstag_monat < 1 then
					boronstag_genau = false
				else
					if boronstag_tag < 1 then
						boronstag_genau = false
					else
						boronstag_genau = true
					end
				end
			else
				return 'Fehlerhafte Eingabe beim Boronstag. Keine Berechnung möglich. [[Kategorie:Person mit falschem Boronstag]]'
			end
		end
	else
		boronstag_belegt = false
	end
	tagesdatum_jahr = (os.date( "*t" )['year'] - 977)
	tagesdatum_tagimjahr = os.date( "*t" )['yday']
	if tsatag_belegt then
		if boronstag_belegt then
			tagdiff = boronstag_tagimjahr - tsatag_tagimjahr
			jahrdiff = boronstag_jahr - tsatag_jahr
			if tagdiff < 0 then
				tagdiff = 365 + tagdiff
				jahrdiff = jahrdiff - 1
			end
			if jahrdiff < 0 then
				return 'Keine Altersberechnung möglich, Boronstag liegt vor dem Tsatag. [[Kategorie:Person mit falschen Datumsangaben]]'
			end
		else -- lebt noch
			tagdiff = tagesdatum_tagimjahr - tsatag_tagimjahr
			jahrdiff = tagesdatum_jahr - tsatag_jahr
			if tagdiff < 0 then
				tagdiff = 365 + tagdiff
				jahrdiff = jahrdiff - 1
			end
			if jahrdiff < 0 then
				return 'Keine Altersberechnung möglich, die Person ist noch gar nicht geboren. [[Kategorie:Person mit Tsatag in der Zukunft]]'
			end
		end
		alter_in_jahren = jahrdiff
		alter_plus_tage = tagdiff
		if alter_in_jahren == 1 then
			jahrwort = 'Jahr'
		else
			jahrwort = 'Jahre'
			if boronstag_belegt then
				jahrwort = jahrwort .. 'n'
			end
		end
		if alter_plus_tage == 1 then
			tagwort = 'Tag'
		else
			tagwort = 'Tage'
			if boronstag_belegt then
				tagwort = tagwort .. 'n'
			end
		end
		if boronstag_belegt then
			praefix = frame:expandTemplate{ title = 'BOR' } .. ' mit '
		else
			praefix = ''
		end
		if alter_in_jahren > lebenserwartung then
			suffix = ' (möglicherweise verstorben) [[Kategorie:Person (möglicherweise verstorben)]]'
		else
			suffix = ''
		end
		if alter_in_jahren > (lebenserwartung * 2) then
			suffix = ' (wahrscheinlich verstorben) [[Kategorie:Person (wahrscheinlich verstorben)]]'
		end
		if boronstag_belegt then
			suffix = suffix .. '[[Kategorie:Person (historisch)]]'
		else
			suffix = suffix .. '[[Kategorie:Person (lebend)]]'
		end
		if tsatag_genau ~= true or boronstag_genau ~= true then
			return praefix .. 'etwa ' .. alter_in_jahren .. ' ' .. jahrwort .. suffix
		else
			return praefix .. alter_in_jahren .. ' ' .. jahrwort .. ' und '.. alter_plus_tage .. ' ' .. tagwort .. suffix
		--	return tagesdatum_jahr .. '-' .. tagesdatum_tagimjahr .. '-' .. tsatag_jahr .. '-' .. tsatag_tagimjahr .. '-' .. tagdiff
		end
	else
		return 'Berechnung nicht möglich ohne Tsatags-Datum [[Kategorie:Person ohne Tsatag]]'
	end
end

return p