How to add a custom field which dynamically renders different output according to certain conditions?
Computed Field seems to meet your needs.


  These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views.


Emphasis mine. Either require it in your module and use it, or use it's code, it is open source after all.